Hide-Show layers by name

This forum is for 'Work-in-Progress' QCAD user developed script Add Ons and Plug-ins.

Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: andrew, Husky, J-J

Post Reply
User avatar
dfriasb
Full Member
Posts: 72
Joined: Thu Mar 10, 2016 1:08 pm
Location: Calafell, Tarragona, Spain

Hide-Show layers by name

Post by dfriasb » Fri Jul 21, 2017 11:05 am

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
Attachments
ExDFa_layers_On_Off.zip
These are command script files in js
(65.57 KiB) Downloaded 119 times
All the projection layers "_p" Off.png
All the projection layers "_p" Off.png (268.29 KiB) Viewed 6645 times
All layers On.png
All layers On.png (269.86 KiB) Viewed 6645 times
David Frías Barranco | architect
dfriasb@gmail.com | davidfriasarquitecto.es

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 1991
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Hide-Show layers by name

Post by Husky » Fri Jul 21, 2017 7:28 pm

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?
Husky-2017.07.21-03.png
Husky-2017.07.21-03.png (4.57 KiB) Viewed 6636 times
Work smart, not hard: QCad Pro

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 1991
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Hide-Show layers by name

Post by Husky » Fri Jul 21, 2017 7:30 pm

@Andrew
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

User avatar
dfriasb
Full Member
Posts: 72
Joined: Thu Mar 10, 2016 1:08 pm
Location: Calafell, Tarragona, Spain

Re: Hide-Show layers by name

Post by dfriasb » Sat Jul 22, 2017 10:27 am

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.
David Frías Barranco | architect
dfriasb@gmail.com | davidfriasarquitecto.es

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 1991
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Hide-Show layers by name

Post by Husky » Sun Jul 23, 2017 4:13 am

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.
Thanks for the info.
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.
Sounds good. Too bad that it doesn't work in English ...... :wink:
Work smart, not hard: QCad Pro

riverbuoy
Senior Member
Posts: 103
Joined: Thu Oct 03, 2013 5:37 pm

Re: Hide-Show layers by name

Post by riverbuoy » Wed Jul 26, 2017 1:56 am

Hi dfriasb,
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.
You are correct. You have already put in some effort. With a little more I think you can do this.
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

Post Reply

Return to “QCAD 'Script Add-On & Plug-in challenge' - Work in Progress”