Activate Layer From Selection

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
CVH
Premier Member
Posts: 4920
Joined: Wed Sep 27, 2017 4:17 pm

Activate Layer From Selection

Post by CVH » Wed Jul 20, 2022 7:12 am

Hi all,

I wrote this script regarding this post:
https://qcad.org/rsforum/viewtopic.php?t=9355

And it is already very helpful. :P

The tool will activate the layer that the entities in selection have in common.
Therefor it requires a selection upfront.
It will report an ambiguous selection disregarding the actual current layer being ambiguous with others in the selection.
It does not re-activate a current active layer but will report that the selection is on the current layer.
Setting a layer active is a two step process, it requires an extra action to fully undo.

With 'Y' there are not many options left for the shortcut (b, g, j, q, x).
### Update see lower ###
Opted for the key sequence 'YJ' what doesn't seem to conflict.
### Updated to 'YG' ### (Because of conflict in later QCAD versions)

Had some hiccups in coding it ... :wink:
For one, creating subfolders including the hierarchy separator ' ... ' acts weird.

For PRO users it will now also expand the layer tree so that the active layer is at least visible.
The reasons for that are:
- On reloading a drawing all main level parents are collapsed.
Sublayers only may retain their expanded/collapsed state.
- A drawing may open without the current active sublayer visible.
- Expanding/collapsing a level in the Layer List is also setting it active.

The tool should work for CE users just the same. Can anyone confirm that?
### Updated, now CE proof ### (Tested in v3.32.3 as CE)

Initially intended as a tool in the Layer menu but reverted back to the Misc .. Layer menu.
Details are in the init script and scripts are textual files.

Scrolling the Layer List would be a nice addition 8) but that is beyond my capabilities :oops: .
### Implemented ### (CE and Pro)

The 5 files in the zipper can be installed in your QCAD installation path under ...\scripts\Misc\MiscLayer\ActivateLayerFromSelection\
Where the 3 dots stand for your QCAD installation folder (CE, Pro, QCAD/CAM or appropiate)
Or in the local data location, see Changelog ... 3.26.2 (2021/04/15):
https://www.ribbonsoft.com/en/documentation/changelog
Please also refer to this answer by Andrew to detect your specific user data location.
  • Folders:
    ...\scripts\Misc\
    ...\scripts\Misc\MiscLayer\
    ...\scripts\Misc\MiscLayer\ActivateLayerFromSelection\
    May not exist in a standard installation, create them manually.
The folder construction is mandatory, the path to the main script itself should read:
...\scripts\Misc\MiscLayer\ActivateLayerFromSelection\ActivateLayerFromSelection.js

### UPDATED ###
The addon was downloaded 510 times before the revision.
ActivateLayerFromSelection.zip
2025 revision
(9.42 KiB) Downloaded 268 times

Andrew may include this in a future release of QCAD.
In such a case one would delete these installed files and additional the emptied folders.

Andrew may also decide to implement it as a Layer tool, details are in the initialization file.
In such a case one must remove those that are installed in the Misc menu to avoid conflicts.

Regards,
CVH
Last edited by CVH on Sun Jun 29, 2025 2:06 pm, edited 3 times in total.

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

Re: Activate Layer From Selection

Post by andrew » Wed Jul 27, 2022 9:04 am

Thanks.

I'd propose to implement this as part of the context menu instead:

- User right-clicks entity
- Context menu shows "Activate layer of entity"

Is there an advantage of the implementation based on the current selection?

John Hyslop
Premier Member
Posts: 520
Joined: Mon Sep 30, 2019 6:21 am
Location: Melbourne - Australia

Re: Activate Layer From Selection

Post by John Hyslop » Wed Jul 27, 2022 10:10 am

I'll 2nd that Andrew, I've been using this with hotkeys YJ..
And nice work CVH.. Very useful indeed..

Cheers
John
IF IT IS TO BE IT IS UP TO ME [ Ten most powerful 2 letter words ]

John Hyslop
Premier Member
Posts: 520
Joined: Mon Sep 30, 2019 6:21 am
Location: Melbourne - Australia

Re: Activate Layer From Selection

Post by John Hyslop » Wed Jul 27, 2022 10:30 am

. Is there an advantage of the implementation based on the current selection?
I think if a drawing had a few layers and using the same colour it would be beneficial selecting 1st..just my 2 cents worth 🤔

Cheers
John
PS Thinking more about this could you cover both options
Right click on selection and just right click change layer 🤔
IF IT IS TO BE IT IS UP TO ME [ Ten most powerful 2 letter words ]

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

Re: Activate Layer From Selection

Post by andrew » Wed Jul 27, 2022 10:45 am

The context menu option does not depend on the selection at all. The layer of the entity that is right-clicked is activated independent of the current selection.

John Hyslop
Premier Member
Posts: 520
Joined: Mon Sep 30, 2019 6:21 am
Location: Melbourne - Australia

Re: Activate Layer From Selection

Post by John Hyslop » Wed Jul 27, 2022 11:17 am

I see now what you mean :oops:
IF IT IS TO BE IT IS UP TO ME [ Ten most powerful 2 letter words ]

CVH
Premier Member
Posts: 4920
Joined: Wed Sep 27, 2017 4:17 pm

Re: Activate Layer From Selection

Post by CVH » Wed Jul 27, 2022 6:08 pm

andrew wrote:
Wed Jul 27, 2022 9:04 am
Is there an advantage of the implementation based on the current selection?
Andrew,
In my case several entities can be stacked on the same spot each the same or with just that tiny difference with other trials.
In general I do not delete many things, I set aside or isolate.

I used to Alt-Select, read the layer property and lookup the layer in question to activate it.
This can be complicated by being created in a foreign language.
When all sub levels are expanded it may even turn out that it was already active.
If I have to expand parent levels I also activate them, any original focus is lost.
All not really a problem until I decide to undo my last drawing action.

Now I do Alt-Select and YJ.
Bonus: It only adds 2 steps to undo.

Why the multi selection and disregarding the current.
I use it to continue drawing on the common 'other layer' than what is now the current.
The layer property will then show '*VARIES*' and one can not expand that field for more info or select any without actually moving them.
Depending on a proper selection I can now even toggle back and forth.

I also use the tool to display all the parent structure of the (sub-)layer that I left visible when I reload a drawing.

Regards,
CVH

CVH
Premier Member
Posts: 4920
Joined: Wed Sep 27, 2017 4:17 pm

Update: Activate Layer From Selection

Post by CVH » Sun Jun 29, 2025 1:23 pm

Hi all,

'Move selection to the current layer' (YJ) was introduced in QCAD Pro v3.28.2 (2023/09/04)
The keyboard shortcut was updated to YG to avoid collision with this Pro tool.

Starting with 'Y' there are not many options left: The number zero and keys 'B' or 'Q'. :o

The original contribution was most likely not QCAD CE proof.
That uses a different type of widget for the Layer List.

The revision is also functional in CE.

Scrolling the Layer List was beyond my capabilities in 2022.
Gave it a new attempt.

The revision now scrolls the Layer List so that the current active layer is displayed.
Halfway the list would be preferable but I settled for 'at least visible'. :wink:

I have updated my contribution in the first post of this topic.
Installation instructions for the Addon are included and revised.

Regards,
CVH


PS 1:
QCAD Pro users may opt out on enabling hierarchical layers what has NO effect on how the Layer List is displayed.
Has effect on PurgeLayers, EditLayer(or -Pro), SelectLayer(or -Pro), DeselectLayer(or -Pro), AddLayer(or -Pro).
But for example adding 'Layer 1' and 'Layer1 ... Sub1' is displayed as hierarchical layers just the same.
Disabling was reported to crash QCAD/CAM (FS#2265) and was fixed.
When the LayerListPro.js script is present it removes the CE version initiated by the basic LayerList.js script.
But it adds for example AddSubLayer.js as an action to the Layer List Context Menu.
This dialog also displays hierarchical layers.
Also remark that opting in/out may be missing on a first/second attempt to configure the Layer List. (Topic 11625)

PS 2:
'Activate layer of entity' in the Context Menu was introduced for QCAD Pro (Date not retrievable)
As stated above by Adrew this is unrelated to an existent selection.
ALT + L-click or an R-Click for the Context Menu if configured don't mix.
With stacked entities the closest under the cursor is arbitrary.
This action does not expand collapsed parents layers if any, nor does it scroll in the Layer List.
Expanding/collapsing any layer is also setting it currently active what counteracts activating the intended.
Remark that (re-)activating the current active layer via the Context Menu is also regarded as a document change.
While nothing really changed ...

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”