I have several switches that I would like to combine, each with ~80 children. I'd like one of the selected switches to be a 'root' or parent, and each child of the other switches get re-located to become a child of the corresponding node on the root or parent.
Combine node search came back with nothing useful (I did not look past the first few seemingly off topic returns).
Was hoping someone already had a script to do this, or something similar.
Yep, I like those comments, thanks!
Am I right in thinking I need to grab switch children while processing rec?
As my code is now, I go through and get names and child counts. But in order to re-structure the hierarchy, I need to re-locate into rec, yes?? Otherwise, how do I reverse engineer from a switch name and child number (so far I only have a count, not a list of child node id/names)??
# 01.20.2017 zip multiple switches together # if there is a mismatch in switch node counts, the 'prime' # switch must contain more children, else error # # portions of this script from Presagis support forum # db = mgGetCurrentDb() selectList = mgGetSelectList (db) num_recs = mgGetRecListCount(selectList) # invert selection; the last shall become first (check select panel) rec,matrix = mgGetNthRecInList (selectList, num_recs) def DeleteAllMasks(switch): numMasks = mgGetSwitchMaskCount(switch) for i in range(0,numMasks): b = mgDeleteSwitchMask(switch, 0) def SetSimpleSwitchMasks(switch): numChildren = mgCountChild(switch) # there will always be one mask for i in range(0,numChildren-1): mgAddSwitchMask(switch) numMasks = mgGetSwitchMaskCount(switch) print numMasks,numChildren for i in range(0,numMasks): mgInitSwitchMask(switch, i, MG_FALSE) mgSetSwitchBit(switch, i, i, MG_TRUE) child_counts =  switch_list =  if (num_recs == 0): mgSendMessage (MMSG_ERROR, "Select two or more switches to zip") elif (mgGetCode(rec) != fltSwitch): mgSendMessage (MMSG_ERROR, "No Switch node selected") elif num_recs < 2: mgSendMessage (MMSG_ERROR, "Only one Switch selected!") else: #print num_recs for i in range (0, num_recs): rec,m = mgGetNextRecInList (selectList) if (mgGetCode(rec) != fltSwitch): mgSendMessage (MMSG_ERROR, "Invalid selection - switch nodes only!") break # mgSelectOne(rec) # name = mgGetName (rec) switch_list.append(mgGetName (rec)) # print name, i child_counts.append( mgCountChild(rec)) # check child counts; OK if first sel has more nodes than others, otherwise error # first index is from prime/primary prime_count = child_counts for x in range(1, len(child_counts)): if child_counts[x] > prime_count: mgSendMessage (MMSG_ERROR, "Primary switch has fewer children than others") break # for each switch selected, re-parent to switch (primary) for x in range(1, len(switch_list)): print switch_list[x] # for each child of prime node for y in range (0, child_counts): #print switch_list
Hang on, it sounds like you are doing something extra now. The script I gave you originally was intended to simply "reset" the switch masks --after-- you did all the attach/detach manually in Creator. Sounds like you want the script to do more? Attach / Detach nodes under the switch? If so, IMO that is a completely different script. Can you clarify or confirm? Thanks
Yes, I know :(
I don't like the manual re-parent bit.
"I have several switches that I would like to combine, each with ~80 children. I'd like one of the selected switches to be a 'root' or parent, and each child of the other switches get re-located to become a child of the corresponding node on the root or parent."