FreeCAD slow performance on create many objects

Need help, or want to share a macro? Post here!
Sergey
Posts: 2
Joined: Mon Mar 30, 2015 5:39 pm

FreeCAD slow performance on create many objects

Postby Sergey » Mon Mar 30, 2015 6:30 pm

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
Posts: 2960
Joined: Wed Oct 05, 2011 7:36 am

Re: FreeCAD slow performance on create many objects

Postby ickby » Mon Mar 30, 2015 7:11 pm

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
Posts: 2960
Joined: Wed Oct 05, 2011 7:36 am

Re: FreeCAD slow performance on create many objects

Postby ickby » Mon Mar 30, 2015 7:13 pm

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
Site Admin
Posts: 11845
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: FreeCAD slow performance on create many objects

Postby yorik » Tue Mar 31, 2015 2:00 pm

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

Postby Sergey » Tue Mar 31, 2015 8:08 pm

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.