Guest User

Blender import PLY file with all attributes

a guest
Jan 9th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import bpy
  2. # clear all visible
  3. bpy.ops.object.select_all(action='SELECT')
  4. bpy.ops.object.delete(use_global=False)
  5.  
  6. # PLY file name
  7. name = "robot"
  8.  
  9. #impoprt PLY
  10. bpy.ops.wm.ply_import(
  11.     filepath="path-to-file/%s.ply" % name,
  12.     import_colors="LINEAR",
  13.     import_attributes=True
  14. )
  15. # doc:
  16. # https://docs.blender.org/api/current/bpy.ops.wm.html
  17.  
  18. # create the color attribute on the object's geometry
  19. bpy.ops.geometry.color_attribute_add(name="Color")
  20.  
  21. # store ref to mesh  
  22. mesh = bpy.data.objects[name]
  23.  
  24. #create geometry node
  25. geom_node = mesh.modifiers.new('geom_node',type='NODES')
  26.  
  27. #Create a pointer to the node tree
  28. tree = bpy.data.node_groups[0]
  29.  
  30. #Set that tree to your modifier
  31. mesh.modifiers['geom_node'].node_group = tree
  32.  
  33. #set the "Color" attribute as the output of the Geometry node
  34. geom_node["Socket_2_attribute_name"] = "Color"
Add Comment
Please, Sign In to add comment