Scripting and layers

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
ianbottomley
Newbie Member
Posts: 4
Joined: Tue Mar 15, 2016 8:01 pm

Scripting and layers

Post by ianbottomley » Sat Apr 23, 2016 4:40 pm

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

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

Re: Scripting and layers

Post by andrew » Sun Apr 24, 2016 7:53 pm

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.

ianbottomley
Newbie Member
Posts: 4
Joined: Tue Mar 15, 2016 8:01 pm

Re: Scripting and layers

Post by ianbottomley » Mon Apr 25, 2016 5:41 pm

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

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”