Scripting question, add hatch

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Scripting question, add hatch

Postby 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
hungerburg
Senior Member
 
Posts: 125
Joined: Fri May 28, 2010 7:35 pm

Postby 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
andrew
Site Admin
 
Posts: 2556
Joined: Fri Mar 30, 2007 6:07 am

Postby 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]));
}
User avatar
hungerburg
Senior Member
 
Posts: 125
Joined: Fri May 28, 2010 7:35 pm


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 2 guests