FreeCAD 0.17R10088 breaks Screw-maker

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

FreeCAD 0.17R10088 breaks Screw-maker

Post by ulrich1a »

The commit https://github.com/FreeCAD/FreeCAD/comm ... 66d8cc7204 breaks the screw placement in Screw-maker.
The following code does not move the screw into its place anymore. Is this intended with the commit, or is this a bug?

Code: Select all

          pl = FreeCAD.Placement()
          pl.Rotation = (normvec.x,normvec.y,normvec.z,cos_res) #Drehungs-Quaternion
          neuPlatz = ScrewObj_m.Placement
          neuPlatz.Rotation = pl.Rotation.multiply(ScrewObj_m.Placement.Rotation)
          neuPlatz.move(Pnt1)
Ulrich
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: FreeCAD 0.17R10088 breaks Screw-maker

Post by DeepSOIC »

This is a fundamental problem as far as I understand. When you read out something.Placement, it is actually returns a copy of something's placement, which remembers that it's an attribute of object.

If you read out something.Placement again, a new copy will be returned, and the old copy will lose connection to "something". It may be very tricky to fix... Let's see what Werner thinks.
wmayer
Founder
Posts: 20308
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: FreeCAD 0.17R10088 breaks Screw-maker

Post by wmayer »

Sorry for the late reply but I didn't notice this thread earlier.

Based on your code snippets I put together this example which worked in 0.16 as you expect it.

Code: Select all

ScrewObj_m=App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.recompute()

pl = FreeCAD.Placement()
pl.Rotation = (1,1,1,0.5) #Drehungs-Quaternion
neuPlatz = ScrewObj_m.Placement
neuPlatz.Rotation = pl.Rotation.multiply(ScrewObj_m.Placement.Rotation)
neuPlatz.move(App.Vector(2,4,6))
But now look at this example

Code: Select all

ScrewObj_m=App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.recompute()

pl = FreeCAD.Placement()
pl.Rotation = (1,1,1,0.5) #Drehungs-Quaternion
neuPlatz = ScrewObj_m.Placement
neuPlatz.Rotation = pl.Rotation.multiply(ScrewObj_m.Placement.Rotation)
ScrewObj_m.Placement = FreeCAD.Placement()
neuPlatz.move(App.Vector(2,4,6))
It has only one additional line

Code: Select all

ScrewObj_m.Placement = FreeCAD.Placement()
to overwrite the old placement so that neuPlatz isn't the placement of ScrewObj_m any more. But the code still shows the same effect because internally neuPlatz still knows about its previous "parent" object and thus applies the transformation to it which is clearly wrong.

To fix your problem with the new version you have to explicitly assign the placement again at the end

Code: Select all

ScrewObj_m=App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.recompute()


pl = FreeCAD.Placement()
pl.Rotation = (1,1,1,0.5) #Drehungs-Quaternion
neuPlatz = ScrewObj_m.Placement
neuPlatz.Rotation = pl.Rotation.multiply(ScrewObj_m.Placement.Rotation)
neuPlatz.move(App.Vector(2,4,6))
ScrewObj_m.Placement = neuPlatz
Post Reply