As a test for later development I have modified the Library Item Example script "MyRectangle.js" so instead of drawing line entities it draws a rectangular polyline. It draws the polyline fine but always into the default layer "0".
As a test I created a new layer called "A" and gave it a colour "Yellow".
In code on my script I set the current layer to "A" then added custom properties to the polyline and also set the PropertyLayer to "A", however it always draws it into layer "0". I can select the polyline layer via the property editor but I wanted to do this in code.
I have also noticed (as a sanity test for myself), if I select either layer "0" or "A" before dropping the MyRectangle item from the library browser, and in code get the current layer it is always the same id (21).
I have pasted the relevant code below:
TypeA.getOperation = function(di, width, height) { // the dots: var va = new Array(new RVector(0, 0), new RVector(0, height), new RVector(width, height), new RVector(width, 0)); // the dot connection pairs: // // 1 +----------------+ 2 // | | // | | // 0 +----------------+ 3 // // var linePairs = [[0,1], [1,2], [2,3], [3,0], [1,3], [0,2]]; // var linePairs = [[0,1], [1,2], [2,3], [3,0]]; // connect the dots: // Create the polyline shape var polyline = new RPolylineData(); for (var p = 0; p < va.length; p++) { polyline.appendVertex(va[p]); } // Make it closed polyline.setClosed(true); // id is always the same id whichever layer I select before dropping the script onto the drawing var id = di.getDocument().getCurrentLayerId(); // Select Layer "A" di.getDocument().setCurrentLayer("A"); // id = di.getDocument().getCurrentLayerId(); // Create a polylineEntity so we can add custom properties to them var polylineEntity = new RPolylineEntity(di.getDocument(), polyline) // Set some test custom properties polylineEntity.setCustomProperty("My Property Test", "Name", "Bob"); polylineEntity.setCustomProperty("My Property Test", "Length", "100"); // Place it in layer "A" this returns true polylineEntity.setProperty(RPolylineEntity.PropertyLayer, "A"); // Add the operation and return var addOperation = new RAddObjectOperation(polylineEntity); return addOperation; }I know there are different ways of creating the polyline which seem to work but the above code is the one I ended up using.
I Hope someone can shed some light on this, I am only just starting out with scripting but have years of C++ etc experience.
Thanks,
Andrew.