uhlik/bpy

Loading multiple point clouds into multiple objects

EODEFX opened this issue · 1 comments

Reading the documentation section on the API seems to only cover loading custom point clouds, rather than from ply files. I am attempting to register many point clouds together and it would be easier to load them all at once, rather than create object, navigate to ply file and add, change display %; for every ply file. Could you possibly add a way to do this, or describe how to automate this process. I can get it to the point were the objects are created and the PLY file is "attached" to each object, but they don't draw the clouds.

`import bpy
import bmesh

for i in range(18):
bpy.ops.mesh.primitive_plane_add(enter_editmode=False, location=(0, 0, 0))
bpy.context.object.name = "cloud." + str(i + 1).zfill(3)

o = bpy.context.object.point_cloud_visualizer
o.load.filepath = "D:\Scan Data\200794_SI\200764_SI." + str(i + 1) + ".ply"
o.display.percentage = 25`

uhlik commented

hi,
you can use helpers in add menu and import menu in latest version, they can load multiple files at once (assuming they are the same format), for drawing, erasing etc you can use 3d view header panel menu to execute on current, selected and all in scene.
with api, i only prepared that for drawing raw point data, not really for regular use, i don't see any issue with your code?
anyway, here is piece of script that will do it for you, you just need to set all file paths to a list

import os
import bpy

# make list of ply paths
ls = ["/points1.ply", "/points2.ply", "/points3.ply", ]

c = bpy.context.view_layer.active_layer_collection.collection
for p in ls:
    # derive empty name
    _, t = os.path.split(p)
    n, _ = os.path.splitext(t)
    # make empty
    e = bpy.data.objects.new(n, None, )
    # add to scene
    c.objects.link(e)
    pcv = e.point_cloud_visualizer
    # set filepath to ply
    pcv.load.filepath = p
    pcv.display.percentage = 25.0
    # # to also draw points, uncomment following lines
    # # set object active
    # e.select_set(True)
    # bpy.context.view_layer.objects.active = e
    # # run operator
    # bpy.ops.point_cloud_visualizer.mechanist_draw()