Show/Hide layers with script

Use this forum to ask questions about how to do things in QCAD.

Moderator: andrew

Forum rules
Always indicate Operating system, QCAD version
Attach Drawing files, Screenshots
Post one question per topic.
Post Reply
User avatar
dfriasb
Full Member
Posts: 72
Joined: Thu Mar 10, 2016 1:08 pm
Location: Calafell, Tarragona, Spain

Show/Hide layers with script

Post by dfriasb » Wed Nov 29, 2017 11:23 pm

Hello all,

I'm using

Code: Select all

layer.setFrozen(true)
and

Code: Select all

layer.setFrozen(false)
in two scripts to hide/show some layers with certain names. You can download the attached .js files with the scripts and one test drawing to verify try them if you want. The two commands should have the commitment of hiding or showing all layers whose names are starting with "0" and having one or two additional characters after (so maximum 3 characters layer names). You can try them by command line typing "ch0off" or "ch0on".

The thing is, right now, this two scripts are only partially working. If I hide "manually" one of these layers clicking on the visibility switcher (eye icon) on the Layer List, then the command "ch0on" is not working. The same thing happens if I isolate another current layer with Y,O; after that "ch0on" doesn't work.

About "ch0off", seems it's working as expected in any case.

I guess I'm misunderstanding the behaviour of

Code: Select all

layer.setFrozen(false)
. So, which is the variable I should use?

I also would like to create another script to isolate all layers starting with "0" as well.

Thanks for your support. Best regards,

David
Attachments
modelLayers.dxf
sample drawing to test these commands
(1020.77 KiB) Downloaded 17 times
ch0off_ch0on.zip
scripts for the two commands
(3.29 KiB) Downloaded 21 times
David Frías Barranco | architect
dfriasb@gmail.com | davidfriasarquitecto.es

User avatar
andrew
Site Admin
Posts: 5438
Joined: Fri Mar 30, 2007 6:07 am

Re: Show/Hide layers with script

Post by andrew » Thu Nov 30, 2017 11:10 am

There are two states that influence a layer's visibility: frozen and off.

My suspicion is that you might be switching a layer off in the layer list and freezing it in the script.

First, you might want to show both states in the layer list as follows:
Edit > Application Preferences > Widgets > Layer List > Show frozen column

Notes:
If a layer is frozen, block references on that layer are not shown.
If a layer is off, block references are still shown.
Layer "0" might behave differently depending on preferences in Edit > Application Preferences > Layer > Compatibility.

Post Reply

Return to “QCAD 'How Do I' Questions”