Display Conduit making python functions not seem to work

Hi – I am having a really weird error when I enable & then disable the display conduit within a function, & then run more code, for some reason the len() function does not work. I am trying to get the length of a list, & found that list.Count works in this case. However, it is really weird that when the display conduit is enabled then disabled, the len(list) function gives an error: float is not callable, even though list is a list…With the display conduit code commented out, the len(list) works fine…

Has anyone ran into this error before??

Oh, also, I just tested the list.Count with the display conduit code commented out, & receive an error ‘list’ object has no attribute ‘count’ strange.

ACTUALLY – we just discovered that if you are importing Rhino to a python script you can call a list.Count, BUT if you do not import Rhino, a list has no attribute Count.

Does Rhino somehow extend pythons list class to have the attribute Count??

I don’t think anyone is going to be very helpful without looking at some sample code…

here is the function where the conduit is called:

def buildRules(shapeList,topos,sShapesIn ):

    addShape = False

    shapeRuleAddData = rs.ListBox(shapeList, "Select Shape to Add Rule", "NT_vTools v1")
    if shapeRuleAddData is None:
        return None

    shapeRuleAddDataTok = shapeRuleAddData.split(" " )

    if shapeRuleAddDataTok[0] == "Add":
        return None


    rulesExistAlready = True
    if test<3: rulesExistAlready = False

    shapeNum = int(shapeRuleAddDataTok[1])-1


    cTopo = rs.coercebrep(sShapesIn[shapeNum])
    vData = Rhino.Geometry.VolumeMassProperties.Compute(cTopo)

    bBox = cTopo.GetBoundingBox(False)
    len = bBox.Diagonal.Z
    vec = Rhino.Geometry.Vector3d(0,0,len)
    center = vData.Centroid
    ##DISPLAY CONDUIT!
    ptStart = center
    ptEnd = Rhino.Geometry.Point3d(center.X,center.Y,center.Z+len )

    line = Rhino.Geometry.Line(ptEnd,ptStart)
    screenSize=0
    worldSize=0.5
    conduit = DrawArrowHeadsConduit(line, screenSize, worldSize)


    conduit.Enabled = True
    scriptcontext.doc.Views.Redraw()
    #rs.GetString("Pausing for user input")

    #GET NEW OBJECTS
    objs,units = getRule(topos,shapeNum,rulesExistAlready)

    conduit.Enabled = False
    scriptcontext.doc.Views.Redraw()


    #test = shapeRuleAddDataTok.Count
    test = len(shapeRuleAddDataTok)

    if objs == None:
        return [None, None, shapeList,False, False, units]


    if not rulesExistAlready:
        shapeList[shapeNum]= shapeRuleAddDataTok[0]
    else:
        rulesAdded = shapeRuleAddDataTok[1].split("(")
        rCount = int(rulesAdded[1])+1
        shapeList[shapeNum]=shapeRuleAddDataTok[1] + " ("+str(rCount)+" added)"




    return [objs, shapeNum, shapeList,True, False, units]

& the conduit is a simple arrow display:

class DrawArrowHeadsConduit(Rhino.Display.DisplayConduit):
  def __init__(self, line, screenSize, worldSize):
    self.line = line
    self.screenSize = screenSize
    self.worldSize = worldSize

  def DrawForeground(self, e):
    e.Display.DrawArrow(self.line, System.Drawing.Color.Red, self.screenSize, self.worldSize)

Also, here is a modified version of the entire code i’m running – the error is happening @ line 182

import rhinoscriptsyntax as rs
import Rhino
import System.Drawing
import scriptcontext
import System.Windows.Forms
import math,time
import System


class DrawArrowHeadsConduit(Rhino.Display.DisplayConduit):
  def __init__(self, line, screenSize, worldSize):
    self.line = line
    self.screenSize = screenSize
    self.worldSize = worldSize

  def DrawForeground(self, e):
    e.Display.DrawArrow(self.line, System.Drawing.Color.Red, self.screenSize, self.worldSize)



def main():
    section = "NT_vTools"
    rExist = False
    objData = rs.GetDocumentData(section)

    if len(objData)!=0:
        rExist = True

    rules = []
    topos = []
    shapeList = []
    units = []


    if rExist:
        topoCount = int(rs.GetDocumentData(section,"T_count"))

        sShapesIn = []


        for i in range(topoCount):
            rules.append([])

            tEntry = "T-"+str(i)
            shapeIn = System.Guid(rs.GetDocumentData(section,tEntry))
            sShapesIn.append(shapeIn)

            shape = rs.coercebrep(shapeIn)
            topos.append( [shape.Vertices.Count, shape.Faces.Count])


            ruleCount = int(rs.GetDocumentData(section,tEntry+"_count"))

            if ruleCount==1:
                shapeList.append("Shape "+str(i+1)+ " ("+str(ruleCount)+" rule added)")
            else:
                shapeList.append("Shape "+str(i+1)+ " ("+str(ruleCount)+" rule's added)")

            for j in range(ruleCount):
                rEntry = tEntry + "_R-"+str(j)
                datain = rs.GetDocumentData(section,rEntry)
                tokData = datain.split(",")
                ruleObjs = []
                for k in range(len(tokData)):
                    ruleObjs.append(System.Guid(tokData[k]))



                rules[i].append(ruleObjs)


        shapeList.append("Add New Topology")

    else:

        sShapesIn = rs.GetObjects("select Seed Shapes",rs.filter.polysurface)
        if sShapesIn is None: #error Checking
            print "forgot input"
            return


        for i in range(0,len(sShapesIn)):
            shape = rs.coercebrep(sShapesIn[i])
            topos.append( [shape.Vertices.Count, shape.Faces.Count])
            shapeList.append("Shape "+str(i+1))
            rules.append([])
            units.append([])
        shapeList.append("Add New Topology")


    while True:
        objs, data1, nShapeList, addRule, endBuild, nUnits = buildRules(shapeList, topos,sShapesIn)

        if addRule:
            rules[data1].append(objs)
            if nUnits:
                units[data1].append(nUnits)
            shapeList = nShapeList
        elif objs == None:
            shapeList = nShapeList
        else:
            rules.append([])
            units.append([])

            topos = data1
            shapeList = nShapeList
            sShapesIn.append(objs)

        if endBuild:
            break

    totalTopos = len(sShapesIn)

    rs.SetDocumentData(section, "T_count",str(totalTopos))

    tCount = 0
    for rulesInType in rules:
        RuleEntry = "T-"+str(tCount)
        rs.SetDocumentData(section, RuleEntry,str(sShapesIn[tCount]))
        totalRules = len(rulesInType)
        rs.SetDocumentData(section, RuleEntry+"_count",str(totalRules))

        for i in range(totalRules):
            entry = RuleEntry + "_R-"+str(i)

            strRuleGuids = str(rulesInType[i][0])
            for j in range(1,len(rulesInType[i])):
                strRuleGuids+=","+str(rulesInType[i][j])

            rs.SetDocumentData(section, entry,strRuleGuids)
        tCount+=1


    print "saved"
    #buildRules(shapeList, topos)



def buildRules(shapeList,topos,sShapesIn ):

    addShape = False

    shapeRuleAddData = rs.ListBox(shapeList, "Select Shape to Add Rule", "NT_vTools v1")
    if shapeRuleAddData is None:
        return None

    shapeRuleAddDataTok = shapeRuleAddData.split(" " )

    if shapeRuleAddDataTok[0] == "Add":
        return None





    shapeNum = int(shapeRuleAddDataTok[1])-1


    cTopo = rs.coercebrep(sShapesIn[shapeNum])
    vData = Rhino.Geometry.VolumeMassProperties.Compute(cTopo)

    bBox = cTopo.GetBoundingBox(False)
    len = bBox.Diagonal.Z
    vec = Rhino.Geometry.Vector3d(0,0,len)
    center = vData.Centroid
    ##DISPLAY CONDUIT!
    ptStart = center
    ptEnd = Rhino.Geometry.Point3d(center.X,center.Y,center.Z+len )

    #test = ptStart + vec
    line = Rhino.Geometry.Line(ptEnd,ptStart)
    screenSize=0
    worldSize=0.5
    conduit = DrawArrowHeadsConduit(line, screenSize, worldSize)


    conduit.Enabled = True
    scriptcontext.doc.Views.Redraw()
    #rs.GetString("Pausing for user input")

    #test = shapeRuleAddDataTok.Count
    test = len(shapeRuleAddDataTok)

    rulesExistAlready = True
    if test<3: rulesExistAlready = False
    #GET NEW OBJECTS
    objs,units = getRule(topos,shapeNum,rulesExistAlready)

    conduit.Enabled = False
    scriptcontext.doc.Views.Redraw()





    if objs == None:
        return [None, None, shapeList,False, False, units]


    if not rulesExistAlready:
        shapeList[shapeNum]= shapeRuleAddDataTok[0]
    else:
        rulesAdded = shapeRuleAddDataTok[1].split("(")
        rCount = int(rulesAdded[1])+1
        shapeList[shapeNum]=shapeRuleAddDataTok[1] + " ("+str(rCount)+" added)"




    return [objs, shapeNum, shapeList,True, False, units]
    #buildRules(shapeList,topos)


def getRule(topos,shapeNum,rulesExistAlready):

    topo = topos[shapeNum]

    def cp_filt1(rhino_object, geometry, component_index):
        iscpFilt = False

        topoCheck = [geometry.Vertices.Count, geometry.Faces.Count]
        if topo==topoCheck:
            return True
        else:
            return False

    def cp_filt2(rhino_object, geometry, component_index):
        iscpFilt = False

        topoCheck = [geometry.Vertices.Count, geometry.Faces.Count]
        if topoCheck in topos:
            return True
        else:
            return False

    objs = []
    units = None

    getUnits = True

    if rulesExistAlready:

        msgBox = rs.MessageBox("add additional mesh unit types?", 4, "NT_vTools v1")
        if msgBox == 7:
            getUnits = False

    if getUnits :
        units = rs.GetObjects("select Unit Curves, Pts, &/or Meshes"+str(shapeNum+1), rs.filter.curve+rs.filter.point+rs.filter.mesh)
        if units is None: #error Checking
            print "no Units input"

    baseShape = rs.GetObject("select base shape -- RULE "+str(shapeNum+1),rs.filter.polysurface,custom_filter=cp_filt1 )
    if baseShape is None: #error Checking
        print "forgot input"
        return None

    objs.append(baseShape)

    children = rs.GetObjects("select base shape Children -- RULE "+str(shapeNum+1), rs.filter.polysurface,custom_filter=cp_filt2 )
    if children is None: #error Checking
        print "forgot input"
        return None

    objs.extend(children)

    return [objs,units]



if( __name__ == "__main__" ):
    main()

Hi Bradley,

Can you just post your .py file?

To get better formatting of your script on this forum, please read this

vTools_latticeSetup_7.py (8.5 KB)

here is the .py file – if you uncomment line 174 & run, you will get the error I am mentioning…

Maybe the first question I have, though, is why when you import Rhino, you the Count attribute for lists work, but w/o importing rhino, if you try list.Count, it doesn’t work…

Well, I’m not smart enough to run your script. Perhaps a data file and some instructions might help.

But on line 185, I do see this:

len = bBox.Diagonal.Z

len is a Python function, and you are reusing the symbol as a variable. Not sure this is allowed.

Yeah, it’s just setup to store brep objects in rhino’s document data. That does solve the issue, but it doesn’t answer my question of why a list, when you import Rhino, has Count as an attribute, but if you don’t import rhino, there is no Count attribute. In python, I know there isn’t meant to be Count as a list attribute…

Probably because of this:

http://msdn.microsoft.com/en-us/library/27b47ht3(v=vs.100).aspx