How do we prevent new parts from being displayed?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
JonathanBelnoue
Posts: 10
Joined: Fri Jan 19, 2018 4:01 pm

How do we prevent new parts from being displayed?

Post by JonathanBelnoue »

Hello,

I think that is a relatively simple problem but I do not seem to be able to find my way around it. I am creating a number of parts from a python script, check their intersections and create new parts for the intersection (subtracting the intersection from the original part). Anyway, this procedure requires me to use a number of addObject and getObject commands which end up displaying my parts. This is slowing the code down quite substantially and I was wondering how I can avoid this.
Any ideas?

Many thanks in advance
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: How do we prevent new parts from being displayed?

Post by microelly2 »

yourPart.ViewObject.Visibility=False
JonathanBelnoue
Posts: 10
Joined: Fri Jan 19, 2018 4:01 pm

Re: How do we prevent new parts from being displayed?

Post by JonathanBelnoue »

Thanks for your answer again. It works but it was not what was slowing down my code... :-( Bad guess!
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: How do we prevent new parts from being displayed?

Post by TheMarkster »

Depending on the objects it might not be necessary to show them in order to use them.
JonathanBelnoue
Posts: 10
Joined: Fri Jan 19, 2018 4:01 pm

Re: How do we prevent new parts from being displayed?

Post by JonathanBelnoue »

Yes this was my thinking but either the addObject command or the GetObject one seems to dispay them automatically. The solution above only seems to erase them immediately after displaying them which does not not help in terms of code speed.
User avatar
Chris_G
Veteran
Posts: 2601
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: How do we prevent new parts from being displayed?

Post by Chris_G »

Document.addObject() creates high-level FreeCAD objects, that are parametric (through their properties), but also more resource hungry.
Taking a Cone as an example :

Code: Select all

cone = App.ActiveDocument.addObject("Part::Cone","Cone")
# creates a high-level, parametric FreeCAD object, that will appear in the Tree-View

cone_shape = Part.makeCone(2,3,4)
# creates an OpenCascade solid. Much more lightweight, but not parametric.
# since it is a solid, it will work with Boolean operations, etc ...

cone_surface = Part.Cone()
# here, we get a geometry surface. Very low-level, since it needs to be bounded, 
# and combined with circle faces to build the same kind of cone as above
First option is good if you want to expose the object to the user, and offer him the ability to tweak the object (through its properties).
Second option is IMHO more suited for scripting.
I don't know the kind of objects you are working with, so I can't say much more, but maybe you could try to work with OpenCascade shapes.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: How do we prevent new parts from being displayed?

Post by microelly2 »

there are two phases where computation time is required
one is the call of toShape() (A)
and the other is the rendering in the 3D scene (B).

if you first set the view object hidden and than set the Shape you can skip the render time (B).

If you only need the internal data of a part and not realy the shape you can skipt the toShape() call.
In this case you do not see anything but you still have the data.

I use this when I work with large BSpline Surfaces. I hold the data (poles. mutiplicities ... ) in background and can do calculations on it.
Sometimes when I need some detail to display I only use a small segment of the nurbs, create the shape and display it.
For the remaining data I use faster representations like point clouds or meshes.
phpBB [video]
JonathanBelnoue
Posts: 10
Joined: Fri Jan 19, 2018 4:01 pm

Re: How do we prevent new parts from being displayed?

Post by JonathanBelnoue »

Thanks all, really nice and helpful community here. I can always find someone knowledgeable who can help getting around the problems I face.
From your last 2 comments it looks clear that what I want is to not create an object and keep the data at the background. Many thanks!
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: How do we prevent new parts from being displayed?

Post by microelly2 »

Here some results from my current work which illustrate my tipp.
I store the calculated shape of a BSplineSurface selfShape to an other object

the rintime results
savetime hidden 0.000312805175781
savetime show 0.506098031998
savetime intern 8.10623168945e-06

if the part is hidden the store of the shape is factor 1000 faster than when it is displayed.

Code: Select all


obj=App.ActiveDocument.addObject('Part::Spline','result')

tt=time.time()
obj.ViewObject.hide()
obj.Shape=self.Shape
print "savetime hidden ",time.time()-tt

tt=time.time()
obj.ViewObject.show()
obj.Shape=self.Shape
print "savetime show ",time.time()-tt

tt=time.time()
z=self.Shape
z=self.Shape
print "savetime intern ",time.time()-tt


Post Reply