[Solved] Shape get back around origin
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
[Solved] Shape get back around origin
I'm learning python, and I'm trying to build a parametric object like a egg.
After moved it on Z axle, and when I change a parameter It's remade around the origin.
How I can avoid that?
After moved it on Z axle, and when I change a parameter It's remade around the origin.
How I can avoid that?
- Attachments
-
- Ovoide.py
- (1.76 KiB) Downloaded 27 times
Last edited by Vincent B on Tue Nov 12, 2019 7:40 pm, edited 1 time in total.
Re: Shape get back around origin
Salut GlouGlou,
Very challenging for learning Python.
I only have a very quick look (not easy to understand without any comment in the code), but I saw this line in execute() :
In this line, Z is always set to 0.
Don't know if it's the reason, but the only clue I have for you ATM.
Very challenging for learning Python.
I only have a very quick look (not easy to understand without any comment in the code), but I saw this line in execute() :
Code: Select all
matriz.append(FreeCAD.Vector(x,y,0))
Don't know if it's the reason, but the only clue I have for you ATM.
Re: Shape get back around origin
z still =0 because it's a 2D curve.
If you move a cube or any shape (placement), and change his parameter, it don't come back on origins.
What I have missed?
If you move a cube or any shape (placement), and change his parameter, it don't come back on origins.
What I have missed?
Re: Shape get back around origin
Hi GlouGlou,
Don't have a very precise explanation ATM, but it solves the problem if I delete the 'onChanged' function (which seems useless as the 'execute' function is launched automatically as soon as a property --placement, radius, ...-- is changed).
The weird thing is that when 'execute' is launched from your macro with the line :
then the placement is reset by the line :
In other cases (when 'execute' is self launched by FC), the latter line doesn't reset the placement. I can't explain why ATM...
Don't have a very precise explanation ATM, but it solves the problem if I delete the 'onChanged' function (which seems useless as the 'execute' function is launched automatically as soon as a property --placement, radius, ...-- is changed).
The weird thing is that when 'execute' is launched from your macro with the line :
Code: Select all
self.execute(fp)
Code: Select all
fp.Shape = curve.toShape()
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Shape get back around origin
In execute(..), assign Placement attribute of the shape to fp.Placement before assigning the Shape property.
When FreeCAD recompute's your feature, it does that internally. However, from onChanged, it is not done implicitly, so you should do it explicitly.
When FreeCAD recompute's your feature, it does that internally. However, from onChanged, it is not done implicitly, so you should do it explicitly.
Re: Shape get back around origin
Well corroborate what happens, but not clear for me how to assign the placement.
ATM I can only see the (obviously useless) :
Code: Select all
fp.Placement = fp.Placement
Code: Select all
currPlacement = fp.Placement
fp.Shape = ... # change shape here
fp.Placement = currPlacement #re-assign placement
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Shape get back around origin
No.
This is how the end of your execute should look like:
This is how the end of your execute should look like:
Code: Select all
...
if fp.createFace == True:
sh = Part.Face(Part.Wire(curve.toShape()))
else:
sh = curve.toShape()
sh.Placement = fp.Placement
fp.Shape = sh
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Shape get back around origin
BTW, I wanted to find that piece of code in C++, but I can't. Probably, realthunder changed it. So I'm not sure about how it all works now.
Re: Shape get back around origin
Thanks @DeepSOIC
Re: Shape get back around origin
Thanks a lot.
next step: insert a icon inside the tree view.