-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a bug ? #1
Comments
Repeat the code for several times. There is about a 5% chance that an object cannot be displayed. The Z coordinate is - nan m |
Thanks for sharing your code! So the issue seems to be in the order of operations in your code. On Basically, there is a good chance that the reference to the location vector object will be invalid. Notice that I delete the object after using it in my example This also can be solved by making a copy of the location vector. So your code would look like this
|
thank you very much, I made a mistake :) |
import bpy
import bmesh
import random as rnd
def deleteall():
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False, confirm=False)
for m in bpy.data.materials:
bpy.data.materials.remove(m)
def RndColor():
return [rnd.uniform(0,1.0),rnd.uniform(0,1.0),rnd.uniform(0,1.0),1.0]
def SetMaterial(obj,color):
material = bpy.data.materials.new(name=f'rnd color material') # maybe repeated
material.use_nodes = True
#rnd_material.diffuse_color = RndColor()
#bpy.data.materials[rnd_material.name].node_tree.nodes["Emission"].inputs[0].default_value = (0.0441256, 0.57093, 1, 1)
material.node_tree.nodes["Principled BSDF"].inputs["Metallic"].default_value = rnd.uniform(0,1)
material.node_tree.nodes["Principled BSDF"].inputs["Roughness"].default_value = rnd.uniform(0,1)
material.node_tree.nodes["Principled BSDF"].inputs["Base Color"].default_value = color
obj.data.materials.append(material)
def go_1():
deleteall()
#----------------------------------------------------------------------------------------
if name == "main":
go_1()
The text was updated successfully, but these errors were encountered: