incorprate all Placement into shape coordinates

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

incorprate all Placement into shape coordinates

Post by bernd »

if removeSplitter() is used on a Shape the Shape returned has all placement incorporated into the vertices coordinates. What is the best way to archieve this without removeSplitter(), because this methods cleans the Shape. Is there any method around or does this needs to be done manually?

cheers bernd
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: incorprate all Placement into shape coordinates

Post by onekk »

bernd wrote: Thu Apr 13, 2023 6:35 am if removeSplitter() is used on a Shape the Shape returned has all placement incorporated into the vertices coordinates. What is the best way to archieve this without removeSplitter(), because this methods cleans the Shape. Is there any method around or does this needs to be done manually?

cheers bernd
You have to do some tests, as it probably is due to the copy that removeSplitter() probably is doing:

Some hints from:

https://forum.freecadweb.org/viewtopic. ... 74#p603474

Code: Select all

# deep copy = waste of memory and nullify shape compare API
dp_copy = shape.copy()

# shallow copy
sh_copy = Part.Shape(shape)
Hope it helps.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: incorprate all Placement into shape coordinates

Post by bernd »

both do not incorporate the Placement into the vertices coordinates. They keep the placment in the placement not in the vertices coordinates ...
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: incorprate all Placement into shape coordinates

Post by onekk »

bernd wrote: Thu Apr 13, 2023 9:33 am ...
Probably removeSplitter() will make some other operations, I usually see this behaviour when I make as example a Boolean operation, the new object will have a null Placement and retain the "relative position" of original objects.

try eventually if:

Code: Select all

help(Part.Shape.copy())
has some argument, sadly I'm on mobile, so no way to check directly, but I have some reminescence of the presence of some arguments.

Hope it helps.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: incorprate all Placement into shape coordinates

Post by bernd »

Code: Select all

 |  copy(...)
 |      Create a copy of this shape
 |      copy(copyGeom=True, copyMesh=False) -> Shape
 |      --
 |      If copyMesh is True, triangulation contained in original shape will be
 |      copied along with geometry.
 |      If copyGeom is False, only topological objects will be copied, while
 |      geometry and triangulation will be shared with original shape.
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: incorprate all Placement into shape coordinates

Post by onekk »

Sadly is not what I remembered.

I don't know what person to poke exactly.

@edwilliams16, @chrisb, @Chris_G or even @wmayer are usually my source of informations and people whom I discuss this sort of things.

Let's see if some help could came from them. :D

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: incorprate all Placement into shape coordinates

Post by wmayer »

bernd wrote: Thu Apr 13, 2023 6:35 am if removeSplitter() is used on a Shape the Shape returned has all placement incorporated into the vertices coordinates.
The placement of the top-level shape is applied to the direct child shapes and not only to the vertexes.
What is the best way to archieve this without removeSplitter(), because this methods cleans the Shape.
Since you talk about removeSplitter() that works for shells and solids: You can move the top-level placement to the children with

Code: Select all

shape = ...
clean_shape = Part.Shell(shape.Faces)
Internally the attribute Faces uses TopExp_Explorer which when iterating over sub-elements applies the placement of the parent shape.
So, assuming you have applied a placement to shape then shape.Placement has the same output as shape.Face1.Placement because when accessing Face1 with TopoExp_Explorer it copies the placement of shape to the accessed sub-shape.

Another way of iterating over sub-shapes is TopoDS_Iterator which provides an option to ignore the placements of parent shapes. The Python API provides this function with shape.childShapes(). But this method only allows you to access direct children and no grandchildren. So, if your shape is a solid you can only access the shell and from the shell you can access the faces.

Example:

Code: Select all

box = Part.makeBox(1,1,1)
box.Placement.isIdentity() # True

box.Placement.Base = App.Vector(1,2,3)
box.Placement.isIdentity() # False

box.Face1.Placement.isIdentity() # False

# Get the sub-shape without placement of parent shape
shells = box.childShapes(False, False)
shells[0].Placement.isIdentity() # True, means the shell itself has no placement set
faces = shells[0].childShapes(False, False)
faces[0].Placement.isIdentity() # True

# Create a cleaned box
cleaned_box = Part.Solid(Part.Shell(box.Faces))
cleaned_box.Face1.Placement.isIdentity() # False, is OK
cleaned_box.Placement.isIdentity() # True, is what we want

# If you display the two boxes with 
Part.show(box)
Part.show(cleaned_box)

# you will see that they are coincident. In the property editor you can see that the placement
# of the one object is a translation set and the other object not.
chrisb
Veteran
Posts: 53945
Joined: Tue Mar 17, 2015 9:14 am

Re: incorprate all Placement into shape coordinates

Post by chrisb »

Just to report back: I am of no help here.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
Roy_043
Veteran
Posts: 8456
Joined: Thu Dec 27, 2018 12:28 pm

Re: incorprate all Placement into shape coordinates

Post by Roy_043 »

Alternatively you can use transformGeometry:

Code: Select all

import Part

box = Part.makeBox(1,1,1)
box.Placement.Base = App.Vector(1,2,3)
Part.show(box)
print(box.Placement.isIdentity()) # False

new = Part.Shape(box)
new = new.transformGeometry(new.Placement.Matrix)
new.Placement = App.Placement()
Part.show(new)
print(new.Placement.isIdentity()) # True
print(new.Face1.Placement.isIdentity()) # True
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: incorprate all Placement into shape coordinates

Post by bernd »

lots of stuff to read and test ... thanks guys ...

BTW: This is why I am asking ... viewtopic.php?p=675641#p675254
Post Reply