Just realized in Arch it is not possible to parse the document the object is created in if use Arch.makeSomeSmartArchObject(parameters). The active document is used for all Arch make methods.
Mhh IMHO in no document is given the active should be used. For robustness it would makes sense to parse the doc the object is created in, would it not?
ATM I need to explizit set the ActiveDocument with the doc object I would like object to be created in. If not I get a miss match if creating documents objects inside the document and closing the document in a loop.
cheers bernd
specify document in Arch make methods
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: specify document in Arch make methods
Do you mean something like this?
Code: Select all
doc1 = App.openDocument("Doc1")
doc2 = App.openDocument("Doc2")
Arch.make_something(doc1, args)
Arch.make_something(doc2, args)
So, changing this would mean refactoring the entire programming interface which would take a while, and could potentially break things.
The easiest thing that I can think about is adding an additional argument at the end to consider the document.
Code: Select all
def make_something(args, doc=None):
if not doc:
doc = App.activeDocument()
Last edited by vocx on Tue Sep 15, 2020 4:02 pm, edited 1 time in total.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: specify document in Arch make methods
exactly.
In FEM all make methods have a document parameter. In FEM it is at the end, which is cumbersome if you would like to use the active document, because you need to add it all the time. But IMHO better than no doc parameter.
I am curious what others think about this.
In FEM all make methods have a document parameter. In FEM it is at the end, which is cumbersome if you would like to use the active document, because you need to add it all the time. But IMHO better than no doc parameter.
I am curious what others think about this.
Re: specify document in Arch make methods
You're reading my mind
Yes, this is very much needed. For compatibility reasons, you have to make the document optional, but in reality, you can't create objects outside the document, can you? C++ defines "addObject" function as a method of a Document.
Maybe similarly Python should have it's own DocumentProxy?
E.g.
but maybe that's complicated. A simple additional parameter would do.
Yes, this is very much needed. For compatibility reasons, you have to make the document optional, but in reality, you can't create objects outside the document, can you? C++ defines "addObject" function as a method of a Document.
Maybe similarly Python should have it's own DocumentProxy?
E.g.
Code: Select all
class DocumentProxy:
def __init__(self, doc):
if not doc:
raise Error("No active document. Aborting")
self.doc = doc
def addObject(self, proxy_class, arguments, name, cpp_type = 'Part::FeaturePython'):
obj = self.doc.addObject(cpp_type, name)
proxy_obj = proxy_class(obj)
obj.Proxy = proxy_obj
return obj
def makeWall(doc, *args):
wall = doc.addObject(_Wall, args, 'wall', )
Re: specify document in Arch make methods
FYI: you can not create document objects outside of a document, but in Part one can create shape objects without the need to create a document object. Arch, Draft and most FEM objects do not support this either. But this is a totally different story even more complicated to change.
Re: specify document in Arch make methods
I agree with that as well. vocx's solution seems the easiest, to maintain backwards compatibility...