Proper way to fully delete an object
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Proper way to fully delete an object
Hello everybody,
I use a script that repeatedly makes some objects inside a document, computes some volumes and deletes the objects afterwards. I use the removeObject method of the Document-class to do that. This seems to work as they are no longer present in App.ActiveDocument.Objects. However, I noticed that the computations get very slow after a while and I suspect that the deleted objects are still somewhere in the memory. If I close the document and open a new one this does not happen.
Is there another way to fully delete the objects in the document?
Best regards,
Dominik
I use a script that repeatedly makes some objects inside a document, computes some volumes and deletes the objects afterwards. I use the removeObject method of the Document-class to do that. This seems to work as they are no longer present in App.ActiveDocument.Objects. However, I noticed that the computations get very slow after a while and I suspect that the deleted objects are still somewhere in the memory. If I close the document and open a new one this does not happen.
Is there another way to fully delete the objects in the document?
Best regards,
Dominik
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: Proper way to fully delete an object
removeObject should do the job,
how many objects do you create temporary and delete them again?
how many objects do you create temporary and delete them again?
Re: Proper way to fully delete an object
you could try to disable the transactions (undo/redo) as this keeps the objects in memory. The document has a proeprty for that, don't remember the exact name right now... something like: mydoc.UndoMode = 0
Re: Proper way to fully delete an object
Around 100000.microelly2 wrote: ↑Mon Oct 15, 2018 9:12 am removeObject should do the job,
how many objects do you create temporary and delete them again?
Thank you! I will try that and see if it helps.
- microelly2
- Veteran
- Posts: 4688
- Joined: Tue Nov 12, 2013 4:06 pm
- Contact:
Re: Proper way to fully delete an object
if you only calculate some geometric values you need not to create a document object.
You can hold the shape information in memory
You can hold the shape information in memory
Re: Proper way to fully delete an object
I need some objects stored in a template file, add some more objects programmatically, perform some boolean operations and finally calculate some volumes. I don't think I can do that without a document.if you only calculate some geometric values you need not to create a document object.
You can hold the shape information in memory
Unfortunately, UndoMode = 0 did not work. I still have got the issue that the computations slow down after a lot of evaluations. If nobody else has an idea how to fix this, I guess I have to stick with reloading the document from time to time.
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: Proper way to fully delete an object
Document object doesn't refer to the document; it refers to the objects, example "Cut" is a Document object. Microelly2's suggestion is to create the object in memory, but don't add it to the document.kaktus018 wrote: ↑Thu Oct 18, 2018 7:23 pmI need some objects stored in a template file, add some more objects programmatically, perform some boolean operations and finally calculate some volumes. I don't think I can do that without a document.if you only calculate some geometric values you need not to create a document object.
You can hold the shape information in memory
Unfortunately, UndoMode = 0 did not work. I still have got the issue that the computations slow down after a lot of evaluations. If nobody else has an idea how to fix this, I guess I have to stick with reloading the document from time to time.
So, instead of:
Code: Select all
cyl = App.ActiveDocument.addObject("Part::Cylinder","Cylinder")
App.ActiveDocument.ActiveObject.Label = "Cylinder"
App.ActiveDocument.recompute()
print(str(cyl.Shape.Volume))
Code: Select all
import Part
cyl2 = Part.makeCylinder(10,2) #radius 10, height 2
print(str(cyl2.Volume))
Try this:
Code: Select all
cyl.Shape = cyl2
Re: Proper way to fully delete an object
Alright, that's indeed an option. I don't know if I will change the scripts but I'm pretty certain that this will also solve my issue. Thanks!