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.
Feature request: Alias as optional name in sketch.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
Feature request: Alias as optional name in sketch.
I have uploaded many FreeCAD video tutorials to my YouTube channel
Re: Feature request: Alias as optional name in sketch.
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.
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: Feature request: Alias as optional name in sketch.
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.
Re: Feature request: Alias as optional name in sketch.
Cool TheMarkster!TheMarkster wrote: ↑Mon Aug 27, 2018 6:34 pmjruiz 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.
Just for completeness you have to ( ) 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
Re: Feature request: Alias as optional name in sketch.
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
Of course that's an opinion.
I have uploaded many FreeCAD video tutorials to my YouTube channel
Re: Feature request: Alias as optional name in sketch.
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.
-
- Veteran
- Posts: 5505
- Joined: Thu Apr 05, 2018 1:53 am
Re: Feature request: Alias as optional name in sketch.
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
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
Re: Feature request: Alias as optional name in sketch.
Cool!TheMarkster wrote: ↑Tue Aug 28, 2018 1:35 amThis 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).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
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
Just test it. Work fine.
Thanks a lot
I have uploaded many FreeCAD video tutorials to my YouTube channel