Start a new topic

What's the proper way to parse a db from the selection to a specified level, say objects?

Greetings,


I know mgWalk is used to parse a database, can it also be used to walk the selection (from a Creator script)? How is this done?  Let's say

  

db = mgGetCurrentDb()

SelectList = mgGetSelectList(db)
if mgGetRecListCount(selectList) == 1:

    if mgGetCode(rec) == fltObject:
        print('Found FLTOBJECT')
    else:
        # not an object selected, so walk the selected tree returning objects in a list

  


Thanks!


Shawn

1 Comment

OK, previous post indicated I had something, but I'm not doing something right b/c I get the same nodes printing no matter what I select.


So apparently this does not in fact work:

 

mgWalk (rec, None, gatherObjNodes, objList, MWALK_ON)

 

Here's the full code:


  

db = mgGetCurrentDb()
selectList = mgGetSelectList (db)

def gatherObjNodes (db, parent, rec, objList):
    if mgGetCode (rec) == fltObject:
        print('found object!')
        objList.append(rec)
    return MG_TRUE
    
def getObjTOD(rec):
    attrRec = mgGetAttList(rec,fltObjNoDay, fltObjNoDusk, fltObjNoNight)
    # tuple
    print(mgGetName(rec))
    print(type(attrRec), attrRec)
    
objList = []
    
print('Length of list:', len(selectList))
print('code is:', mgGetCode(rec))

if not mgGetCode(rec) == fltObject:
    print('Selection is not an object')
    mgWalk (rec, None, gatherObjNodes, objList, MWALK_ON)
    
    print('Objects?',len(objList))
    for x in objList:
        getObjTOD(x)
else:
    print('Found FLTOBJECT')
    
    getObjTOD(rec)
        

  


Thx


Shawn


Login to post a comment