How to create Hatch with script

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
mpele
Newbie Member
Posts: 7
Joined: Mon Jan 02, 2017 9:57 am

How to create Hatch with script

Post by mpele » Tue Feb 21, 2017 11:59 am

I am trying to modify HatchFromSelection.js to create simple hatch for "virtual triangle" but there is no result.
Could anyone help me with this code?

Code: Select all

HatchFromSelection.prototype.beginEvent = function() {
    EAction.prototype.beginEvent.call(this);

    var doc = this.getDocument();
    var di = this.getDocumentInterface();

    var hatchData = new RHatchData();
    hatchData.setDocument(doc);
	
	hatchData.setLineweight(RLineweight.Weight015);

	hatchData.newLoop();
	hatchData.addBoundary(new RLine(new RVector(0,0), new RVector(100,0)));
	hatchData.addBoundary(new RLine(new RVector(100,0), new RVector(200,0)));
	hatchData.addBoundary(new RLine(new RVector(200,0), new RVector(0,0)));
	
	EAction.handleUserWarning(qsTr("hatchData.getExploded: "+hatchData.getExploded()), true);

    hatchData.setSolid(true);
    hatchData.setScale(1);
    hatchData.setAngle(10);
    hatchData.setPatternName("Test");

    var hatch = new RHatchEntity(doc, hatchData);
    var op = new RAddObjectOperation(hatch, false, false);
	
    di.applyOperation(op);

    di.autoZoom();
EAction.handleUserWarning(qsTr("beginEvent finished"), true);
    this.terminate();
	
};

mpele
Newbie Member
Posts: 7
Joined: Mon Jan 02, 2017 9:57 am

Re: How to create Hatch with script

Post by mpele » Wed Feb 22, 2017 8:35 am

I have found problem - there is no problem. The coordinates of triangle are on one line so, there are no visible hatch :oops:

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”