mcneel / ghpython

A Grasshopper component for Rhino.Python
http://www.food4rhino.com/project/ghpython
118 stars 34 forks source link

conditional failure #10

Closed bengolder closed 13 years ago

bengolder commented 13 years ago

Here is my gh python script:


import Rhino
import scriptcontext
# if the switch is on:
if ImportSwitch == True:
    opt = Rhino.FileIO.FileReadOptions()
    opt.ImportMode = True
    # if the delete is on:
    if DeleteSwitch == True:
        objtype = Rhino.DocObjects.ObjectType.AnyObject
        enumSettings = Rhino.DocObjects.ObjectEnumeratorSettings()
        enumSettings.ObjectTypeFilter = objtype
        guids = [o.Id for o in scriptcontext.doc.Objects.FindByFilter(enumSettings)]
        scriptcontext.doc.Objects.Delete(guids, True)
    # for each file:
    for fpath in FilePaths:
        # import it
        scriptcontext.doc.ReadFile(fpath, opt)
layerTree = []
# get everything on the layers
for layname in LayerNames:
    objs = scriptcontext.doc.Objects.FindByLayer(layname)
    guidString = ','.join([str(obj.Id) for obj in objs])
    layerTree.append(guidString)
a = layerTree

the input variables are:

scriptcontext.doc is targeted to the Rhino doc, not the gh doc if ImportSwtich is False, and I change the the contents of FilePaths, I would expect this to not read any files. But it reads files any time that the contents of FilePaths are changed. even while ImportSwitch is off.

... and the guidstrings are a hack becauuse I don't know how to make DataTrees in python. : /

my apologies if I'm posting too many issues. It means that I'm really excited about this component. :D

piac commented 13 years ago

rhinocommon-related question