Changing Shape of Part::Feature resets its Placement?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Roy_043
Veteran
Posts: 8576
Joined: Thu Dec 27, 2018 12:28 pm

Changing Shape of Part::Feature resets its Placement?

Post by Roy_043 »

I am trying to create a Part::Feature and notice that changing its Shape will reset its Placement. Is the expected behavior?

Code: Select all

import FreeCAD as App
import Draft
import Part

pts = [App.Vector( 2, 1, 0),
       App.Vector( 6, 1, 0),
       App.Vector( 6, 4, 0),
       App.Vector( 2, 4, 0)]
shp = Part.Shape([Part.LineSegment(pts[0], pts[1]),
                  Part.LineSegment(pts[1], pts[2]),
                  Part.LineSegment(pts[2], pts[3]),
                  Part.LineSegment(pts[3], pts[0])])
pl = App.Placement()
pl.Base = pts[0] # bottom left point is also center for scaling.
obj = App.ActiveDocument.addObject("Part::Feature")
obj.Placement = pl
print(obj.Placement)
obj.Shape = shp
print(obj.Placement)
App.ActiveDocument.recompute()
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Changing Shape of Part::Feature resets its Placement?

Post by ickby »

Yes, it is.

The Part::Feature placement is always equal to the Shape placement. If you change Part::Feature placement it writes it into the shape. If you change the shape it writes the shapes placement into Part::Feature. This way you have always consistent Placement of document object and the shape itself if you extract it.

check:
obj.Shape.Placement
User avatar
Roy_043
Veteran
Posts: 8576
Joined: Thu Dec 27, 2018 12:28 pm

Re: Changing Shape of Part::Feature resets its Placement?

Post by Roy_043 »

Thanks for your answer.
Post Reply