Python Set object Material Help

Discussion related to the LuxCore functionality, implementations and API.
Post Reply
User avatar
MentalArray
Posts: 6
Joined: Thu Sep 24, 2020 3:52 pm

Python Set object Material Help

Post by MentalArray »

Hi so im wanting to this in this order
  • Add a new material
    Set material to an existing object
    Remove old material from scene
i did find this code but its not the same in the fact that it changes a current material

Code: Select all

# Begin scene editing
		self.session.BeginSceneEdit()

		# Edit the material
		self.scene.Parse(pyluxcore.Properties().
			Set(pyluxcore.Property("scene.materials.shell.type", ["mirror"])).
			Set(pyluxcore.Property("scene.materials.shell.kr", [0.75, 0.75, 0.75])))
		# To remove unreferenced constant textures defined implicitely
		self.scene.RemoveUnusedTextures()
		# To remove all unreferenced image maps (note: the order of call does matter)
		self.scene.RemoveUnusedImageMaps()
		
		# End scene editing
		self.session.EndSceneEdit()
i have been trying to use the command
UpdateObjectMaterial()
but getting error RuntimeError : Unknown object in Scene::UpdateObjectMaterial():
what should i be passing as the object name if i have an object described below

Code: Select all

scene.objects.27342762485360.material = "BlankMat00012419016618936"
scene.objects.27342762485360.ply = scenes/Fracball_LuxCore/Ball.ply
scene.objects.27342762485360.camerainvisible = 0
scene.objects.27342762485360.id = 1795813475
scene.objects.27342762485360.appliedtransformation = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
thank you for any help in advance
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Python Set object Material Help

Post by Dade »

MentalArray wrote: Sat Oct 03, 2020 12:19 pm i have been trying to use the command
UpdateObjectMaterial()
but getting error RuntimeError : Unknown object in Scene::UpdateObjectMaterial():
what should i be passing as the object name if i have an object described below

Code: Select all

scene.objects.27342762485360.material = "BlankMat00012419016618936"
scene.objects.27342762485360.ply = scenes/Fracball_LuxCore/Ball.ply
scene.objects.27342762485360.camerainvisible = 0
scene.objects.27342762485360.id = 1795813475
scene.objects.27342762485360.appliedtransformation = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
"27342762485360" is the object name to pass to Scene::UpdateObjectMaterial() (what were you using ?).

P.S. like the material name is "shell" in your code fragment.
Support LuxCoreRender project with salts and bounties
User avatar
MentalArray
Posts: 6
Joined: Thu Sep 24, 2020 3:52 pm

Re: Python Set object Material Help

Post by MentalArray »

hi yes i did use that and i used the mat name and get the error material now :(
this is running in c# python net 3.7

Code: Select all

 
 session.BeginSceneEdit();
 	//this line adds the material correctly
        sceneProps.SetFromString("scene.materials.whitematte.type = matte" + Environment.NewLine +
        "scene.materials.whitematte.kd = 0.75 0.0 0.0" + Environment.NewLine +
        "scene.materials.whitematte.id = 10101010");
        
        //this line throws the error (Python.Runtime.PythonException: 'RuntimeError : Unknown material in  Scene::UpdateObjectMaterial(): whitematte')
        
          scene.UpdateObjectMaterial("27342762485360", "whitematte");
                                    
session.EndSceneEdit();
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Python Set object Material Help

Post by Dade »

MentalArray wrote: Sat Oct 03, 2020 3:53 pm hi yes i did use that and i used the mat name and get the error material now :(
this is running in c# python net 3.7

Code: Select all

 
 session.BeginSceneEdit();
 	//this line adds the material correctly
        sceneProps.SetFromString("scene.materials.whitematte.type = matte" + Environment.NewLine +
        "scene.materials.whitematte.kd = 0.75 0.0 0.0" + Environment.NewLine +
        "scene.materials.whitematte.id = 10101010");
        
        //this line throws the error (Python.Runtime.PythonException: 'RuntimeError : Unknown material in  Scene::UpdateObjectMaterial(): whitematte')
        
          scene.UpdateObjectMaterial("27342762485360", "whitematte");
                                    
session.EndSceneEdit();
Did you forget to post some line of code code ? You are not parsing the sceneProps. It should be something like:

Code: Select all

 
session.BeginSceneEdit();
        sceneProps.SetFromString("scene.materials.whitematte.type = matte" + Environment.NewLine +
        "scene.materials.whitematte.kd = 0.75 0.0 0.0" + Environment.NewLine +
        "scene.materials.whitematte.id = 10101010" + Environment.NewLine);
        
        // MISSING THIS:
	scene.Parse(sceneProps)	
        
         scene.UpdateObjectMaterial("27342762485360", "whitematte"); 
session.EndSceneEdit();
You are also missing a "+ Environment.NewLine" from the last "scene.materials.whitematte.id" property (but as far as I remember this shouldn't be a problem anymore).
Support LuxCoreRender project with salts and bounties
User avatar
MentalArray
Posts: 6
Joined: Thu Sep 24, 2020 3:52 pm

Re: Python Set object Material Help

Post by MentalArray »

yes i have tried that latest code

Code: Select all

session.BeginSceneEdit();
                                    sceneProps.SetFromString("scene.materials.whitematte.type = matte" + Environment.NewLine +
                                    "scene.materials.whitematte.kd = 0.75 0.0 0.0" + Environment.NewLine +
                                    "scene.materials.whitematte.id = 10101010" + Environment.NewLine);
                                   
                                    scene.Parse(sceneProps);
                                    scene.UpdateObjectMaterial("27342762485360", "whitematte");
                                    session.EndSceneEdit();
umm still get error :(
Python.Runtime.PythonException: 'RuntimeError : Unknown material in Scene::UpdateObjectMaterial(): whitematte'
User avatar
MentalArray
Posts: 6
Joined: Thu Sep 24, 2020 3:52 pm

Re: Python Set object Material Help

Post by MentalArray »

ok got it working finally :)
just needed to add

Code: Select all

scene.Parse(pyluxcore.Properties(sceneProps));
and it worked....
Post Reply