+ Reply to Thread
Results 1 to 6 of 6

Thread: How to create a Rhino Common Object from a Guid

  1. #1

    How to create a Rhino Common Object from a Guid

    Hi,

    If I use the rs.GetObject("Get Object") to select for example a curve I get the Guid of the curve as a return value.

    Now I would like to create a NurbsCurve Object from that Guid (Rhino.Geometry.NurbsCurve())

    So I can delete the object from the scene, but later can access the data again, if I need it.

    How do I do that?

    Thanks for your help.
    Martin

  2. #2
    Hi,

    well I found a Solution.

    Python Code:
      #Get the Cuve
         guid = rs.GetObject("Get Curve")
         
         #Get the Instance of the currently active Rhino Document
         doc = Rhino.RhinoDoc.ActiveDoc
         
         #Get the Object from the current Active Doc
         object = doc.Objects.Find(guid)
         
         #Delete the Original Object
         rs.DeleteObject(guid)
         
         #Get CurveGeometry From Object
         crv = object.CurveGeometry
         
         #Create the Curve again (with a new ID)
         newObject = doc.Objects.AddCurve(crv)

    The only thing missing is a "isCurve" Command in Rhino Common. It's probably somewhere, but I couldn't find it.

    Thanks
    Martin

  3. #3
    New Member
    Join Date
    Apr 2010
    Location
    Bratislava, Slovakia
    Posts
    6
    how about: if object.ObjectType == Rhino.DocObjects.ObjectType.Curve

  4. #4
    Thanks Marian,
    sounds good.

    -
    Martin

  5. #5
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,472
    Blog Entries
    19
    Hi Martin,
    I would recommend changing this just a wee bit:
    Python Code:
      import rhinoscriptsyntax as rs
      import scriptcontext
       
      #Get the Cuve
      guid = rs.GetObject("Get Curve", rs.filter.curve)
       
      #Get the Instance of the document that ran this script. This is always the
      #same as Rhino.RhinoDoc.ActiveDoc on Windows, but on Mac this may not
      #be the case
      doc = scriptcontext.doc
         
      #Get the Object from the current Active Doc
      object = doc.Objects.Find(guid)
      #Get the curve geometry from the object
      crv = object.CurveGeometry
      # make absolutely sure that the curve is a "private" copy
      # and is not still under the control of the RhinoDoc
      crv.EnsurePrivateCopy()
      #Now delete the Original Object
      rs.DeleteObject(guid)
       
      # ...do some things...
      #Create the Curve again (with a new ID)
      newObject = doc.Objects.AddCurve(crv)
    Last edited by Steve Baer; 10-20-2010 at 11:42 AM.

  6. #6
    Thanks Steve,

    works great.

    -
    Martin
    Last edited by Martin; 12-08-2010 at 08:52 AM.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts