ikua wrote: ↑Fri Feb 09, 2024 10:11 am
The rest is also a mistery how it works, but it works, but it seems, that the ".name()" converts the RColor to hex, and that can be used to set the color of the new layer. So it also works with custom colors, because it actually never refers to the color name.
Your approach without the name did not work for me, cause i could not use the RColor as input for the addLayer.
Remark that I did not mentioned any kind of an approach beside swapping
.toLowerCase() and
.toString() ...
... Fairly straightforward, one needs a string based object before one can convert it to lower case.
Ok, hex it is, I recently discovered that sometimes it is required to look over the hedge with Qt:
Mystery solved!
Another remark is to simply use
EAction.handleUserMessage("...");
https://github.com/qcad/qcad/blob/maste ... n.js#L1900
The hierarchic layer separator is in fact " ... " but the absence of the last space won't matter in this case.
You don't have to convert the result from
.getName() to a string because it always returns a QString ... At least an empty one:
https://qcad.org/doc/qcad/3.0/developer ... a0f00ba811
For now you only copy over the child name with the appropriate naming & color ...
... The simple API adds the defaults "Continuous" Linetype and weight 0.00mm
https://github.com/qcad/qcad/blob/maste ... ate.js#L59
You can already see the major difference in the number of
RLayer attributes vs 4 for
addLayer.
At some point you might want to consider to leave the simple API for what it is.
But the same remarks that Andrew made with your previous script are valid here ... :
- Query the child layer in question, clone it.
(For the moment this is a variable and not an actual layer object of the drawing)
- Alter the naming of the clone to match the new parent.
- Add the cloned layer object to the drawing as a new object.
This new child layer will be a perfect clone of the child in question, all attributes will be a mirror except the parent name.
- Group your actions to one operation and/or multiple operations to one transaction.
This spares you intermediate screen updates and other related things that all take time and one can undo the action in one go.
Finally ...
Your code assumes that
oldlayer_name exits and that adding a new parent
newlayer_name is always required.
It also assumes that
oldlayer_name is a main level parent name, but
.indexOf(...) != -1 only diversify on if it occurs, not on where.
Change that to
== 0 or use the
String.startsWith(...) function:
https://github.com/qcad/qcad/blob/maste ... y.js#L2166
Regards,
CVH