FreeCAD slow performance on create many objects

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Sergey
Posts: 2
Joined: Mon Mar 30, 2015 5:39 pm

FreeCAD slow performance on create many objects

Post by Sergey »

Hi, all!
My task create FreeCAD document containing about 500000-1000000 simple objects (2D rectangles, 2D circles, polylines)

I wrote simple test script to insert rectangles to FreeCAD document.

When I try insert about 10000 rectangles, i get wery low performance. It takes wery long time to complete.

for x in range(0,10000):
print("creating element no: %d"%(x))
pl = FreeCAD.Placement()
pl.Base = FreeCAD.Vector(x*10,0,0)
rec = Draft.makeRectangle(length=5,height=2,placement=pl,face=False,support=None)
#wery slow for loop
##save document fast
FreeCAD.getDocument("Unnamed").saveAs("test_freecad.fcstd")

There is possibility to write faster code?
** I try to do this way
AAD = FreeCAD.ActiveDocument
for x in range(0,10000):
c = Part.makeCircle(5)
c.Placement.Base = FreeCAD.Vector(x*10,0,0)
shapeobj = AAD.addObject("Part::Feature","circle"+str(x))
shapeobj.Shape = c
**
This code work much faster, but all objects has Visibility = False
and shapeobj.ViewObject.Visibility = True raise Exception because shapeobj.ViewObject seems Null

Second question:
When i open document with 10000 rectangles, FreeCAD frozen for along time (about 1 minute on my laptop with Core i7 and 32GB ram). So question - it is not possible to view document with 1000000 simple objects?

Regards, Sergey.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: FreeCAD slow performance on create many objects

Post by ickby »

It is definitly impossible if if you create a document object for every object. Just imaging 1 million objects in your tree, what shall be the purpose of that?

What should work is to add all those geometries into one shape. My machine, 6 year old notebook, manages 250000, so a new machine should be able to do a million:

Code: Select all

shapes = [];
for x in range(0,500):
	for y in range(0,500):
		c = Part.makeCircle(5)
		c.Placement.Base = FreeCAD.Vector(x*10,y*10,0)
		shapes.append(c)

p = Part.makeCompound(shapes)
Part.show(p)
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: FreeCAD slow performance on create many objects

Post by ickby »

oh, and make sure your default deviation setting is not too small (mine is 0.5) as this would kill your visualization speed easily
User avatar
yorik
Founder
Posts: 13664
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: FreeCAD slow performance on create many objects

Post by yorik »

Indeed this is a main limitation of FreeCAD. You must manage the number of document objects. Unlike apps like AutoCAD, here each object is a powerful and complex entity, and therefore their max number is not infinite.
Sergey
Posts: 2
Joined: Mon Mar 30, 2015 5:39 pm

Re: FreeCAD slow performance on create many objects

Post by Sergey »

Hi, all!
Thank You for reply.
This way with one Document Object is working. Now I can view about 500 000 -700 000 circles in one shape without problem. On a 1000 0000 circles i have some periodical freezes on 20 sec but can view document.

I run script directly as python script on a server and object document has property Visibility = False
Can set it to True?
FreeCADGui.getDocument("Untitled").getObject("Shape").Visibility = True - not working in a script.
Post Reply