Hello all,
I just finished some commands to control layer visibility depending on the 2nd character of the layer name. I use to name layers with only two characters, the first one is for the building chapter (demolitions, structure, partitions, roofs, etc.) and the second one to define the kind of view and graphical relevance (section, projection, rear, hidden, light, aux. lines, measurements, user notes...).
It was easy for me to hide and show layers on the same building chapter, as they are alphabetically ordered, but not for the second one.
It is my first script really working, but of course I think it can be done much better!! Anyway I attach the files and screenshots of my QCAD window were you can see my layer list and the effect of one of these commands. Just to share!
Best regards,
David
Hide-Show layers by name
Moderators: andrew, Husky, J-J
- dfriasb
- Senior Member
- Posts: 119
- Joined: Thu Mar 10, 2016 1:08 pm
- Location: Calafell, Tarragona, Spain
Hide-Show layers by name
- Attachments
-
- ExDFa_layers_On_Off.zip
- These are command script files in js
- (65.57 KiB) Downloaded 867 times
-
- All the projection layers "_p" Off.png (268.29 KiB) Viewed 26455 times
-
- All layers On.png (269.86 KiB) Viewed 26455 times
Re: Hide-Show layers by name
Hi David,
curious like I'm I was going to play with your script a bit - but could you get me started with a explanation how to use those shortcuts on a Win System.
What is the first Letter in those commands?
curious like I'm I was going to play with your script a bit - but could you get me started with a explanation how to use those shortcuts on a Win System.
What is the first Letter in those commands?
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."
Re: Hide-Show layers by name
@Andrew
Could you please move this topic to "QCAD 3 ' Script Add-On & Plug-in challenge ' - Work in Progress".
Thanks.
Could you please move this topic to "QCAD 3 ' Script Add-On & Plug-in challenge ' - Work in Progress".
Thanks.
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."
- dfriasb
- Senior Member
- Posts: 119
- Joined: Thu Mar 10, 2016 1:08 pm
- Location: Calafell, Tarragona, Spain
Re: Hide-Show layers by name
Hello Husky,
I use an spanish keyboard. In order to don't interfere with existing shortcuts I decided to use "ñ" and "ç" for these new ones.
Actually I would like to improve the command with some dialog like:
Enter Character position in layer names -- 1,2,3,...
Enter Character -- a-z A-Z 0-9
Enter freeze status: Show/Hide
In this way only one command should be needed for the same task, and not so many like now (2 per letter). And also it could be used for any string lenght in layer names.
I use an spanish keyboard. In order to don't interfere with existing shortcuts I decided to use "ñ" and "ç" for these new ones.
Actually I would like to improve the command with some dialog like:
Enter Character position in layer names -- 1,2,3,...
Enter Character -- a-z A-Z 0-9
Enter freeze status: Show/Hide
In this way only one command should be needed for the same task, and not so many like now (2 per letter). And also it could be used for any string lenght in layer names.
Re: Hide-Show layers by name
Thanks for the info.dfriasb wrote:I use an spanish keyboard. In order to don't interfere with existing shortcuts I decided to use "ñ" and "ç" for these new ones.
Sounds good. Too bad that it doesn't work in English ......dfriasb wrote:Actually I would like to improve the command with some dialog like:
Enter Character position in layer names -- 1,2,3,...
Enter Character -- a-z A-Z 0-9
Enter freeze status: Show/Hide.
![Wink :wink:](./images/smilies/icon_wink.gif)
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."
Re: Hide-Show layers by name
Hi dfriasb,
I would create a command that when activated would display a combo box, check box and button in the options toolbar. The combo box would contain the digits 0-9, lowercase letters a-z, uppercase letters A-Z. The check box could be labelled 'Show' and the button would contain a 'tick' icon. The user would then choose the appropriate letter or digit in the combo box, and check or uncheck the 'Show' check box. and finally click the button to run the command.
When you loop through the layer names you use a built-in javascript function named 'endsWith()'. This checks if a string ends with a given string. So you would store the character selected in the combo box, and use that with 'endsWith'. Then if the 'Show' check box was checked you would turn the layer on. If the 'Show' check box was unchecked, you would turn the layer off. (You could actually label the check box 'Hide', in which case, if checked it would turn the layer off, and unchecked would turn the layer on. This would be a matter of personal preference.)
To get a full explanation of using strings in javascript, google 'javascript string'. This will bring up a list of links to websites giving a full description of how to use strings in javascript, and also other functions you could use.
To see how to use combo boxes in the toolbar, look at the 'ConvertUnit' command in the directory 'scripts/Edit/ConvertUnit'. This has two combo boxes in the options toolbar, and a button with a 'tick' icon. The description of the user interface is in the file 'ConvertUnit.ui'. This is a plain text file in xml format. Although you could change this using a text editor, this is not recommended. Instead you should use a program called 'QtDesigner' to open and edit the file. (QtDesigner is part of the Qt Libraries and is free. Again google 'QtDesigner').
This should be enough to get you started.
Having said all that however, I think you should take a look at the QCAD Pro add on. This adds a feature called 'hierarchical layers'. This allows you to have parent layers which can contain one or more sub-layers. So you could for example create a layer called 'a', and then add sub-layers to it (e.g. 0a,1a, aa, ba, Aa, Ba etc). Then, by clicking the eye icon on the parent layer, you can switch the parent layer, and all its sub-layers, on or off, with one click. So you could use more descriptive names for each layer. I think this may be a better solution, saving you both time and effort. QCAD Pro also adds lots of other features, including the ability to read and write DWG files, which could be useful if you share your files with other people.
Anyway I hope this has been useful
Regards
riverbuoy
You are correct. You have already put in some effort. With a little more I think you can do this.dfriasb wrote:In this way only one command should be needed for the same task, and not so many like now (2 per letter). And also it could be used for any string length in layer names.
I would create a command that when activated would display a combo box, check box and button in the options toolbar. The combo box would contain the digits 0-9, lowercase letters a-z, uppercase letters A-Z. The check box could be labelled 'Show' and the button would contain a 'tick' icon. The user would then choose the appropriate letter or digit in the combo box, and check or uncheck the 'Show' check box. and finally click the button to run the command.
When you loop through the layer names you use a built-in javascript function named 'endsWith()'. This checks if a string ends with a given string. So you would store the character selected in the combo box, and use that with 'endsWith'. Then if the 'Show' check box was checked you would turn the layer on. If the 'Show' check box was unchecked, you would turn the layer off. (You could actually label the check box 'Hide', in which case, if checked it would turn the layer off, and unchecked would turn the layer on. This would be a matter of personal preference.)
To get a full explanation of using strings in javascript, google 'javascript string'. This will bring up a list of links to websites giving a full description of how to use strings in javascript, and also other functions you could use.
To see how to use combo boxes in the toolbar, look at the 'ConvertUnit' command in the directory 'scripts/Edit/ConvertUnit'. This has two combo boxes in the options toolbar, and a button with a 'tick' icon. The description of the user interface is in the file 'ConvertUnit.ui'. This is a plain text file in xml format. Although you could change this using a text editor, this is not recommended. Instead you should use a program called 'QtDesigner' to open and edit the file. (QtDesigner is part of the Qt Libraries and is free. Again google 'QtDesigner').
This should be enough to get you started.
Having said all that however, I think you should take a look at the QCAD Pro add on. This adds a feature called 'hierarchical layers'. This allows you to have parent layers which can contain one or more sub-layers. So you could for example create a layer called 'a', and then add sub-layers to it (e.g. 0a,1a, aa, ba, Aa, Ba etc). Then, by clicking the eye icon on the parent layer, you can switch the parent layer, and all its sub-layers, on or off, with one click. So you could use more descriptive names for each layer. I think this may be a better solution, saving you both time and effort. QCAD Pro also adds lots of other features, including the ability to read and write DWG files, which could be useful if you share your files with other people.
Anyway I hope this has been useful
Regards
riverbuoy