using removeSplitter() changes position of part

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
basnijholt
Posts: 4
Joined: Mon Sep 27, 2021 9:08 pm
Contact:

using removeSplitter() changes position of part

Post by basnijholt »

I am doing the following and I am trying to assert whether this is expected behavior?

Execute the following in the Python console:

Code: Select all

from freecad import app as FreeCAD
import Draft

doc = FreeCAD.newDocument("testDoc")
box1 = doc.addObject("Part::Box", "Box1")
doc.recompute()
box2 = Draft.move(box1, FreeCAD.Vector(1, 0, 0), copy=True)
doc.recompute()
Now it shows a second box that is moved.

Image

If I now run the following code:

Code: Select all

box2.Shape = box2.Shape.removeSplitter()
doc.recompute()
Suddenly box2 shifts back to the old position.

Image

Is this expected? If yes, how can I use removeSplitter() such that the position of the object stays fixed.


I am using:

OS: macOS 10.16
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24291 (Git)
Build type: Release
Branch: (HEAD detached at 0.19.2)
Hash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.8
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.4.0
Locale: C/Default (C)
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: using removeSplitter() changes position of part

Post by TheMarkster »

These are parametric primitive objects. If you try to change the Shape property like this it will be overwritten when the object recomputes itself.

Make it a Part::Feature instead of a Part::Box and then you can change its Shape property.

Code: Select all

from freecad import app as FreeCAD
import Draft

#doc = FreeCAD.newDocument("testDoc")
#box1 = doc.addObject("Part::Box", "Box1")
#doc.recompute()
#box2 = Draft.move(box1, FreeCAD.Vector(1, 0, 0), copy=True)
#doc.recompute()
#
#box2.Shape = box2.Shape.removeSplitter()
#doc.recompute()

doc = FreeCAD.newDocument("testDoc")
box1 = doc.addObject("Part::Feature", "Box1")
doc.recompute()
box1.Shape = Part.makeBox(10,10,10)
box2 = Draft.move(box1, FreeCAD.Vector(1, 0, 0), copy=True)
doc.recompute()

fusion = box2.Shape.fuse(box1.Shape)
Part.show(fusion,"fusion")

box2.Shape = fusion.removeSplitter()
doc.recompute()
basnijholt
Posts: 4
Joined: Mon Sep 27, 2021 9:08 pm
Contact:

Re: using removeSplitter() changes position of part

Post by basnijholt »

Thanks a lot!

Strangely, in FreeCAD 0.19 alpha2 this used to work, so in our work, we came to rely on it :D

Good to know that I can just make a Part::Feature and overwrite the Shape.
Post Reply