Hi,
I have use Arch.makeRebar() function in my Python script and suddenly noticed one bug present in that function.
Detail description of bug:
When passing all parameters to Arch.makeRebar(baseobj, sketch, diameter, amount, offset), properties of an object is changed but changes are not reflected in GUI. For eg, if we pass amount=6 and diameter=12 property value of rebar object is change but in the GUI it will show only one rebar of default diameter. So, by adding recompute() function this problem is solved.
Pull request: https://github.com/FreeCAD/FreeCAD/pull/677
Regards,
Pull request: added recompute() function to reflect changes in the GUI
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Pull request: added recompute() function to reflect changes in the GUI
one recompute in the end would have probably been sufficient... why did you add so many?
Re: Pull request: added recompute() function to reflect changes in the GUI
Yes, I know but when I have added recompute in the end then again changes like amount and diameter are not reflected in the GUI. That's why I have added five recompute functions and it's working fine now in all situations.DeepSOIC wrote:one recompute in the end would have probably been sufficient... why did you add so many?
Regards,
Re: Pull request: added recompute() function to reflect changes in the GUI
I also don't understand why the 5 recomputes? The makeRebar function can be called only once with all its parameters, to creat a rebar object. To change the parameters of the created rebar, you won't call this function again, but rather manipulate directly the properties of the created object...
Can you explain better what is the problem you encountered?
Can you explain better what is the problem you encountered?
Re: Pull request: added recompute() function to reflect changes in the GUI
Another issue here is that App.ActiveDocument doesn't necessarily need to be the document this object is part of. The correct way would be
or if you only want to recompute the object itself but not the whole document
Code: Select all
obj.Document.recompute()
Code: Select all
obj.recompute()
Re: Pull request: added recompute() function to reflect changes in the GUI
Yes, sure.yorik wrote:I also don't understand why the 5 recomputes? The makeRebar function can be called only once with all its parameters, to creat a rebar object. To change the parameters of the created rebar, you won't call this function again, but rather manipulate directly the properties of the created object...
Can you explain better what is the problem you encountered?
You see in the above image when I passed parameters to Arch.makeRebar(structure_base, sketch, 11, 7, 20), values of Rebar object are changed (i.e. amount=7, diameter=11 and offset=20) but in the GUI only one rebar with default diameter is shown. It will also shown same behaviour if I add recompute() in the end of makeRebar() function.
Steps to reproduce this error:
1. Copy and paste code in the FreeCAD python console.
Code: Select all
import Arch
s = Arch.makeStructure(length=1000.0,width=800.0,height=200.0)
s.Placement.Base = FreeCAD.Vector(0.0,0.0,0.0)
FreeCAD.ActiveDocument.recompute()
Code: Select all
class Rebar_shapes():
def __init__(self, sketch, side_cover, front_cover, bottom_cover, amount, diameter, offset):
selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
face = selected_obj.SubElementNames[0]
face_obj = selected_obj.SubObjects[0]
sketch.MapMode = "FlatFace"
structure_base = App.ActiveDocument.getObject(str(selected_obj.Object.Label))
sketch.Support = [(structure_base, face)]
if face_obj.normalAt(0,0).y == -1:
sketch.addGeometry(Part.LineSegment(App.Vector(face_obj.Vertexes[0].X+side_cover, face_obj.Vertexes[0].Z+bottom_cover,0),App.Vector(face_obj.Vertexes[1].X-side_cover,face_obj.Vertexes[1].Z+bottom_cover,0)),False)
structure = Arch.makeRebar(structure_base, sketch, diameter, amount, offset)
FreeCAD.ActiveDocument.recompute()
s=App.activeDocument().addObject('Sketcher::SketchObject','Sketch')
Rebar_shapes(s,100,10,50,7,11,20)
By adding recompute() after every initializing of property solved the above problem.
Regards,
Re: Pull request: added recompute() function to reflect changes in the GUI
wmayer wrote:Another issue here is that App.ActiveDocument doesn't necessarily need to be the document this object is part of. The correct way would beCode: Select all
obj.Document.recompute() [/quote] Yeah, I got your point and updated my pull request. Now, I used only one [mono]obj.Document.recompute()[/mono] instead of five [mono]FreeCAD.ActiveDocument.recompute()[/mono] and it's working fine. Regards,