Create model set from selection - with same name

Started by TVC-15, September 10, 2020, 07:57:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TVC-15

When I right-click a group I can 'Create model set from selection', I'd like a script to do this, but automatically name the model set with the same name as the group.
I'm new to python and trying to figure it out but would appreciate some help with what looks to be a couple lines of code.
Ultimately I'd try to write a script would take all the groups in the Default model set and put them into separate model sets automatically.

Rigg3d

Hi, I came to the forums to try and find a solution for something similar to this... but couldn't find anything.
I need a script to create a new model set for each piece of selected geometry (I work with a lot of different variants). Below you'll find my take on the script I need - please adjust to your needs.
It's important to note this is my 2nd ever script (1st in keyshot) and is janky as hell so you have to follow some criteria for it to work:
1. All selected nodes have to be from the "Default" model set and a direct child of it. Any further levels down and it won't work.
2. All selected geometry should have a different name.

I can't seem to find a command to delete extra geometry (or just transfer needed geometry to the new model set to begin with) - so unwanted nodes are only hidden in the new model sets. I don't know if anyone knows anything about this?

Lastly, if anyone in the community that knows Python wants to give me a few tips on the below code to help me get better it'd be much appreciated  :)



def main():
    objName = []
    objHidden = []
    objLocked = []
    root = lux.getSceneTree()
    dSet = root.find(name = "Default", types = lux.NODE_TYPE_MODEL_SET)

    #identify and store selected nodes.
    for n in root.find():
        if n != root:
            if n.isSelected():
                objName.append(n.getName())

    #unlock and unhide all direct children of default model set (and store settings).
    for ds in dSet:
        for d in ds.getChildren():
            objHidden.append(d.isHidden())
            objLocked.append(d.isLocked())
            d.unlock()
            d.show()

    #create new model sets.
    for n in objName:
        lux.newModelSet(n)
       
    #hide unwanted nodes in newly created model sets.
    mSet = root.find(types = lux.NODE_TYPE_MODEL_SET)
    for ms in mSet:
        for m in ms.getChildren():
            if ms.getName() == m.getName():
                 print(ms.getName())
            if ms.getName() != m.getName():
                m.hide()

    #return default model set to previous state.
    i = 0
    for ds in dSet:
        for d in ds.getChildren():
            if objHidden[i] == True:
                d.hide()
            else:
                d.show()
            if objLocked[i] == True:
                d.lock()
            else:
                d.unlock()

            i += 1
           
        print("...successfully created")

main()