Isotropix Forums

Object selection by shading group or assigned shader

General Discussion about Isotropix and CG related topics

Re: Object selection by shading group or assigned shader

Unread postby machieb » Thu May 14, 2020 6:29 pm

Hello,

there was a small error in your script. A friend of mine figured it out! He said that the sgList has to be cleared every time...
Now it works as expected! Thanks!

python code

sgName = "blackhole"

objList = []

objects = ix.api.OfObjectVector()
filter = "*"
type = "GeometryPolymesh"
ix.application.get_matching_objects(objects, filter, type)
for i in range (objects.get_count()):
sg = objects[i].get_module().get_geometry().get_shading_group_names()
sgList = []

for j in range(sg.get_count()):
sgList.append(sg[j])
if sgName in sgList:
obj = objects[i].get_full_name()
objList.append(obj)
group = ix.cmds.CreateObject(sgName + "_objs", "Group", "project://")
for obj in objList:
ix.cmds.AddValues([str(group) + ".inclusion_items"], [obj])
machieb
 
Posts: 24
Joined: Fri Nov 29, 2019 11:20 am

Re: Object selection by shading group or assigned shader

Unread postby machieb » Thu May 14, 2020 7:10 pm

With the help of a friend I expanded the script. I want so share it. Maybe someone needs it?

You select an object, run the script and a group is generated that contains all objects that have the same shading group name as the first selected object.

python code

sel = ix.selection[0]

sg = sel.get_module().get_geometry().get_shading_group_names()

sgList = []

for i in range(sg.get_count()):
sgList.append(sg[i])

print sgList

sgName = ''

if len(sgList) > 0:
sgName = sgList[0]

objList = []

objects = ix.api.OfObjectVector()

filter = "*"

type = "GeometryPolymesh"

ix.application.get_matching_objects(objects, filter, type)

for i in range (objects.get_count()):

sg = objects[i].get_module().get_geometry().get_shading_group_names()
sgList = []

for j in range(sg.get_count()):

sgList.append(sg[j])

if sgName in sgList:

obj = objects[i].get_full_name()

objList.append(obj)

group = ix.cmds.CreateObject(sgName + "_objs", "Group", "project://")

for obj in objList:

ix.cmds.AddValues([str(group) + ".inclusion_items"], [obj])
machieb
 
Posts: 24
Joined: Fri Nov 29, 2019 11:20 am

Re: Object selection by shading group or assigned shader

Unread postby dboude » Fri May 15, 2020 8:49 am

Haha yes, clearing the list of course !

Cool that it works properly now ;)
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1400
Joined: Mon Jul 03, 2017 10:51 am

Re: Object selection by shading group or assigned shader

Unread postby dcourtois » Fri May 15, 2020 4:28 pm

I edited your messages to add Python syntax highlighting. Makes things easier to read a prettier :)
User avatar
dcourtois
 
Posts: 72
Joined: Tue Jul 25, 2017 3:15 pm

Previous

Return to General Discussion
cron