Page 1 of 1

Scripting Question?

Posted: Mon Jul 01, 2013 8:00 pm
by dodaykos
In my current script, I have managed to successfully insert line and text entities, but I need to be able to add rows of symbols that are located in my library. My question is: how would I go about inserting a .dxf file through code?

Re: Scripting Question?

Posted: Tue Jul 02, 2013 12:02 pm
by hungerburg
Below pseudo-code is taken from a utility function of mine.

Code: Select all

    var DING = # A reference to the current drawing #
    var bPath = "/absolute/path/to/block/drawing.dxf"
    var bName = "Name of the Block";
    var FAIL = function() { debugger; };
    var x = y = 0; // Insert Position
    var h = v = false; // Insert Mirror

    var bDoc = new RDocument(new RMemoryStorage(), new RSpatialIndexNavel());
    var bInt = new RDocumentInterface(bDoc);
    if (bInt.importFile(bPath) != RDocumentInterface.IoErrorNoError) {
        FAIL("Block missing: " + bPath);
        bInt.destroy();
        return;
    }

    var operationP = new RPasteOperation(bDoc);
    operationP.setOffset(new RVector(x, y));
    operationP.setBlockName(bName);
    operationP.setScale(1.0);
    operationP.setRotation(0.0);
    operationP.setFlipHorizontal(h || false);
    operationP.setFlipVertical(v || false);
    operationP.setToCurrentLayer(true);
    operationP.setOverwriteLayers(false);
    operationP.setOverwriteBlocks(false);
    DING.documentInterface.applyOperation(operationP);
    bInt.destroy();

Re: Scripting Question?

Posted: Wed Jul 03, 2013 3:39 pm
by dodaykos
Aha! Much thanks, hungerburg! :D