Notifications
Clear all

[Closed] Theory Questions

Some quick theory questions:

  1. Is it always advisible to store the objs you are going to be working with in an array first rather than looping through them directly? Like

 currentlySelected = getCurrentSelection()
 
 for obj in currentlySelected do ( )
 

or


 for obj in objects do ( )
 
  1. Is it better to store the value of a spinner/checkbox in a global variable rather than accessing the rollout.checkbox.checked value directly?
 
 global chkbox1state = 0
 
 rollout rltMain "Main" (
    checkbox chk_box1 "Checkbox: " checked:chkbox1state
 
    on chk_box1 changed thestate do (
 	  chkbox1state = thestate
    )
 )
 
  (Option 1, accessing through the global variable) 
 fn isChecked = (
    if chkbox1state == 1 then 
 	  return 1
    else
 	  return 0
 )
 
 
   (Option 2, accessing directly) 
  fn isChecked = (
     if rltMain.chk_box1.checked == 1 then 
  	  return 1
     else
  	  return 0
  )
 

Obviously if you are accessing it directly you wouldn’t be using the global variable chkbox1state.

Are there any problems associated with accessing the property state directly?

  1. What is the best way to loop through all scene materials as well (even those not in the material editor)

Many thanks, hope to see some good discussion, I’m curious.
-Colin

4 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

There is a big difference – storing objects in an array creates a SNAPSHOT of the object collection, while looping directly through a selection, objects or geometry or helpers etc. collection uses the “live” scene.

Both are valid in the simplest case, but the moment you start CHANGING the scene, the first method becomes mandatory.

For example, if the operations you are performing in the loop would change the scene selection (for example by creating new objects), then FOR O IN SELECTION DO would fail miserably because SELECTION will change dynamically during the loop.
Similarly, FOR O IN OBJECTS DO would fail (either crash or miss some objects) if you are adding or deleting scene objects as the content of OBJECTS would change dynamically while you loop.

Thus, if you intend to do anything that would modify the object collection you are loopting through, create a snapshot of the collection in an array and then loop through it:

theSel = selection as array
for o in theSel do...
 rdg

Hi Colin,

1: I’d say: it depends on what you want to do with the objects.
Here is a discussion onthis topic:
http://forums.cgsociety.org/showthread.php?f=98&t=490666&highlight=loop

2: As it is recomended to store the rollout in a global variable I would access it through the rollout. This keeps your global scope somewhat tidy and clean.
http://forums.cgsociety.org/showthread.php?f=98&t=219175&highlight=rollout+global+destroydialog

3: You can use refs.dependents or getClassInstances – what ever fits best in your situation.
http://www.sloft.com/2005/11/26/maxscript-references/

Georg

Hi rdg or Bobo or anyone,

If its not too much trouble could you elaborate on when you would choose refs.dependents over getClassInstances for getting all bitmaps in a scene.

cheers

Dan


 bmaps = getClassInstances BitmapTexture
 
 for b in bmaps do (
    -- do something to the scene's bitmaps
 )
 

Thanks for digging up those links Georg and thanks for your input BoBo!

-Colin