I'm trying to add layers to a drawing in a library script. Ive tried a thousand versions of code but with no success.
Put simply - no layers are created whatever I do.
My latest attempt is to do this: in the 'create' method
var layer = new RLayer(documentInterface.getDocument(), "My New Layer");
addOperation.addObject(layer);
addOperation.apply(documentInterface.getDocument());'
No errors are generated - but no layer is created
Any suggestions welcome
thanks
Scripting and layers
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Re: Scripting and layers
A script library item cannot be used to create empty layers in a document.
Here's what happens:
- The script library item is rendering itself into a temporary (off-screen) document, very similar to the clipboard. This temporary document will contain the layers that are being created in the create method.
- When the script library item is inserted into the current document, the entities that were generated are copied one by one into the document.
- Whenever an entity is copied into the document, the layer that entity is on is also copied. Since empty layers have no entities on them, they are never copied into the document. In other words: layers are only copied 'on demand', that is when they are actually being used by an entity.
Here's what happens:
- The script library item is rendering itself into a temporary (off-screen) document, very similar to the clipboard. This temporary document will contain the layers that are being created in the create method.
- When the script library item is inserted into the current document, the entities that were generated are copied one by one into the document.
- Whenever an entity is copied into the document, the layer that entity is on is also copied. Since empty layers have no entities on them, they are never copied into the document. In other words: layers are only copied 'on demand', that is when they are actually being used by an entity.
-
- Newbie Member
- Posts: 4
- Joined: Tue Mar 15, 2016 8:01 pm
Re: Scripting and layers
Thanks Andrew - I will do some more experiments based on that.
Is that information contained anywhere in the documentation, Ive searched long and hard for some 'architecture' information. But no joy so far
Is that information contained anywhere in the documentation, Ive searched long and hard for some 'architecture' information. But no joy so far