Export Mesh in Local Coordinate System

Georges Vacher
Georges Vacher Member Posts: 3
First Comment Photogenic
**

Hello

In mechanical scripting, is there a simple method to get mesh coordinates in a local coordinate system (cartesian).
Do I have to program the transformation myself or can I use some already programmed methods ?
I found something with 4x4 matrix, but I'm too old for that ...

Thanks

Comments

  • Georges Vacher
    Georges Vacher Member Posts: 3
    First Comment Photogenic
    **

    Oups sorry

    It was quite easy to do with csys.matrix...
    Just surprised there is no method to do this natively

    bye

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 345
    25 Answers 100 Comments 25 Likes First Anniversary
    ✭✭✭✭

    FYI you can use some DPF operators to rotate data to a given CS (matrix).

    import mech_dpf
    import Ans.DataProcessing as dpf

    def RotationMatrixFieldFromCS(CsName):
    """

    """
    CS = ExtAPI.DataModel.GetObjectsByName(CsName)[0]
    CsMatrix = list(CS.Matrix)
    TransformMatrix = [CsMatrix[i] for i in [0,3,6,1,4,7,2,5,8]]
    rot_mat_f = dpf.FieldsFactory.CreateScalarField(1)
    rot_mat_f.Data = TransformMatrix
    return rot_mat_f
    

    def RotationOperatorFromCs(CsName, FieldsContainer):
    """
    """
    rot_mat_f=RotationMatrixFieldFromCS(CsName)
    RotateOp = dpf.operators.geo.rotate_fc() # operator instantiation
    RotateOp.inputs.fields_container.Connect(FieldsContainer)
    RotateOp.inputs.coordinate_system.Connect(rot_mat_f)
    return RotateOp

    def AlignFieldToCs(CsName, FieldsContainer):
    """
    Take a field and align it to a local CS in Mechanical by its Name
    """
    RotateOp=RotationOperatorFromCs(CsName, FieldsContainer)
    RotField=RotateOp.outputs.fields_container.GetData()
    return RotField

    def ObjByName(Name):
    return ExtAPI.DataModel.GetObjectsByName(Name)[0]

  • Georges Vacher
    Georges Vacher Member Posts: 3
    First Comment Photogenic
    **

    Thanks Mike for this method.
    I'm not familiar with DPF, but I'll try to learn how to use it.