EasyAlias macro
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: EasyAlias macro
Great idea. I had not thought to also allow for rows. I believe there have been some recent improvements to the spreadsheet interface available from python, making it easier to find the selected cells. Once 0.20 becomes the new stable I will likely look into revising the macro.
- xsuper9988
- Posts: 223
- Joined: Sat Oct 24, 2020 4:20 am
Re: EasyAlias macro
Thanks again for the Macro you originally sharedTheMarkster wrote: ↑Fri Jan 21, 2022 5:13 pm Great idea. I had not thought to also allow for rows. I believe there have been some recent improvements to the spreadsheet interface available from python, making it easier to find the selected cells. Once 0.20 becomes the new stable I will likely look into revising the macro.
This is a very useful Macro
Re: EasyAlias macro
Firstly,
thanks for this macro it's a massive time saver.
I've made a modification to the setAlias() function to work with my way of defining aliases.
The modification allows just the text in parentheses as the alias.
If no parentheses are found then the entire cell text is used.
Cheers
Ouriço
thanks for this macro it's a massive time saver.
I've made a modification to the setAlias() function to work with my way of defining aliases.
The modification allows just the text in parentheses as the alias.
If no parentheses are found then the entire cell text is used.
Code: Select all
def setAlias(sheet, cellIndex, alias):
address = cellIndexToAddress(cellIndex)
# extract any text between () and use that as the alias.
# If brackets not found then use the original alias.
firstidx = alias.find('(')
secondidx = alias.find(')')
if (firstidx != -1) and (secondidx != -1) and (firstidx < secondidx):
alias = alias[firstidx + 1 : secondidx]
sheet.setAlias(address, alias)
Ouriço
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: EasyAlias macro
Thanks. I have included your code in the macro. Latest version: 2022.03.21ourico wrote: ↑Mon Mar 21, 2022 11:33 pm Firstly,
thanks for this macro it's a massive time saver.
I've made a modification to the setAlias() function to work with my way of defining aliases.
The modification allows just the text in parentheses as the alias.
If no parentheses are found then the entire cell text is used.
Screenshot from 2022-03-21 23-17-00.pngCheersCode: Select all
def setAlias(sheet, cellIndex, alias): address = cellIndexToAddress(cellIndex) # extract any text between () and use that as the alias. # If brackets not found then use the original alias. firstidx = alias.find('(') secondidx = alias.find(')') if (firstidx != -1) and (secondidx != -1) and (firstidx < secondidx): alias = alias[firstidx + 1 : secondidx] sheet.setAlias(address, alias)
Ouriço
Re: EasyAlias macro
Hi All,
As a new user, I found the EasyAlias macro for spreadsheets. It irked me a bit that I couldn't select a full column of names formatted into separate groups (i.e., with blank cells between some rows), but had to manually select each group of rows.
I have "enhanced" the EasyAlias macro to allow this kind of operation, simply ignoring any blank cells in the "name to be alias" column.
This required two lines of code in the main body of the macro, so I won't post the entire file again.
Hope this makes someones life easier!
As a new user, I found the EasyAlias macro for spreadsheets. It irked me a bit that I couldn't select a full column of names formatted into separate groups (i.e., with blank cells between some rows), but had to manually select each group of rows.
I have "enhanced" the EasyAlias macro to allow this kind of operation, simply ignoring any blank cells in the "name to be alias" column.
This required two lines of code in the main body of the macro, so I won't post the entire file again.
Code: Select all
s = getSpreadsheet()
if not s:
raise Exception('No spreadsheet selected. Please select a spreadsheet in the tree view.')
cellIndices = getSelectedCellIndices(s)
if len(cellIndices) == 0:
FreeCAD.Console.PrintWarning("Unable to get selected cell indices.\n");
s.Document.openTransaction("EasyAlias")
for ci in cellIndices:
#FreeCAD.Console.PrintMessage("setting alias: "+s.Name+'['+str(cellIndexToAddress(getCellIndexNextColumn(ci)))+"] ---> "+getCellContent(s,ci).replace(' ','_')+"\n")
# new code
addr = cellIndexToAddress(ci)
if (len(s.getContents(addr)) > 0):
# end new code, the try except block is now indented an extra level
try:
setAlias(s, getCellIndexNextColumn(ci), str(getCellContent(s,ci).replace(' ','_').replace('.','_'))) #use e.g. content of A5 as alias for B5
except:
FreeCAD.Console.PrintError("Error. Unable to set alias: "+getCellContent(s,ci).replace(' ','_')+" for spreadsheet: "+str(s)+" cell "+cellIndexToAddress(getCellIndexNextColumn(ci))+"\n")
FreeCAD.Console.PrintError("Remember, aliases cannot begin with a numeral or an underscore or contain any invalid characters.\n")
s.Document.commitTransaction()
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: EasyAlias macro
I have updated the macro to version 2022.07.31 to include code from red6rick. Thanks for the fix. I had not realized there even was an issue with skipped rows.
@chennes Not a big deal, but one thing I noticed in testing is when the aliases are added I don't instantly get the yellow highlights for the cells that now contain aliases as I did in 0.19. The first time I tried the new code I thought the aliases were not being set because the background cell color did not change instantly. This color change gives a nice feedback to the user that the action was successful. The cell must be refreshed in some way, which can include clicking on the python console or presumably clicking on some other document object or window. It also refreshes when clicking on one of the cells containing the new alias, but this doesn't update all the new cells. I'm not sure about 0.20, tested with the following:
@chennes Not a big deal, but one thing I noticed in testing is when the aliases are added I don't instantly get the yellow highlights for the cells that now contain aliases as I did in 0.19. The first time I tried the new code I thought the aliases were not being set because the background cell color did not change instantly. This color change gives a nice feedback to the user that the action was successful. The cell must be refreshed in some way, which can include clicking on the python console or presumably clicking on some other document object or window. It also refreshes when clicking on one of the cells containing the new alias, but this doesn't update all the new cells. I'm not sure about 0.20, tested with the following:
Code: Select all
OS: Windows 10 (10.0)
Word size of FreeCAD: 64-bit
Version: 0.21.29485 (Git)
Build type: Release
Branch: master
Hash: a236ca843fdd6674afb6d7ed1454fbd3b547f5ea
Python 3.8.13, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: English/United States (en_US)
Installed mods:
* A2plus 0.4.56a (Disabled)
* Assembly4 0.12.3
* BOLTSFC
* CurvedShapes 1.0.4
* Curves 0.3.0
* DynamicData 2.46.0
* fasteners
* FCGear
* frame 0.1.0
* FreeCAD_mcm_addon
* gears
* hfcInventorMentorA
* InvGears
* lattice2
* Manipulator
* MeshRemodel 1.8919.0
* POV-Ray-Rendering
* sheetmetal 0.2.54
* ThreadProfile 1.81.0
Re: EasyAlias macro
Hi all
First time FreeCAD user, forum writer, code contributor here, so please forgive me if I am doing something completely stupid here.
I created a GitHub repository for this macro here:
https://github.com/ronnystandtke/EasyAlias
... and made some improvements to it, namely I:
Cheers
Ronny
First time FreeCAD user, forum writer, code contributor here, so please forgive me if I am doing something completely stupid here.
I created a GitHub repository for this macro here:
https://github.com/ronnystandtke/EasyAlias
... and made some improvements to it, namely I:
- added support for selecting several spreadsheets
- added support for multiple columns, even arbitrary cell selections
- added support for columns beyond "Z"
- added support for German umlauts
- use a GUI dialog for error messages
Cheers
Ronny
-
- Posts: 79
- Joined: Tue Jan 21, 2020 1:11 pm
Re: EasyAlias macro
HI.
Thanks for Macro, its awsome.
I'm a simple user of the CAD, I do just for personal use.
I find that I need to have at least two spreadsheets open.
One I call 'paras' and another I call 'res1', and then add more 'res' spreadsheets as I require.
This allows me to store references created from the original paras without creating a looping error.
When I use this macro, it tells me to close all other spreadsheets and doesn't do anything.
Is there a way around this?
Thanks for Macro, its awsome.
I'm a simple user of the CAD, I do just for personal use.
I find that I need to have at least two spreadsheets open.
One I call 'paras' and another I call 'res1', and then add more 'res' spreadsheets as I require.
This allows me to store references created from the original paras without creating a looping error.
When I use this macro, it tells me to close all other spreadsheets and doesn't do anything.
Is there a way around this?
- xsuper9988
- Posts: 223
- Joined: Sat Oct 24, 2020 4:20 am
Re: EasyAlias macro
Opening two spreadsheets and using macro will cause errorsNaxia wrote: ↑Wed Oct 05, 2022 8:23 am HI.
Thanks for Macro, its awsome.
I'm a simple user of the CAD, I do just for personal use.
I find that I need to have at least two spreadsheets open.
One I call 'paras' and another I call 'res1', and then add more 'res' spreadsheets as I require.
This allows me to store references created from the original paras without creating a looping error.
When I use this macro, it tells me to close all other spreadsheets and doesn't do anything.
Is there a way around this?
But why do you have to open two spreadsheets?
Maybe you provide a simple example
This will make it easier for everyone to understand or discuss other solutions