Skip to content

How to transform global axis into local using python in cadwork? #128

Description

@lucas-ita

Hi,
Could someone please share a code snippet utilizing the apply_transformation_coordinate(elements, old_point, old_xl, old_yl, new_point, new_xl, new_yl) method? To aid our understanding, let's consider a practical example involving an inclined beam in Cadwork. Let's envision placing the beam in a scene and, subsequently, using the mentioned method to transform the global axis into local coordinates. The expected outcome is that the beam no longer remains inclined.

Activity

  1. Brunner246 commented on Feb 28, 2024

    @Brunner246
    Contributor

    you could do something like this

    from typing import List
    
    import cadwork
    import element_controller as ec
    import geometry_controller as gc
    
    
    def get_element_orientation_and_position(element_id: int):
        point1 = gc.get_p1(element_id)
        x_direction = gc.get_xl(element_id)
        y_direction = gc.get_yl(element_id)
        return point1, x_direction, y_direction
    
    
    def transform_element(element_id: int, point1_new: cadwork.point_3d, x_direction_new: cadwork.point_3d,
                          y_direction_new: cadwork.point_3d):
        point1_old, x_direction_old, y_direction_old = get_element_orientation_and_position(element_id)
        ec.apply_transformation_coordinate([element_id],
                                           point1_old,
                                           x_direction_old,
                                           y_direction_old,
                                           point1_new,
                                           x_direction_new,
                                           y_direction_new)
    
    
    if __name__ == '__main__':
        element_ids: List[int] = ec.get_user_element_ids()
    
        x_direction_new = cadwork.point_3d(1., 0., 0.)
        y_direction_new = cadwork.point_3d(0., 1., 0.)
    
        for element_id in element_ids:
            point1_new = gc.get_p1(element_id) # or set your preferred position
            transform_element(element_id, point1_new, x_direction_new, y_direction_new)
  2. locked and limited conversation to collaborators on Feb 29, 2024
  3. converted this issue into a discussion #129 on Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions