So i was headed in another direction with atleast getting and checking if the lods were in a list.
so maybe something like if this is not in the list but this is....
changes = ....
def LODEdit(db,parent,rec,userData): name = mgGetName(rec) lodList = name if 'lod_lo' in lodList: changes = mgSetAttList(rec, fltLodSwitchIn, 5000, fltLodSwitchOut, 15000) if 'lod_hi' in lodList: changes = mgSetAttList(rec, fltLodSwitchIn, 15000, fltLodSwitchOut, 2500) if 'lod_clutter' in lodList: changes = mgSetAttList(rec, fltLodSwitchIn, 2500, fltLodSwitchOut, 0) if 'lod_lights' in lodList: changes = mgSetAttList(rec, fltLodSwitchIn, 80000, fltLodSwitchOut, 0) return MG_TRUE
Hey John,
Sorry I missed your first post. It looks like you are getting really close to the solution. A few notes on what I see:
1) You need to find nodes with a given name. There are two good ways to do this. You can use mgFind or you can use mgWalk. It looks like you are doing both in the script. This is not needed. Either of these will do the trick. If you are searching for many different names, then mgWalk will probably be most simple, so this might be the best course of action.
2) I see you are using mgWalk with MWALK_MASTERALL. This is good practice when you need to walk into external references. Unfortunately, we do not allow modification of external references. These are part of a collection of read-only nodes. This is probably why you see even though you are setting the fltLodSwitch values they are not changing. I could be mistaken, but if your LOD nodes are in externals, you will need to first search for all external nodes, then open each external node and walk them directly. If you have nested externals, this can be even more complicated.
I modified your script to remove the mgFind and tested it. It works perfect in a situation where there are no Exrefs.
def LODEdit(db,parent,rec,userData): name = mgGetName(rec) if name == 'lod_lo': changes = mgSetAttList(rec, fltLodSwitchIn, 5000, fltLodSwitchOut, 15000) if name == 'lod_hi': changes = mgSetAttList(rec, fltLodSwitchIn, 15000, fltLodSwitchOut, 2500) if name == 'lod_clutter': changes = mgSetAttList(rec, fltLodSwitchIn, 2500, fltLodSwitchOut, 0) if name == 'lod_lights': changes = mgSetAttList(rec, fltLodSwitchIn, 80000, fltLodSwitchOut, 0) return MG_TRUE db = mgGetCurrentDb() mgWalk(db,LODEdit,None,None,MWALK_MASTERALL)
The good news is that if you have Creator Pro, you can use this exact script inside of the batch-run-script tool. This tool will let you select this script to run and select all your exrefs to run it on.
chris, yeah this works as is. I was pleased I got it that far. But what I was wanting it to do is if there is no lod_lo, i would want the switch out numbers for lod_hi to be a different number.
def LODEdit(db,parent,rec,userData): name = mgGetName(rec) if name == 'lod_lo': changes = mgSetAttList(rec, fltLodSwitchIn, 5000, fltLodSwitchOut, 15000) if name == 'lod_hi': changes = mgSetAttList(rec, fltLodSwitchIn, 15000, fltLodSwitchOut, 2500) if name == 'lod_clutter': changes = mgSetAttList(rec, fltLodSwitchIn, 2500, fltLodSwitchOut, 0) if name == 'lod_lights': changes = mgSetAttList(rec, fltLodSwitchIn, 80000, fltLodSwitchOut, 0) return MG_TRUE db = mgGetCurrentDb() mgWalk(db,LODEdit,None,None,MWALK_MASTERALL)
Ok, I see what you are getting at.
I modified it to do what you are thinking. The trick is to use a storage class and pass that storage class as userData to the walk. Then you just find the LODs you are looking for and store them in the class. Then after the walk you can decide what the ranges are after you know what LODs are found.
I noticed that your switch in was smaller than your switch out in the code. The switch in determines when to start showing an LOD, and the switch out determines when to stop showing the LOD. So if you are flying toward something, it will switch in at a large distance, then when you get too close it will switch out as something else switches in. Basically I think your values were backward.
Here is the script that probably does what you are looking for.
reallyFar = 15000 sortaFar = 5000 prettyClose = 2500 veryClose = 0 class LODStorage: pass def LODEdit(db,parent,rec,userData): name = mgGetName(rec) if name == 'lod_lo': userData.lo = rec if name == 'lod_hi': userData.hi = rec if name == 'lod_clutter': userData.clutter = rec if name == 'lod_lights': userData.lights = rec return MG_TRUE db = mgGetCurrentDb() foundLods = LODStorage() foundLods.lo = None foundLods.hi = None foundLods.clutter = None foundLods.lights = None mgWalk(db,LODEdit,None,foundLods,MWALK_MASTERALL) if foundLods.lo: changes = mgSetAttList(foundLods.lo, fltLodSwitchIn, reallyFar, fltLodSwitchOut, sortaFar) if foundLods.hi and foundLods.lo: changes = mgSetAttList(foundLods.hi, fltLodSwitchIn, sortaFar, fltLodSwitchOut, veryClose) elif foundLods.hi: changes = mgSetAttList(foundLods.hi, fltLodSwitchIn, reallyFar, fltLodSwitchOut, veryClose) if foundLods.clutter: changes = mgSetAttList(foundLods.clutter, fltLodSwitchIn, prettyClose, fltLodSwitchOut, veryClose) if foundLods.lights: changes = mgSetAttList(foundLods.lights, fltLodSwitchIn, 80000, fltLodSwitchOut, 0)
Sweet, this is working..thank you for this
little confused with the
foundLods.lo = None
why is there a None there?
None is a Python value. It is used for initialization and often when there are unexpected values or errors. I'm using it in the code to make sure the value exists and is easily checked to see if it has been set to a valid value.
ah, ok. Thank you for the clarification. Sorry to have so many questions. I can read all day on python tips and tricks but dont really understand it until its applied to something Im using it for.
So I try to go back after I get a script running and leave very detailed comments on exactly what is going on. like way more text than a basic "it does this"
I definitely appreciate the help received.
I'm happy to help!
played with it some more and this came out working with everything I needed.
reallyFar = 80000 kindaFar = 50000 sortaFar = 15000 prettyClose = 2500 veryClose = 0 class LODStorage: pass def LODEdit(db,parent,rec,userData): name = mgGetName(rec) if name == 'lod_lo': userData.lo = rec if name == 'lod_hi': userData.hi = rec if name == 'lod_clutter': userData.clutter = rec if name == 'lod_lights': userData.lights = rec return MG_TRUE db = mgGetCurrentDb() foundLods = LODStorage() foundLods.lo = None foundLods.hi = None foundLods.clutter = None foundLods.lights = None mgWalk(db,LODEdit,None,foundLods,MWALK_MASTERALL) if foundLods.lo and foundLods.hi and foundLods.clutter and foundLods.lights: changes = mgSetAttList(foundLods.lo, fltLodSwitchIn, kindaFar, fltLodSwitchOut, sortaFar) changes = mgSetAttList(foundLods.hi, fltLodSwitchIn, sortaFar, fltLodSwitchOut, prettyClose) changes = mgSetAttList(foundLods.clutter, fltLodSwitchIn, prettyClose, fltLodSwitchOut, veryClose) changes = mgSetAttList(foundLods.lights, fltLodSwitchIn, reallyFar, fltLodSwitchOut, veryClose) elif foundLods.lo and foundLods.hi and foundLods.lights: changes = mgSetAttList(foundLods.lo, fltLodSwitchIn, kindaFar, fltLodSwitchOut, sortaFar) changes = mgSetAttList(foundLods.hi, fltLodSwitchIn, sortaFar, fltLodSwitchOut, veryClose) changes = mgSetAttList(foundLods.lights, fltLodSwitchIn, reallyFar, fltLodSwitchOut, veryClose) elif and foundLods.hi and foundLods.lights: changes = mgSetAttList(foundLods.hi, fltLodSwitchIn, kindaFar, fltLodSwitchOut, veryClose) changes = mgSetAttList(foundLods.lights, fltLodSwitchIn, reallyFar, fltLodSwitchOut, veryClose)
your last 'elif' starts with an 'and'
this might through an error when it hits this case. (not quite sure what it will do)
probably best to delete that extra 'and'
yeah i see that. now. I guess that was just me typing it in here.
John
So I have figured out a bit of what I asked about a few weeks ago. I only got so far and dont really know where to go next.
So say there is only an lod_hi and lod lights
what can i say that if it sees no lod_lo, to change lod_hi switch out to a different number?
if/and/elsif/or...im not sure what