Community
VRED Forum
Welcome to Autodesk’s VRED Forums. Share your knowledge, ask questions, and explore popular VRED topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Vred Professional Python set materialids for all materials

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
Anonymous
3756 Views, 15 Replies

Vred Professional Python set materialids for all materials

Hello,

I have one important question:

With:

 

mat = findMaterial("a")
colorComponentData = vrFieldAccess(mat.fields().getFieldContainer('colorComponentData'))
colorComponentData.setUInt32("materialID", 5)

 

I can change the MaterialID of the material names a to 5.

I have got a scene with 120 different materials. How can I change the MaterialID of all these Materials

to 5?

How can I define for mat all Materials? Like mat = findMaterials(all) or (selected)?

 

Thank you very much for help!

Best

 

15 REPLIES 15
Message 2 of 16
sinje_thiedemann
in reply to: Anonymous

Hi,

 

how to loop over all materials:

 

mats = getAllMaterials()

for mat in mats:
    colorComponentData = vrFieldAccess(mat.fields().getFieldContainer('colorComponentData'))
    colorComponentData.setUInt32("materialID", 5)

 

Regards

Sinje

Message 3 of 16
Anonymous
in reply to: sinje_thiedemann

Hey,

thanks for your reply.

Unfortunately there is an error:

vrFieldAcces: fc pointer == NullFC!

Any idea?

Best

 

Message 4 of 16
sinje_thiedemann
in reply to: Anonymous

That's for materials that don't have the colorComponentData field, e.g. switch materials.

 

You can add a hasField() check:

 

mats = getAllMaterials()

for mat in mats:
    if mat.fields().hasField('colorComponentData'):
        colorComponentData = vrFieldAccess(mat.fields().getFieldContainer('colorComponentData'))
        colorComponentData.setUInt32("materialID", 5)
        print "set id for " + mat.getName()

 

Message 5 of 16
Anonymous
in reply to: sinje_thiedemann

THANK YOU SO MUTCH!

🙂

Message 6 of 16
Anonymous
in reply to: Anonymous

Hallo,

 

wie müsste man

 

mats = getAllMaterials()

for mat in mats:
    if mat.fields().hasField('colorComponentData'):
        colorComponentData = vrFieldAccess(mat.fields().getFieldContainer('colorComponentData'))
        colorComponentData.setUInt32("materialID", 0)
        print "set id for " + mat.getName()

ändern, damit nur die Materialids der Materialien ausgewählter Objekte verändert werden und damit bei jedem Durchlauf 1 addiert wird.
Ziel ist dann bei zum Beispiel 10 Objekten mit 10 Materialien die IDs 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 zu haben.
Wie wäre der Code um z.B. alle Materialids der Materialien ausgewähler Objekte auf 0 zu setzen?

Vielen Dank für eure Hilfe.

Viele Grüße

Stefan

Message 7 of 16
Anonymous
in reply to: Anonymous

Und eine weitere Frage, die uns auch noch auf den Fingernägeln brennt.

 

mats = getAllMaterials()

for mat in mats:
    if mat.fields().hasField('colorComponentData'):
        colorComponentData = vrFieldAccess(mat.fields().getFieldContainer('colorComponentData'))
        colorComponentData.setUInt32("materialID", 0)
        print "set id for " + mat.getName()

Funktioniert gut und alle IDs stehen dann auf 0 oder was auch immer man für einen Wert angibt. Allerdings wird das Ganze erst nach speichern und erneut öffnen im Viewport auch angezeigt. Gibt es noch einen Befehl bzw. eine Codezeile, die Vred und oder die Grafikkarte dazu zwingt zu aktualisieren? In der Praxis müssen wir schnell wieder alles auf 0 setzen und für andere Objekte neue Werte setzen. Dafür müssen wir jetzt oft speichern und wieder neu öffnen. Bei großer Datenmenge kann das ziemlich lange dauern. Hat jemand eine Idee?

Message 8 of 16
michael_nikelsky
in reply to: Anonymous

Hi,

 

wenn bei den ComponentSettings oder ComponentData etwas geändert wird muß man immer auch noch ein Feld des Materials ändern, damit er die Änderung erkennt. 

 

Viele Grüße

Michael



Michael Nikelsky
Sr. Principal Engineer
Message 9 of 16
sinje_thiedemann
in reply to: Anonymous

Hallo Stefan,

Materialien ausgewählter Objekte bekommst du über getSelectedNodes() (siehe vrScenegraph in der Python-Doku) und node.getMaterial() (siehe vrNodePtr).

Viele Grüße

Sinje

Message 10 of 16
Anonymous
in reply to: sinje_thiedemann

Hallo zusammen,

 

mit:

 

mats = getAllMaterials()

for mat in mats:
    if mat.fields().hasField('colorComponentData'):
        colorComponentData = vrFieldAccess(mat.fields().getFieldContainer('colorComponentData'))
        colorComponentData.setUInt32("materialID", 0)
        print "set id for " + mat.getName()

 

setze ich alle Materialids auf 0 oder 1 oder auf was auch immer ich möchte.

Checke ich die Materialien, so sind alle Materialids danach geändert. Gucke ich mir den Renderpass MaterialID an, so ist die Ansicht noch nicht

aktualisiert und alle Materials werden noch so angezeigt wie vorher - bis ich die Szene abspeicher und neu öffne. Dann stimmt auch alles an der

Ansicht. Gibt es einen Befehl, mit dem ich die Aktualisierung erzwinge, ohne speichern und neu öffnen zu müssen?

Freue mich über eine Antwort.

Viele Grüße

Stefan

 

Message 11 of 16
michael_nikelsky
in reply to: Anonymous

Hallo,

 

die Material Id ist in den ColorComponentData, daher bekommt das Material selbst nichts davon mit, daß sich dort etwas geändert hat und updated sich nicht. Damit das Material selbst die Änderung mitbekommt muß dort ebenfalls eine Änderung erfolgen. Das einfachste ist irgendein Feld des Materials wieder auf den Wert zu setzen den es bereits hat. Im Script bieten sich dafür die Analytic* Felder an, da die in jedem Truelight Material vorhanden sind.

 

Viele Grüße

Michael



Michael Nikelsky
Sr. Principal Engineer
Message 12 of 16
Anonymous
in reply to: michael_nikelsky

Hallo Michael,

vielen Dank für dien schnelle Antwort.

Könntest du mir noch kurz aufzeigen, wie du das Script dafür erweitern würdest, bitte?

Lg

Message 13 of 16
michael_nikelsky
in reply to: Anonymous

Einfach so:

 

mats = getAllMaterials()

for mat in mats:
    if mat.fields().hasField('colorComponentData'):
        colorComponentData = vrFieldAccess(mat.fields().getFieldContainer('colorComponentData'))
        colorComponentData.setUInt32("materialID", 5)
        mat.fields().setUInt32("flags", mat.fields().getUInt32("flags"))
        print "set id for " + mat.getName()

Viele Grüße

Michael



Michael Nikelsky
Sr. Principal Engineer
Message 14 of 16
Anonymous
in reply to: michael_nikelsky

Thank you ver much!
Message 15 of 16
jeremy.beauchamp
in reply to: Anonymous

I used this script and its helpful if you have a material libarary that gets used over and over. That way paint, plastics, glass etc always have the same RGB channels. 

 

I've been doing a lot of compositing using RGB MATID's and I was wondering if its possible to setup multiple MATID passes in a single file and add only RGB channels to it. I typically have 8-10 MATID passes and I'm having to save a file for every RGB MATID pass. 

Thanks,

Jeremy

Message 16 of 16
Anonymous
in reply to: michael_nikelsky

Hello Michel, am I trying here, how could I get only the mateira that are inside the folder in the Asset Manager menu?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report