type of element

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Karol Dembiński
Posts: 8
Joined: Thu Mar 19, 2020 7:02 pm

type of element

Post by Karol Dembiński »

Hi, I am trying to check if selected thing is a line.

>>> k.TypeId
'Part::Part2DObjectPython'

no Type method.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: type of element

Post by ickby »

You need some deeper understanding of the freecad datastructures used. I recommend Part_Module Part_scripting and Topological_data_scripting
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: type of element

Post by openBrain »

Also use getSelectionEx() function and test SubObjects.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: type of element

Post by vocx »

Karol Dembiński wrote: Tue Jun 02, 2020 12:07 pm Hi, I am trying to check if selected thing is a line.
What line? A Draft Line? A Draft Line is a Python object (scripted objects) that sits on top of a base C++ object, in this case, Part_Part2DObject. Therefore, its TypeId will be this C++ object.

The type of a Draft object is specified in the Type attribute of its Proxy.

Code: Select all

print(obj.Proxy.Type)
For convenience, Draft provides a function to get this quickly.

Code: Select all

Draft.getType(obj)
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.
Karol Dembiński
Posts: 8
Joined: Thu Mar 19, 2020 7:02 pm

Re: type of element

Post by Karol Dembiński »

vocx wrote: Tue Jun 02, 2020 2:56 pm
Karol Dembiński wrote: Tue Jun 02, 2020 12:07 pm Hi, I am trying to check if selected thing is a line.
What line? A Draft Line? A Draft Line is a Python object (scripted objects) that sits on top of a base C++ object, in this case, Part_Part2DObject. Therefore, its TypeId will be this C++ object.

The type of a Draft object is specified in the Type attribute of its Proxy.

Code: Select all

print(obj.Proxy.Type)
For convenience, Draft provides a function to get this quickly.

Code: Select all

Draft.getType(obj)
Well, yes, I mean Draft object named 'line' and I'm using it's start and end, so I wanted to mak sure it not only has start and and, but also make sure that, what is named "start' and 'end' are indeed what I mean.
Post Reply