How to add and orient local coordinate system in Mechanical?

Options
Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 411
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:

Best Answers

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

    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: 411
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Answer ✓
    Options

    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()
    

Answers

  • Erubus
    Erubus Member Posts: 4
    First Comment
    Options

    hello, I want to create a coordinate system using the ACT script, code is cs = Model.CoordinateSystems cs_obj = cs.AddCoordinateSystem() cs_obj.Name = "xz" cs_obj.OriginDefineBy = Ansys.Mechanical.DataModel.Enums.CoordinateSystemAlignmentType.Associative selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities) selection.Ids = id_list cs_obj.OriginLocation = selection but error is cs is None, How to solve it?

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

    @Erubus Can you please create a new discussion for this question and maybe share the screenshot of the error you get?