Extend Draft.make### functions by a name argument?

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
tobycz
Posts: 28
Joined: Tue Jul 26, 2016 2:35 am

Extend Draft.make### functions by a name argument?

Post by tobycz »

Hi,

I'm using the Draft workbench quite a bit from Python, basically many of the make### functions.
However, these functions don't allow to specify a name for the objects, e.g., Draft.makeText creates objects with the names

Code: Select all

Text

Code: Select all

Text001
and so on.

I would suggest to extend these functions with a name argument.
Something similar has been done already in this thread for makeWire
https://forum.freecadweb.org/viewtopic. ... t+in+draft

I'm happy to help with this.
I'm just not sure what would be good (coordinated) approach.

Tobi
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: Extend Draft.make### functions by a name argument?

Post by TheMarkster »

Presuming you wish to make changes to Draft.py and submit a Pull Request, I suggest it should be a keyword (named) argument, Name="default" where "default" is the name already given by default, e.g. "Text" or "Wire". This way existing code still works as before and does not break existing code, but those who wish to take advantage of the new argument would be able to.

For example:

stringList = ["some","list","of","strings"]
myText = Draft.makeText(stringList)

would still work the same as before, but now also I could use:

stringList = ["some","list","of","strings"]
myText = Draft.makeText(stringList, Name="MyName")
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Extend Draft.make### functions by a name argument?

Post by vocx »

TheMarkster wrote: Tue Aug 06, 2019 2:09 am Presuming you wish to make changes to Draft.py and submit a Pull Request, I suggest it should be a keyword (named) argument, Name="default" where "default" is the name already given by default, e.g. "Text" or "Wire". ...
This is already possible with a few commands, the problem is that it's not a consistent behavior.

Code: Select all

def makeArray(baseobject,arg1,arg2,arg3,arg4=None,arg5=None,arg6=None,name="Array"):
    ...
    obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
Basically, the addObject() method is responsible for assigning the name. However, the actual name of the object doesn't matter too much; what the user would like to modify is the "label" which is modifiable, unlike the "name" which is fixed.

Something like this.

Code: Select all

def makeArray(baseobject,arg1,arg2,arg3,arg4=None,arg5=None,arg6=None,name="Array"):
    ...
    obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Array")  # Fixed name
    obj.Label = name  # variable label
The Arch Workbench is more flexible in this regard, but the Draft functions were written a long time ago, so they haven't been designed with everything that the Arch functions have.
tobycz wrote: Mon Aug 05, 2019 11:41 pm I'm happy to help with this.
I'm just not sure what would be good (coordinated) approach.
This should be discussed in the Development forum, where Draft, Arch, and BIM are discussed.
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.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Extend Draft.make### functions by a name argument?

Post by Kunda1 »

Moved to Draft, Arch & BIM per request
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
yorik
Founder
Posts: 13660
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Extend Draft.make### functions by a name argument?

Post by yorik »

I would argument it's interesting to keep the object name something default (text, dimension, etc...) and only change its label. That way you have a redundant way to know what type an object is, even in a file made by someone else in another language...

It was possible early on actually, then we changed because the object name can only contain ascii characters, and this gave a lot of problems with translations, for some languages the object name would end up like _xeac_____001

In what kind of scenario would you like to have the object named as something else?
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Extend Draft.make### functions by a name argument?

Post by vocx »

yorik wrote: Sat Aug 10, 2019 12:53 am ...
In what kind of scenario would you like to have the object named as something else?
I just think most new users don't realize the difference between "Name" and "Label". This distinction probably needs to be better explained in the documentation. I think most users would be satisfied with modifying the "Label", not necessarily the "Name".

Maybe at some point the "Name" should be renamed to something else, like "IType" (ID type), or something cryptic, so the user doesn't try to modify it. Then "Label" can be renamed to "Name". I think most users expect to be able to modify the "Name" property, and they miss on the "Label" property.
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.
Post Reply