# How to add and orient local coordinate system in Mechanical?

Member, Moderator, Employee Posts: 442
✭✭✭✭
edited June 2023

How to add and orient local coordinate system in Mechanical?

Tagged:

• Member, Moderator, Employee Posts: 442
✭✭✭✭

For 2020R2 and above:

```# Add a coordinate system
coordinate_systems = Model.CoordinateSystems

# 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()
```
• Member, Moderator, Employee Posts: 442
✭✭✭✭

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

```# Add a coordinate system
coordinate_systems = Model.CoordinateSystems

# 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
# Set a Transformation Value, say 45deg
csys.SetTransformationValue(1, 45)

# Add a Translational Transformation, index 2
# Set a Transformation Value, say 10mm
csys.SetTransformationValue(2, 10)

# Add a Rotational Transformation, index 3
# Set a Rotational Value, say 10deg
csys.SetTransformationValue(3, 10)

“””
….
“””

# Refresh
ExtAPI.DataModel.Tree.Refresh()
```

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?