Draft and Arch objects TypeId

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Draft and Arch objects TypeId

Post by carlopav »

Hello, maybe it is a stupid question. Why Draft and Arch objects have not a TypeId property? something like Part::Box or Sketcher::Sketch ... so Draft::Line or Draft::Circle ?
follow my experiments on BIM modelling for architecture design
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Draft and Arch objects TypeId

Post by DeepSOIC »

They do, sorta. Use Draft.getType. The standard TypeId doesn't help much because it is a C++ thing only.
https://forum.freecadweb.org/viewtopic. ... 18#p135051
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Draft and Arch objects TypeId

Post by vocx »

carlopav wrote: Sun Aug 25, 2019 9:00 pm Hello, maybe it is a stupid question. Why Draft and Arch objects have not a TypeId property? something like Part::Box or Sketcher::Sketch ... so Draft::Line or Draft::Circle ?
Most Draft objects are created from a Part::Part2DObject, which is "a specialized version of the PartShape for use with flat (2D) geometry", according to src/Mod/Part/App/Part2DObject.h.

Code: Select all

def makeCircle(radius, placement=None, face=None, startangle=None, endangle=None, support=None):
    ...
    obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython",n)
    _Circle(obj)

Code: Select all

obj = Draft.makeCircle(100)
>>> obj.TypeId
'Part::Part2DObjectPython'
The constructor class _Wire, or _Circle, or whatever, is normally derived from _DraftObject, which defines a Proxy attribute, which holds a reference to the class that was used to create the object.

Code: Select all

>>> obj.Proxy
<Draft._Circle object at 0x7fd4eb98fdd8>
The class has a Type attribute that you can investigate and set.

Code: Select all

>>> obj.Proxy.Type
'Circle'

obj.Proxy.Type = "Banana"
>>> obj.Proxy.Type
'Banana'
So, basically, what Draft.getType() does, is to check the obj.Proxy.Type (for Python objects), or the obj.TypeId (for C++ objects).

In the case of Arch, objects are derived from Part::Feature, and the constructor, for example, _ArchPipe, similarly sets the Type to something like "Pipe".
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.
carlopav
Veteran
Posts: 2062
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: Draft and Arch objects TypeId

Post by carlopav »

Thanks, really clear now.
follow my experiments on BIM modelling for architecture design
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Draft and Arch objects TypeId

Post by yorik »

The TypeId is important so you know the base C++ class of your object. The python objects such as Drafts, Archs, etc... are actually live python objects that live inside the C++ object's Proxy property. So it makes sense that the TypeId always refers to the "carrier" C++ object.

The idea of having a Type attribute inside the Proxy object was a dirty hack at first, but it has been more and more used all over FreeCAD (in FEM, Path, etc..) so it has now more or less become a norm now... Be careful of the dirty hacks you do, they might become the norm one day :D
Post Reply