How to transform returned curve array?


#1

I’m not sure I am doing this correctly so I thought I would ask here.

Using RhinoPython, I have a list of lines and arcs. I convert to nurbs curves and combine for one list. I then join them together with Rhino.Geometry.Curve.JoinCurves. It works, I think, and it returns an array of curves:

def getShape(self):
    curveList = []
    for line in self.lineList:
        curveList.append(line.ToNurbsCurve())
    for arc in self.arcList:
        curveList.append(arc.ToNurbsCurve())
    joinedCurves = Rhino.Geometry.Curve.JoinCurves(curveList)
    return joinedCurves

The only way I could find to add the array of curves to the document is to step through array and scriptcontext.doc.Objects.AddCurve(curve) for each one. Somehow, the result is a single joined curve in the viewport.

The next thing I need to do is transform this curve, but I can’t figure out how to apply a transform to the returned array of curves. I am working around it now by transforming each curve as I add it to the document, but that doesn’t seem like the best way to go about it.

shapeCurve = shape.getShape()
            for curve in shapeCurve:
                curve.Transform(moveXform)
                curve.Transform(mirrorXform)
                curve.Transform(rotationXform)
                sc.doc.Objects.AddCurve(curve)

So my question is, after the joining, how do I manipulate the joined curve? How does the document know the array of curves is supposed to be joined? I think if I knew that I could answer the first question.

Thanks!


#2

The array that Rhino.Geometry.Curve.JoinCurves() is returning is an array of the joined curves. The reason it’s an array is that the result of the join could be more than one curve.

If you are absolutely certain that there is only one single joined curve being returned by the method, you can do something like this and avoid the loop:

if len(joinedCurves)==1:
    shapeCurve=joinedCurves[0]
    shapeCurve.Transform(moveXform)
    shapeCurve.Transform(mirrorXform)
    shapeCurve.Transform(rotationXform)
    sc.doc.Objects.AddCurve(shapeCurve)

–Mitch


#3

Ah, didn’t think to check the length of the array, just assumed it was all the pieces I was joining. Thanks!