Isotropix Forums

Object selection by shading group or assigned shader

General Discussion about Isotropix and CG related topics

Object selection by shading group or assigned shader

Unread postby machieb » Mon May 11, 2020 4:04 pm

Hello,

is it somehow possible to select all objects in a clarisse scene, that have the same shading group, or a specific shader assigned to them? Maybe with a python script? Or can I filter in the group to only include objects with a specific shading group?

What I try to do:
I import an alembic as reference into clarisse, the shading groups have been assigned before in a dcc package.
For example I have a 3D car and I want to select all parts, that have the shading group called carpaint, to put those parts into a clarisse-group.
I want to put them in a group because I want to render the carpaint parts with different lighting and reflections.

Greetings Marcus
machieb
 
Posts: 24
Joined: Fri Nov 29, 2019 11:20 am

Re: Object selection by shading group or assigned shader

Unread postby dboude » Mon May 11, 2020 5:29 pm

Hi,

Yes, you can achieve that with a script.

Cheers
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 machieb » Mon May 11, 2020 8:39 pm

Thank you for your quick answer!
Can you please give me some more informations, because I´m not familiar with python scripting.
I would select an object, then run the script and then every other object with the same shading group gets selected. Is that a complex script? Are there informations in the Clarisse manual how to read the shading group via python?

I hope someone can help! Thanks Marcus
machieb
 
Posts: 24
Joined: Fri Nov 29, 2019 11:20 am

Re: Object selection by shading group or assigned shader

Unread postby dboude » Mon May 11, 2020 9:46 pm

Here is a little snippet listing all the shading groups of the selected geometry

Code: Select all
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


Cheers
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 machieb » Mon May 11, 2020 10:36 pm

Thank you very much,

I will try to figure out the rest!

Cheers
machieb
 
Posts: 24
Joined: Fri Nov 29, 2019 11:20 am

Re: Object selection by shading group or assigned shader

Unread postby machieb » Wed May 13, 2020 9:55 am

Hello,

it´s a very hard nut to crack for me! :D
How can I select an objects via script if I know their shadinggroup?
Do you have a snippet for that?

Thanks and cheers
machieb
 
Posts: 24
Joined: Fri Nov 29, 2019 11:20 am

Re: Object selection by shading group or assigned shader

Unread postby dboude » Wed May 13, 2020 3:39 pm

Set the shading group name you want and run the script. It will create a group at the root level with the objects having this shading group.

Code: Select all
sgName = "Reactor"

sgList = []
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()
    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])


Cheers
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 machieb » Wed May 13, 2020 10:11 pm

Thank you very much, but the script is not working. It is creating a group, but the group contains objects with different shading group names. See attachment.
I wrote "blackhole" as the name of the shading group in your script.
As you see in the group there are parts that have carpaint, glass etc.
Do you have a clue?

Cheers
Attachments
Shading_group_selektion3.jpg
machieb
 
Posts: 24
Joined: Fri Nov 29, 2019 11:20 am

Re: Object selection by shading group or assigned shader

Unread postby dboude » Thu May 14, 2020 10:15 am

Hi,

If an object has several shading groups and one of them matches the name given in the script, the object will be gathered. Could you share your asset please ?

Thanks
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 machieb » Thu May 14, 2020 3:57 pm

Hello,

yes you are right, on the car geometry in my screenshots are some objects, that have more than one shading group per object.
But there were objects that had another shading group name also added to the group! I can´t share the car with you because I can only load 5mb files here. But I share one other asset (motorcycle mirrors) from a project with you. It has only one shadinggroup per object. But the script is not working with it. I don´t know why?

I created a simple geometry file (*.abc) with five boxes. One box has more shading groups. If I use your script here and use "Material" as shading group name it works. It the two boxes that have this shading group name in a clarisse group.
Here the script works as you mentioned!
Attachments
Box_with_shading_groups.zip
(3.28 KiB) Downloaded 5 times
SZ_ID059_Spiegel_2_tone_black.zip
(935.52 KiB) Downloaded 11 times
machieb
 
Posts: 24
Joined: Fri Nov 29, 2019 11:20 am

Next

Return to General Discussion