How to add and orient local coordinate system in Mechanical?

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 389
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
edited June 2023 in Structures

How to add and orient local coordinate system in Mechanical?

Tagged:

Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 389
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Answer ✓

    For 2020R2 and above:

    # Add a coordinate system
    coordinate_systems = Model.CoordinateSystems
    csys = coordinate_systems.AddCoordinateSystem()
    
    # Define Primary Axis
    csys.PrimaryAxis = CoordinateSystemAxisType.PositiveZAxis
    # Orient the Primary Axis to a Vector
    csys.PrimaryAxisDirection = Vector3D(1, 0, 0)  # Global X direction
    
    # Set the origin
    csys.SetOriginLocation(Quantity(0,"in"), Quantity(0,"in"), Quantity(0,"in"))
    
    # Refresh
    ExtAPI.DataModel.Tree.Refresh()
    
  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 389
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Answer ✓

    For 2020R1 and below I could only find a solution via Coordinate System Transformation:

    # Add a coordinate system
    coordinate_systems = Model.CoordinateSystems
    csys = coordinate_systems.AddCoordinateSystem()
    
    # Set the origin
    csys.SetOriginLocation(Quantity(0,"in"), Quantity(0,"in"), Quantity(0,"in"))
    
    # Define Primary Axis
    csys.PrimaryAxis = CoordinateSystemAxisType.PositiveZAxis
    
    # Add a Rotational Transformation, each added Transformation gets an index starting from 1
    csys.AddTransformation(TransformationType.Rotation, csys.PrimaryAxis)
    # Set a Transformation Value, say 45deg
    csys.SetTransformationValue(1, 45)
    
    # Add a Translational Transformation, index 2
    csys.AddTransformation(TransformationType.Offset, csys.PrimaryAxis)
    # Set a Transformation Value, say 10mm
    csys.SetTransformationValue(2, 10)
    
    # Add a Rotational Transformation, index 3
    csys.AddTransformation(TransformationType.Rotation, csys.PrimaryAxis)
    # Set a Rotational Value, say 10deg
    csys.SetTransformationValue(3, 10)
    
    “””
    You can add multiple transformations
    ….
    “””
    
    # Refresh
    ExtAPI.DataModel.Tree.Refresh()