I work with Xubuntu 14.04 (64 bit) and QCad Professional 3.7.0. The script BlocksFromFile reads lines from a csv-file and created blocks from the data stored in this file. It is used to start in a drawing, which was created by a template, where a few layers are defined.
The blocks consists of a rectangle and two numbers, which describe the length and the width. Layer “18 mm” is to be assigned to the rectangle (the name of the layer depends on the data in the csv-file). Layer “Text” is to be assigned to the numbers.
… var block = new RBlock(document, name, new RVector(0,0)); var operation = new RAddObjectOperation(block); di.applyOperation(operation); // make new block the current block: di.setCurrentBlock(name); // Layer festlegen switch (stueck[6]) { case 18: ebene = "18 mm"; break; case 28: ebene = "28 mm"; break; case 5: ebene = "5 mm"; break; default: ebene = "0"; break; } di.setCurrentLayer(ebene); // Zeichne ein Rechteck aus Länge und Breite var p1 = new RVector(0, 0); var p2 = new RVector(stueck[2], 0); var p3 = new RVector(stueck[2], stueck[3]); var p4 = new RVector(0, stueck[3]); var line1 = new RLineEntity(document, new RLineData(p1, p2)); var line2 = new RLineEntity(document, new RLineData(p2, p3)); var line3 = new RLineEntity(document, new RLineData(p3, p4)); var line4 = new RLineEntity(document, new RLineData(p4, p1)); operation = new RAddObjectsOperation(); operation.addObject(line1); operation.addObject(line2); operation.addObject(line3); operation.addObject(line4); // Layer festlegen di.setCurrentLayer("Text"); // Länge und Breite als Text in die Mitte der Seiten var pos = new RVector((stueck[2]/2),stueck[3]); // create a text entity and add it to the operation: // für die Länge var textL = new RTextEntity( document, new RTextData( pos, // position pos, // alignment point 20, // height 20, // text width (ignored for now) RS.VAlignTop, // alignments RS.HAlignCenter, RS.LeftToRight, RS.Exact, 1.0, // line spacing factor String(stueck[2]), // the text "Liberation Sans", // font false, // bold false, // italic 0.0, // angle false // simple text without formatting ) ); operation.addObject(textL); // Berechne die Position var pos = new RVector(0,(stueck[3]/2)); // für die Breite var textB = new RTextEntity( document, new RTextData( pos, // position pos, // alignment point 20, // height 20, // text width (ignored for now) RS.VAlignMiddle, // alignments RS.HAlignLeft, RS.LeftToRight, RS.Exact, 1.0, // line spacing factor String(stueck[3]), // the text "Liberation Sans", // font false, // bold false, // italic 0.0, // angle false // simple text without formatting ) ); operation.addObject(textB); di.applyOperation(operation); ...In this case the complete block is assigned to layer “Text”. When I put the the statement di.applyOperation(operation); after the drawing of the rectangle (operation.addObject(line4);) the application will crash.
In the attachment you will find the complete coding of the script. How must I change the coding, so that there are different layers for different objects?
Regards
Peter