Feature request: Alias as optional name in sketch.

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
jruiz
Posts: 479
Joined: Tue Oct 28, 2014 1:07 pm
Contact:

Feature request: Alias as optional name in sketch.

Post by jruiz »

Hi.
I think that when one is constructing a sketch, it could be very useful that at the time of
imposing any constrain by clicking the little expression icon and getting the value from a spreadsheet cell (by spreadsheetName.aliasOfTheCell), the optional name of the constrain be by default the same as the alias of the selected cell.

P.S.: It could be very useful that the alias names could include the space character.

Regards.
I have uploaded many FreeCAD video tutorials to my YouTube channel
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Feature request: Alias as optional name in sketch.

Post by chrisb »

jruiz wrote: Mon Aug 27, 2018 11:21 am it could be very useful that at the time of
imposing any constrain by clicking the little expression icon and getting the value from a spreadsheet cell

P.S.: It could be very useful that the alias names could include the space character.
automated alias creation: yes. Spaces in expressions or alias names: please don't. These are technical names which don't have to be read like a novel.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Feature request: Alias as optional name in sketch.

Post by TheMarkster »

jruiz wrote: Mon Aug 27, 2018 11:21 am Hi.
I think that when one is constructing a sketch, it could be very useful that at the time of
imposing any constrain by clicking the little expression icon and getting the value from a spreadsheet cell (by spreadsheetName.aliasOfTheCell), the optional name of the constrain be by default the same as the alias of the selected cell.

P.S.: It could be very useful that the alias names could include the space character.

Regards.

I wrote a macro that does just the opposite of what you describe. It takes the named constraint and makes the alias from it.

https://forum.freecadweb.org/viewtopic. ... et#p242546

You can use underscores (_) instead of spaces if you need a really_long_alias_name.
User avatar
jruiz
Posts: 479
Joined: Tue Oct 28, 2014 1:07 pm
Contact:

Re: Feature request: Alias as optional name in sketch.

Post by jruiz »

TheMarkster wrote: Mon Aug 27, 2018 6:34 pm
jruiz wrote: Mon Aug 27, 2018 11:21 am Hi.
I think that when one is constructing a sketch, it could be very useful that at the time of
imposing any constrain by clicking the little expression icon and getting the value from a spreadsheet cell (by spreadsheetName.aliasOfTheCell), the optional name of the constrain be by default the same as the alias of the selected cell.

P.S.: It could be very useful that the alias names could include the space character.

Regards.

I wrote a macro that does just the opposite of what you describe. It takes the named constraint and makes the alias from it.

https://forum.freecadweb.org/viewtopic. ... et#p242546

You can use underscores (_) instead of spaces if you need a really_long_alias_name.
Cool TheMarkster!
Just for completeness you have to ( :D ) add my requested feature to your macro (or to a new one). They complement each other.
Regards
Last edited by jruiz on Mon Aug 27, 2018 11:21 pm, edited 1 time in total.
I have uploaded many FreeCAD video tutorials to my YouTube channel
User avatar
jruiz
Posts: 479
Joined: Tue Oct 28, 2014 1:07 pm
Contact:

Re: Feature request: Alias as optional name in sketch.

Post by jruiz »

chrisb wrote: Mon Aug 27, 2018 3:51 pm
jruiz wrote: Mon Aug 27, 2018 11:21 am it could be very useful that at the time of
imposing any constrain by clicking the little expression icon and getting the value from a spreadsheet cell

P.S.: It could be very useful that the alias names could include the space character.
automated alias creation: yes. Spaces in expressions or alias names: please don't. These are technical names which don't have to be read like a novel.
Well, alias names are not exactly expressions. I think they are supposed be easily human readable, not like a novel but as a novel title :D
Of course that's an opinion.
I have uploaded many FreeCAD video tutorials to my YouTube channel
chrisb
Veteran
Posts: 53919
Joined: Tue Mar 17, 2015 9:14 am

Re: Feature request: Alias as optional name in sketch.

Post by chrisb »

jruiz wrote: Mon Aug 27, 2018 10:53 pm I think they are supposed be easily human readable, not like a novel but as a novel title :D
Of course that's an opinion.
So was my post. As I will probably not be forced to use spaces in aliases, I can live with it very well. The entries of a spreadsheet used as labels should of course allow spaces.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Feature request: Alias as optional name in sketch.

Post by TheMarkster »

jruiz wrote: Mon Aug 27, 2018 10:44 pm
Cool TheMarkster!
Just for completeness you have to ( :D ) add my requested feature to your macro (or to a new one). They complement each other.
Regards

Code: Select all

import FreeCAD

selObj = Gui.Selection.getSelectionEx()
for obj in selObj:
    if not 'Sketcher.SketchObject' in str(type(obj.Object)):
        continue
    expr = obj.Object.ExpressionEngine
   # FreeCAD.Console.PrintMessage(str(expr)+'\n')
    newNames=[]
    for ex in expr:
       if not '[' in ex[0]:
           continue
      # FreeCAD.Console.PrintMessage(str(ex[0])+'\n')
       idx=int(ex[0].split('[')[1][:-1]) #'Constraints[9]' becomes 9
       #newNames.append((idx,ex[1].split('.')[1])) #split off, e.g. Spreadsheet.radius = radius
       newNames.append((idx,ex[1].replace('.','_'))) #convert . to underscore, e.g. Spreadsheet.radius = Spreadsheet_radius
    cons = obj.Object.Constraints
    for name in newNames:
        cons[name[0]].Name = name[1]
    obj.Object.Constraints = cons
This is mostly untested, goes without saying. See the 2 lines beginning with #newNames.append and newNames.append? The # is a comment, meaning that line doesn't get executed. You can swap the # around from one line to the other to change the behavior of the macro, depending on whether you want Spreadsheet.radius to become radius or to become Spreadsheet_radius (current behavior). This macro also works if you use an object property instead of a Spreadsheet cell, for example, put a Cube in the document and set a constraint to Cube.Height, and the name of that constraint will be Cube_Height (or Height in the other mode).

Only selected sketches are acted upon, so you need to select the sketch(es) first, then run the macro. Any constraint that already has a name will be ignored.

On the subject of spreadsheet aliases, see this macro, too:

https://forum.freecadweb.org/viewtopic. ... as#p251340
User avatar
jruiz
Posts: 479
Joined: Tue Oct 28, 2014 1:07 pm
Contact:

Re: Feature request: Alias as optional name in sketch.

Post by jruiz »

TheMarkster wrote: Tue Aug 28, 2018 1:35 am
jruiz wrote: Mon Aug 27, 2018 10:44 pm
Cool TheMarkster!
Just for completeness you have to ( :D ) add my requested feature to your macro (or to a new one). They complement each other.
Regards

Code: Select all

import FreeCAD

selObj = Gui.Selection.getSelectionEx()
for obj in selObj:
    if not 'Sketcher.SketchObject' in str(type(obj.Object)):
        continue
    expr = obj.Object.ExpressionEngine
   # FreeCAD.Console.PrintMessage(str(expr)+'\n')
    newNames=[]
    for ex in expr:
       if not '[' in ex[0]:
           continue
      # FreeCAD.Console.PrintMessage(str(ex[0])+'\n')
       idx=int(ex[0].split('[')[1][:-1]) #'Constraints[9]' becomes 9
       #newNames.append((idx,ex[1].split('.')[1])) #split off, e.g. Spreadsheet.radius = radius
       newNames.append((idx,ex[1].replace('.','_'))) #convert . to underscore, e.g. Spreadsheet.radius = Spreadsheet_radius
    cons = obj.Object.Constraints
    for name in newNames:
        cons[name[0]].Name = name[1]
    obj.Object.Constraints = cons
This is mostly untested, goes without saying. See the 2 lines beginning with #newNames.append and newNames.append? The # is a comment, meaning that line doesn't get executed. You can swap the # around from one line to the other to change the behavior of the macro, depending on whether you want Spreadsheet.radius to become radius or to become Spreadsheet_radius (current behavior). This macro also works if you use an object property instead of a Spreadsheet cell, for example, put a Cube in the document and set a constraint to Cube.Height, and the name of that constraint will be Cube_Height (or Height in the other mode).

Only selected sketches are acted upon, so you need to select the sketch(es) first, then run the macro. Any constraint that already has a name will be ignored.

On the subject of spreadsheet aliases, see this macro, too:

https://forum.freecadweb.org/viewtopic. ... as#p251340
Cool!
Just test it. Work fine.
Thanks a lot
I have uploaded many FreeCAD video tutorials to my YouTube channel
Post Reply