I have a DXF file contains lots of blocks. And I want to export blocks to separated DXF files one by one by Javascript. I tried as below but it doesn't work. Did I miss something in those codes? Thank you.
Code: Select all
MyAction.prototype.beginEvent = function() {
MyTest.prototype.beginEvent.call(this);
var appWin = EAction.getMainWindow();
var di_src = EAction.getDocumentInterface();
var doc_src = di_src.getDocument();
var my_appWin = RMainWindowQt.getMainWindow();
var my_tabBar = my_appWin.getTabBar();
var idx = my_tabBar.currentIndex;
var ids = doc_src.queryAllBlocks();
if (ids.length !== 0) {
for (var i = 0; i < ids.length; i++) {
if (!doc_src.queryObject(ids[i]).isModelSpace() && !doc_src.isLayoutBlock(ids[i])) {
var action1 = RGuiAction.getByScriptFile("scripts/File/NewFile/NewFile.js");
if (!isNull(action1)) {
action2.slotTrigger();
}
var di_dest = EAction.getDocumentInterface();
var doc_dest = di_dest.getDocument();
var op_clipBoard = new RClipboardOperation();
op_clipBoard.copyBlock(ids[i], doc_src, doc_dest);
op_past = new RPasteOperation(RDocument.getClipboard());
op_past.setOffset(new RVector(0, 0));
op_past.setRotation(0.0);
op_past.setScale(1.0);
op_past.setFlipHorizontal(false);
op_past.setFlipVertical(false);
op_past.setToCurrentLayer(true);
op_past.setOverwriteBlocks(true);
di_dest.applyOperation(op_past);
di_dest.exportFile(myPath + blockName + ".dxf", "DXF 2000");
var action2 = RGuiAction.getByScriptFile("scripts/File/CloseFile/CloseFile.js");
if (!isNull(action2)) {
action2.slotTrigger();
}
}
}
var my_mdiArea = EAction.getMdiArea();
var windows = my_mdiArea.subWindowList();
my_mdiArea.setActiveSubWindow(windows[idx]);
} else {
appWin.handleUserMessage("an empty file");
}
this.terminate();
};