Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5809

Scope of GUIDs in GHPython

$
0
0

@toivosawen wrote:

Can somebody explain how GUIDs of objects in Grasshopper work? I have the following code to bake some curves into rhino and keep track of their ids:

def my_code():
    isocrvs = []
    #... populate isocrvs list here  ...

    # bake curve into rhino
    for crv in isocrvs:
        new_crv = bake_guide_crv(crv)
        #expected output: True
        #actual output: False
        print rs.IsCurve(new_crv)

def bake_guide_crv(guide_crv_id):
    sc.doc = Rhino.RhinoDoc.ActiveDoc
    # bake guide curve into rhino
    doc_object = rs.coercecurve(guide_crv_id)
    crv_id = sc.doc.Objects.AddCurve(doc_object)
    crv_obj = sc.doc.Objects.Find(crv_id)
    crv_obj.CommitChanges()

    #prints True as expected
    print rs.IsCurve(crv_id)
    rs.DeleteObject(guide_crv_id)
    #we put back the original Grasshopper document as default
    sc.doc = ghdoc
    return crv_id

 if __name__ == '__main__':
    my_code()

Since the curve now exists in rhino, the rs.IsCurve() function should return True? Why does it work within the function, but not after passing the GUID back to the parent function?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 5809

Trending Articles