Transaction failed. Please check for block recursions...

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
weze
Newbie Member
Posts: 6
Joined: Mon May 25, 2020 11:30 am

Transaction failed. Please check for block recursions...

Post by weze » Mon May 25, 2020 11:55 am

Hi,
currently I'm implementing a script which converts all spline entities in a drawing into polylines and exports then the complete drawing to a new DXF file. The conversion from spline to polyline works well (thanks to the scripting sources in Explode.js) as long as I stay in the original drawing and overwrite the spline entities with polylines. But I want to preserve the original drawing for the user and want to make the conversion and export in the background (offline the GUI). So I created a new Document and DocumentInterface and applied the addObjects with
applyOperation to the new DocumentInterface with the result of the Warning "Transaction failed. Please check for block recursions and locked or invisible layers or blocks." and an empty exported DXF file. Below is the source code of the involved function where all the stuff is done:

Code: Select all

Export2visitexLOC.explodeSplines = function(di) {
    var document = di.getDocument();
    var ids = document.queryAllEntities();
    var i, k;
    var appWin = EAction.getMainWindow();

    var splineTolerance = RSettings.getDoubleValue("Explode/SplineTolerance", 0.01);
    var splineSegments = RSettings.getIntValue("Explode/SplineSegments", 64);
    var splinesToLineSegments = RSettings.getBoolValue("Explode/SplinesToLineSegments", false);

    var op = new RAddObjectsOperation();

    for (i=0; i<ids.length; i++) {
        var id = ids[i];
        var entity = document.queryEntity(id);
        if (isNull(entity)) {
            debugger;
        }

        var newObj;
        var valid = true;
        if (isSplineEntity(entity)) {
            // explode spline into polyline with line segments (polyline and splines are shapes):
            var spline = entity.getData().castToShape();
            newObj = spline.toPolyline(splineSegments);
            newObj.simplify();
            valid = !newObj.isEmpty();
        }
        else {
            newObj = entity.clone();
        }

        if (!valid) {
            continue;
        }

        if (isEntity(newObj)) {
            op.addObject(newObj, false, true);
        }
        else {
            var e = shapeToEntity(entity.getDocument(), newObj);
            if (!isNull(e)) {
                e.setSelected(true);
                e.copyAttributesFrom(entity.data(), true);
                if (!isNull(newObj.color)) {
                    e.setColor(new RColor(newObj.color));
                }
                appWin.handleUserMessage(qsTr("new entity blockID: %1 [%2] ").arg(e.getBlockId()).arg(entity.getBlockId()));
                op.addObject(e, false);
            }
        }
    }

    debugger;
    if (!op.isEmpty()) {
        // create new document for export:
        var info = new QFileInfo(document.getFileName());
        var fileName = info.absolutePath() + "/" + info.baseName() + "_exp." + info.completeSuffix();
        var newDoc = new RDocument(new RMemoryStorage(), new RSpatialIndexSimple());
        newDoc.setFileName(fileName);
        var newDI = new RDocumentInterface(newDoc);
        newDI.applyOperation(op);
        if (!newDI.exportFile(fileName)) {
            appWin.handleUserWarning("Cannot export file: " + fileName);
        }
        newDI.destroy();
    }
};
Attached the original drawing spline.dxf with the spline shape I used for testing.

So maybe someone can give me a hint how to set up the document for the export correctly.

Thanks for any help!
Attachments
spline.dxf
(99.59 KiB) Downloaded 362 times

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

Re: Transaction failed. Please check for block recursions...

Post by andrew » Mon May 25, 2020 12:32 pm

An entity "lives" in a document and references a layer, a linetype, etc. in that document. If you query an entity in one document and then store it in another, you would have to adjust (at least) the layer ID, line type ID, the document pointer (setDocument).

weze
Newbie Member
Posts: 6
Joined: Mon May 25, 2020 11:30 am

Re: Transaction failed. Please check for block recursions...

Post by weze » Mon May 25, 2020 1:18 pm

Thank a lot for the fast response!

Implementing your advices solved the problem!

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”