Scripting question, add hatch

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
User avatar
hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Scripting question, add hatch

Post by hungerburg » Tue Jun 21, 2011 11:15 pm

I want to create a hatch from a polyline, shouldnt this work?

Code: Select all

var hatch = new RHatchData(false, 200, 0, "ANSI31");
var polylinie = new RPolyline(punkte, true);
hatch.addBoundary(polylinie);
this works, of course its a lot of footwork…

Code: Select all

var hatch = new RHatchData(false, 200, 0, "ANSI31");
var polylinie = new RPolylineData();
for (var p = 0; p < punkte.length; p++) {
	polylinie.appendVertex(punkte[p]);
}
polylinie.setClosed(true);
hatch.newLoop();
var segments = new RPolylineEntity(zeichnung.document, polylinie).getExploded();
for (i=0; i<segments.length; i++) {
	var segment = segments[i];
	hatch.addBoundary(segment);
}

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

Post by andrew » Wed Jun 22, 2011 8:18 am

Adding a complete polyline as a single boundary element is currently not supported.

You should be able to simplify the code a bit by not using RPolylineData / RPolylineEntity but only RPolyline:

Code: Select all

var hatch = new RHatchData(false, 200, 0, "ANSI31");
var polylinie = new RPolyline();
for (var p = 0; p < punkte.length; p++) {
   polylinie.appendVertex(punkte[p]);
}
polylinie.setClosed(true);
hatch.newLoop();
var segments = polylinie.getExploded();
for (i=0; i<segments.length; i++) {
   var segment = segments[i];
   hatch.addBoundary(segment);
}

User avatar
hungerburg
Premier Member
Posts: 160
Joined: Fri May 28, 2010 7:35 pm

Post by hungerburg » Wed Jun 22, 2011 9:57 am

I see, its just the polyline, but the simple line should work - and it does, as long as I call hatch.newLoop() in the beginning :)

Code: Select all

var hatch = new RHatchData(false, 200, 0, "ANSI31");
hatch.newLoop();
var l = punkte.length;
punkte.push(punkte[0]);
for (var p = 0; p < l; p++) {
	hatch.addBoundary(new RLine(punkte[p], punkte[p+1]));
}

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”