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

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Bayesian
Posts: 90
Joined: Thu Aug 08, 2019 1:49 pm

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

Post by Bayesian »

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
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

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

Post by DeepSOIC »

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: 90
Joined: Thu Aug 08, 2019 1:49 pm

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

Post by Bayesian »

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
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

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
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

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

Post by wmayer »

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: 90
Joined: Thu Aug 08, 2019 1:49 pm

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

Post by Bayesian »

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

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

Post by DeepSOIC »

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!
Post Reply