Local coordinate system definition in Ansys ACT

273 Views Asked by At

I have the location and the base vectors of a coordinate system and I'd like to use this data to create a coordinate system in ANSYS Workbench (2023R1) using the Python ACT API.

I found various methods that provide the same functionality as the GUI, but nothing that would create the system simply using the origin and the bases.

Could someone give me a hint on this?

1

There are 1 best solutions below

1
meshWorker On

I am assuming here, that you are working inside Ansys Mechanical. I found this snippet in the docs and added the 90° counterclockwise rotation function around the y-axis:

def rotate_vector_around_y_axis(vector):
    rotation_matrix = [[0, 0, 1],
                       [0, 1, 0],
                       [-1, 0, 0]]
    rotated_vector = [sum(rotation_matrix[i][j] * vector[j] for j in range(3)) for i in range(3)]
    return rotated_vector

def create_csys_by_origin_and_base(origin,base_vector):

    # Create a new coordinate system
    csys = Model.CoordinateSystems.AddCoordinateSystem()
    
    # place csys origin at arbitrary location
    csys.SetOriginLocation(Quantity(origin[0],"mm"), Quantity(origin[1],"mm"), Quantity(origin[2],"mm"))
    # set base to arbitrary direction

    # rotate base vector
    primary_axis_corresponding = rotate_vector_around_y_axis(base_vector)
    csys.PrimaryAxisDirection = Vector3D(primary_axis_corresponding[0],primary_axis_corresponding[1],primary_axis_corresponding[2])
    
    # force a graphics redraw to update coordinate system graphics annotations
    csys.Suppressed=True
    csys.Suppressed=False
    
origin = [0,25,50]
base_vector = [1,2,3]
create_csys_by_origin_and_base(origin,base_vector)

As I am on 2022R2 the source in the docs looks like this: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v222/en/act_script/act_script_examples_arbitrary_cs.html?q=coordinate%20system

EDIT:

Added rotation matrix since I missed the keyword base vector.