algorithmic modeling for Rhino
I'm trying to reverse the direction of a curve in code. The curve is a real one, in the document, and I want the reversal to "stick" in the document. That is, I want to reverse the direction of the the curve in the file. So I'm getting the curve by Guid (necessary?), and calling Reverse on its Geometry, but it ain't working.
The subroutine looks like this (pardon lack of formatting):
void SetCurveDirectionFrom(Guid cableID, Point3d startPoint)
{
// Find the object from its id
Rhino.DocObjects.RhinoObject cable = doc.Objects.Find(cableID);
if(cable == null)
{
Print("Null Cable!");
return;
}
// The startPoint is either at the start or end of the curve: if at the end, reverse it
Curve cableCrv = (Curve) cable.Geometry;
if(startPoint.Equals(cableCrv.PointAtEnd))
{
cableCrv.Reverse();
}
}
Any insight is appreciated.
(PS: how can I get pasted code to format well in these posts?)
Tags:
You need to put the curve back into the document. Getting a curve out of a document means you'll get a copy, as objects inside the document cannot be modified.
Have a look at RhinoDoc.Objects.Replace()
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thank you David! That did it. I had a feeling I needed to either get a reference to the real thing and operate on that, or somehow tell the document to keep the changes that I made on "my" copy.
For posterity, this seems to work well now:
void SetCurveDirectionFrom(Guid cableID, Point3d startPoint)
{
// Find the object from its id
Rhino.DocObjects.RhinoObject cable = doc.Objects.Find(cableID);
if(cable == null)
{
Print("Null Cable!");
return;
}
// The startPoint is either at the start or end of the curve: if at the end, reverse it
Curve cableCrv = (Curve) cable.Geometry;
if(startPoint.Equals(cableCrv.PointAtEnd))
{
cableCrv.Reverse();
// Replace it in the document
bool success = doc.Objects.Replace(cableID, cableCrv);
if(!success)
Print("Replace failed");
}
}
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by