Code: Select all
App.DocumentObject.evalExpression('2+2')
Code: Select all
obj = App.ActiveDocument.addObject('App::FeaturePython')
obj.ViewObject.ShowInTree = False
obj.evalExpression('2+2')
Code: Select all
App.DocumentObject.evalExpression('2+2')
Code: Select all
obj = App.ActiveDocument.addObject('App::FeaturePython')
obj.ViewObject.ShowInTree = False
obj.evalExpression('2+2')
Code: Select all
App.DocumentObject().evalExpression('2+2')
Code: Select all
>>> App.DocumentObject().evalExpression('2+2')
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: You cannot create directly an instance of 'DocumentObjectPy'.
Code: Select all
>>> App.DocumentObject.evalExpression('2+2')
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: descriptor 'evalExpression' for 'App.DocumentObject' objects doesn't apply to a 'str' object
Doesn't work either. Message:openBrain wrote: ↑Wed Sep 22, 2021 12:50 pmCode: Select all
App.DocumentObject().evalExpression('2+2')
Code: Select all
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: You cannot create directly an instance of 'DocumentObjectPy'.
Unfortunately this is what I expected but want to give a try though...Zoltan wrote: ↑Wed Sep 22, 2021 12:56 pm @openBrain
Makes sense to try the evalExpression on the object and not on the class. However, it does not work either (seems to be an abstract class). Here are the tracebacks:Code: Select all
>>> App.DocumentObject().evalExpression('2+2') Traceback (most recent call last): File "<input>", line 1, in <module> RuntimeError: You cannot create directly an instance of 'DocumentObjectPy'.
Code: Select all
if App.ActiveDocument and App.ActiveDocument.Objects:
App.ActiveDocument.Objects[0].evalExpression("3*2")
True, but I cannot count on the fact that at least one document object exists.TheMarkster wrote: ↑Wed Sep 22, 2021 5:13 pm You could check to see if there are any objects in the document already and use one of them.
Is there a way to make a document object that does not appear in the tree? I know there is a context menu option to hide the object, but it still appears in the tree, but with some kind of overlay added to the icon.Code: Select all
if App.ActiveDocument and App.ActiveDocument.Objects: App.ActiveDocument.Objects[0].evalExpression("3*2")
Snip macro screenshot-aedc86.png
Code: Select all
obj.ViewObject.ShowInTree = False
You can't count on it, but by checking first you can avoid creating one unnecessarily in some instances.
Ah, yes, thanks. I overlooked that (ShowInTree) in your post. I might be able to use this for something I have on the back burner. I experimented by entering it in the python console, but still I get the overlay icon and the object is still in the tree unless I toggle Show Hidden on/off, but I don't know how to do that in python. Maybe it works better in a macro/workbench.The object appears only if the "Show Hidden Items" is enabled in the context menu. You can also hide an item programmatically (as I showed above) byA third way to hide an object: select it, click on the View tab, and then change the Boolean value of the "Show In Tree" property.Code: Select all
obj.ViewObject.ShowInTree = False
Neat trick. I can't seem to reproduce. I don't see anything when I hover the mouse over Show in Tree. Is this in a debugger?By the way, this is how I found this property programmatically: hover your mouse over the "Show In Tree" text to see that its underlying property is "ShowInTree".
Code: Select all
obj.evalExpression("2+2+")
That icon indicates that the object is hidden.I experimented by entering it in the python console, but still I get the overlay icon
If you enable showing the hidden items, they will be shown of course.and the object is still in the tree unless I toggle Show Hidden on/off
Do this:but I don't know how to do that in python
Code: Select all
App.ActiveDocument.ShowHidden = True
Here is a GIF that demonstrates it.I don't see anything when I hover the mouse over Show in Tree.
When you create a document object and add it to the document, it will appear in the tree view (unless you hide it). If you want to work "in-memory", do not associate your custom class object with the Proxy field of a document object.What I would really like to be able to do is create a sketch in memory not in the tree