[SOLVED] Enumerating Property Types and Object Types before opening a Document?

Need help, or want to share a macro? Post here!
Bayesian
Posts: 57
Joined: Thu Aug 08, 2019 1:49 pm

[SOLVED] Enumerating Property Types and Object Types before opening a Document?

Postby Bayesian » Tue Nov 12, 2019 8:42 am

Because I want to simplify my scripts and enable Autocompletion etc, I'd like to have an import module with all supported property and object types.

I know I can get the property Types from, for example a Body object with "body.supportedProperties()" and the supported object types from "document.supportedObjects()".

But that means I would have to create a document and/or an Object to enumerate those. Which works, but isn't exactly elegant.

Is there some kind of registry available?
Last edited by Bayesian on Tue Nov 12, 2019 9:38 am, edited 1 time in total.
User avatar
DeepSOIC
Posts: 7145
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Enumerating Property Types and Object Types before opening a Document?

Postby DeepSOIC » Tue Nov 12, 2019 9:30 am

This information is not exposed. Exposing it might need quite some work.
Listing all attributes is easy. Listing all properties is more difficult. Listing supported objects for a body is doable, but in general it might be not.
Bayesian
Posts: 57
Joined: Thu Aug 08, 2019 1:49 pm

Re: [SOLVED] Enumerating Property Types and Object Types before opening a Document?

Postby Bayesian » Tue Nov 12, 2019 9:40 am

Hm. So there are basically two options: prepare a list offline (which doesn't account for new or nonstandard workbenches) or use the create a document and an object method.
wmayer
Site Admin
Posts: 14988
Joined: Thu Feb 19, 2009 10:32 am

Re: [SOLVED] Enumerating Property Types and Object Types before opening a Document?

Postby wmayer » Tue Nov 12, 2019 1:49 pm

Is there some kind of registry available?
Yes, the central registry is the C++ class Type. At the moment we don't offer a way to access it from Python but it shouldn't be too difficult to implement a way.
wmayer
Site Admin
Posts: 14988
Joined: Thu Feb 19, 2009 10:32 am

Re: [SOLVED] Enumerating Property Types and Object Types before opening a Document?

Postby wmayer » Tue Nov 12, 2019 11:58 pm

git commit e1f85cd09
git commit d61bf15c4

Code: Select all

t=App.Base.TypeId
t.getNumTypes()

p=t.fromName("App::DocumentObject")
p.Key
print(p)

p1=t.fromKey(97)
p1.Name

p.Name
p.isDerivedFrom("Base::BaseClass")
p.Module

pp=p.getParent()
pp.Name
pp.isBad()

b=t.getBadType()
b.Name
I know I can get the property Types from, for example a Body object with "body.supportedProperties()" and the supported object types from "document.supportedObjects()".
This can be done now with:

Code: Select all

App.Base.TypeId.getAllDerivedFrom("App::Property")
App.Base.TypeId.getAllDerivedFrom("App::DocumentObject")
Bayesian
Posts: 57
Joined: Thu Aug 08, 2019 1:49 pm

Re: [SOLVED] Enumerating Property Types and Object Types before opening a Document?

Postby Bayesian » Wed Nov 13, 2019 8:25 am

Thank you, I'm sure this will be useful!
User avatar
DeepSOIC
Posts: 7145
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: [SOLVED] Enumerating Property Types and Object Types before opening a Document?

Postby DeepSOIC » Wed Nov 13, 2019 9:29 am

wmayer wrote:
Tue Nov 12, 2019 11:58 pm

Code: Select all

t=App.Base.TypeId
t.getNumTypes()

p=t.fromName("App::DocumentObject")
p.Key
print(p)
Awesome!