how to check in C++ for a Python-defined object

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

how to check in C++ for a Python-defined object

Post by uwestoehr »

I need to check if a selected object has a certain Type. How is this done for Python Objects?

Usually I can either use

Code: Select all

getSelection().getObjectsOfType<Type>
or I get from the SelectionSingleton the App:DocumentObject and then

Code: Select all

object->getTypeId().isDerivedFrom(Base::Type::fromName("Typename"))
My case is that Type/Typename is a Python-defined object. What would be its Typename?
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: how to check in C++ for a Python-defined object

Post by uwestoehr »

uwestoehr wrote: Wed Feb 01, 2023 4:52 am My case is that Type/Typename is a Python-defined object. What would be its Typename?
I tried now this:

Code: Select all

object->getTypeId().getName()
But this does not give me a unique string to check what type it actually is. In my case I need to check if it is a FEM Elmer solver object.
The result is always FEM::FEMSolverObjectPython, no matter if it is a Ccx, Z88 or Elmer solver object.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: how to check in C++ for a Python-defined object

Post by Roy_043 »

In Python you can check the class:

Code: Select all

obj.Proxy.__class__
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: how to check in C++ for a Python-defined object

Post by uwestoehr »

Roy_043 wrote: Wed Feb 01, 2023 8:49 am In Python you can check the class:

Code: Select all

obj.Proxy.__class__
Thanks. How can I call this from C++ to evaluate the result?
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: how to check in C++ for a Python-defined object

Post by Roy_043 »

I do not know C++. Searching the source code shows that DlgPropertyLink.cpp may provide the answer.
Post Reply