Create and rotate coordinate system

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 712
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
edited June 2023 in Structures

How can I create and rotate a coordinate system in Mechanical through scripting?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 712
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Answer ✓

    Setting the value of the rotation is not straightforward. Below is an example:

    testCS = ExtAPI.DataModel.Project.Model.CoordinateSystems.AddCoordinateSystem()
    testCS.CoordinateSystemType = CoordinateSystemTypeEnum.Cylindrical
    testCS.OriginX = Quantity(0,"m")
    testCS.OriginY = Quantity(0,"m")
    testCS.OriginZ = Quantity(0,"m")
    testCS.PrimaryAxisDefineBy = CoordinateSystemAlignmentType.GlobalZ
    testCS.AddTransformation(TransformationType.Rotation,CoordinateSystemAxisType.PositiveZAxis)
    testCS.SetTransformationValue(1,45)
    

    To flip the CS, one can use:

    test.AddTransformation(TransformationType.Flip,CoordinateSystemAxisType.NegativeXAxis)
    testCS.SetTransformationValue(1,4)
    

    where the second value ranges from 1 to 6 and accounts for +X, +Y, +Z, -X, -Y, -Z respectively.