Notifications
Clear all

[Closed] Subobject selections in objectsets?

Hey there,
I wrote a script that selects elements of objects based on their size (I convert an element to an object and take then that object’s distance from its midpoint to its .max value). It is working nicely except of one aspect that I just cannot get to work. Might be something easy I am missing:

The script should work on multiple selected objects with instanced edit_mesh or edit_poly modifiers as well. How could I manage that? The problem is, for example, if I have a small and large teapot with an instanced edit_mesh/poly modifier selected, the teapots have the same face numeration, I believe. So if I save the faces of the small teapot's handle as bitarry, and then select that array, the larger teapot's handle will be selected as well, even though that element is above the size threshold.


So I guess my question is: how do I set specific face selections in an objecset where all objects in that set have the same, instanced edit_poly edit_mesh modifier?
8 Replies

Lets make this simpler:

I have a couple of objects selected, all with the same instanced edit_poly modifier. The max interface lets me select faces of all objects at once. How do I do the same thing with mxs?

The MacroRecorder would return after selecting a bunch of random faces within my objectselection:
$.modifiers[#Edit_Poly].SetSelection #Face #{} node:$Teapot01
$.modifiers[#Edit_Poly].Select #Face #{1…512} node:$Teapot03

But if I execute the same code, I get an error:
– Unknown property: “modifiers” in $selection

What am I missing here?

thanx

Hi Lena,
I’m trying to understand your problem. I’ve given a try to the following code. It creates two Teapots, an Edit_Poly modifier and assign it to both. Then sets a Face Selection on one of them.

(
    oTeapot01 = Teapot pos:[30, -30, 0] wireColor:green
    oTeapot02 = Teapot pos:[-30, 30, 0] wireColor:blue

    epMod = Edit_Poly()

    addModifier oTeapot01 epMod
    addModifier oTeapot02 epMod

    max modify mode
    modPanel.setCurrentObject epMod

    select oTeapot01
    subObjectLevel = 4

    epMod.select #Face #{257..320} node:oTeapot01
)

I guess the error you’re getting means it searches for modifiers in “selection” or “$” which is a collection of objects, and it doesn’t exist. Edit_Poly modifier you’re looking for is instanced through each object so you can get its reference from any object. In other words, your code should look like:

(
    -- assuming first selected object shares the Edit_Poly modifier

    local epMod = selection[1].modifiers[#Edit_Poly]
    -- if you want to get the modifier by name

    -- or

    local epMod = selection[1].modifiers[1]
    -- if you want to get the modifier by stack index,
    -- assuming Edit_Poly is the first modifier

    -- or

    local epMod = modPanel.getCurrentObject
    -- if you want to get the currently active modifier in the stack
    
    -- and then

    epMod.SetSelection #Face #{} node:$Teapot01
    epMod.Select #Face #{1..512} node:$Teapot03
)

Mind that you need to be in Polygon SubObjectLevel to make the selection work. I hope this helps.

  • Enrico

Easiest way to deal with multi-selections is to set the object to the first item in the selection. Try this intsead:

selection[1].modifiers[#Edit_Poly].SetSelection #Face #{} node:$Teapot01
selection[1].modifiers[#Edit_Poly].Select #Face #{1…512} node:$Teapot03
-Eric

Edit: Which SyncViewS already showed.

Hi,
thanks for your patience with me. I indeed was afraid that part of the problem was the insufficient description of my problem :-).

I finally got all sorted out for the Edit_Poly modifier. Thanks! I guess, I got really confused with all the different mesh/poly operations.

And now I should make the same thing work for the Edit_mesh modifier. Any suggestions on that?

Ok, one more thing with this:

          How do I set a face selection within a edit_mesh modifier? 
          
          E.g.
          (A standard teapot with an edit_mesh modifier)

      subobjectLevel = 4
      select $Teapot01.faces[#{1..512}]
    
          Executing this does end up looking like as if the faces are selected in the view port, but I can't actually do anything with that selection, can't move the faces or anything. The same command works nicely if I convert the teapot into a editable mesh.
          
          Any suggestions?

Hi Lena,
to set a face selection in an Edit_Mesh modifier, you need to specify node and modifier:

(
    -- get first selected object, like a Teapot with an Edit_Mesh Modifier
    local obj = selection[1]

    -- assuming first selected object shares the Edit_Mesh modifier
    
    local emMod = selection[1].modifiers[#Edit_Mesh]
    -- if you want to get the modifier by name
    
    -- or
    
    local emMod = selection[1].modifiers[1]
    -- if you want to get the modifier by stack index,
    -- assuming Edit_Mesh is the first modifier
    
    -- or
    
    local emMod = modPanel.getCurrentObject
    -- if you want to get the currently active modifier in the stack
    
    -- and then

    max modify mode
    modPanel.setCurrentObject emMod
    subObjectLevel = 4

    setFaceSelection obj emMod #{1..512}
)
  • Enrico

gee, this is slightly embarissing… I did try exactly your code first, but it didn’t work because I only used “setFaceSelection obj #{1…512}” instead of “setFaceSelection obj emMod #{1…512}”.

Thanks for explaining the same thing twice to me…

Well, it’s quite tricky, I made that mistake too, nothing to feel embarrassed about. Mind you can specify modifier index in place of modifier reference:

-- assuming Edit_Mesh is the first modifier
setFaceSelection obj 1 #{1..512}
  • Enrico