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: 3416
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).
Opted for the key sequence 'YJ' what doesn't seem to conflict.

Had some hiccups in coding it ... :wink:
For one, creating subfolders including the hierarchy separator ' ... ' acts weird.
And 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?

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

Scrolling the Layer List would be a nice addition 8) but that is beyond my capabilities :oops: .

The 5 files in the zipper can be installed in your QCAD installation path under ...\scripts\Misc\MiscLayer\ActivateLayerFromSelection\
Or in the local data location, see Changelog ... 3.26.2 (2021/04/15):
https://www.ribbonsoft.com/en/documentation/changelog
The folder construction is mandatory, the path to the main script itself should read:
...\scripts\Misc\MiscLayer\ActivateLayerFromSelection\ActivateLayerFromSelection.js

ActivateLayerFromSelection.zip
(7.85 KiB) Downloaded 278 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

User avatar
andrew
Site Admin
Posts: 9037
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: 473
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: 473
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: 9037
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: 473
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: 3416
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

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”