Create and position LCS through a macro

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Ningrich3
Posts: 12
Joined: Mon Jul 18, 2022 4:18 am

Create and position LCS through a macro

Post by Ningrich3 »

Hello everyone,

I was wondering if there is a way to create a datum such as an LCS by means of Python alone.

My concern is that when building an assembly in Assembly 4 I make extensive use of LCS in order to place components relative to each other.
This works just fine.
However, creating LCS using the GUI is a bit of a drag when it's got to be a larger quantity.
I did figure out that

Code: Select all

App.ActiveDocument.getObject("Part").addObject('PartDesign::CoordinateSystem','LCS_1'
creates the LCS, but how to select a reference (for example XY_Plane --> XY on Plane) and offsets in x-,y- and z-direction and rotations?

If possible at all, some Python snippets to start from would be greatly appreciated! :)
edi
Posts: 481
Joined: Fri Jan 17, 2020 1:32 pm

Re: Create and position LCS through a macro

Post by edi »

The created LCS has a Placement, which can be used to move or rotate it:

Code: Select all

from FreeCAD import Vector
LCS_1=FreeCAD.ActiveDocument.addObject(PartDesign::CoordinateSystem','LCS_1')
LCS_1.Placement.move(Vector(10,20,0))
moves the origin of the LCS to position (10,20,0)
Ningrich3
Posts: 12
Joined: Mon Jul 18, 2022 4:18 am

Re: Create and position LCS through a macro

Post by Ningrich3 »

Thank you very much,
that seems to work.
Post Reply