0

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jake77
  • 1,892
  • 2
  • 15
  • 22

1 Answers1

0

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.

meshWorker
  • 183
  • 2
  • 13
  • I know this. This defines the primary axis only, directly defining the secondary etc. is not possible. As it turns out, there is no way to directly define a CS by its base. – jake77 Jun 17 '23 at 10:03