Page 1 of 1

Scripting question, add hatch

Posted: Tue Jun 21, 2011 11:15 pm
by hungerburg
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);
}

Posted: Wed Jun 22, 2011 8:18 am
by andrew
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);
}

Posted: Wed Jun 22, 2011 9:57 am
by hungerburg
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]));
}