XYZ data to point cloud

This script was initially created by Michael Auerswald and 908video.
I sligthly edited the script so it works with the latest version of C4D, which happen to be 2023.
Because the website which hosted the script before seems to be down and people were asking for it you are now here.

Download the python file here

What the script does
The script makes it possibe to import 3D point data into Cinema4d. If you try to import a pointdata only .obj file into c4d you will realize that this is not possible. C4D seems to not understand obj’s which only hold pointdata and ends up importing nothing nor giving the user a error message.

That is where the script comes into play. It reads out every line/point and stores it’s point position and color into an array which will be written into a polygon object inside Cinema4D.

To make this process work the obj file has to be in a specific format otherwise the script will crash. If the file is not in the right format, you can edit it with a text editor to make it work. A photogrammertry software like Agisoft Photoscan should give you the option to directly export your point data as a .txt file to have it as plain position and color data.

Format of the OBJ file
import c4d
from c4d import gui

# This path should point to your .OBJ file you want to read in.
pts_file = "c:\\points.obj"

# Main function
def main():
    doc = c4d.documents.GetActiveDocument()
    num_points = sum(1 for line in open(pts_file))
    print("Lines: " + str(num_points))
    new_obj = c4d.PolygonObject(num_points,0)
    vtx_color_tag = c4d.VertexColorTag(num_points)
    data = vtx_color_tag.GetDataAddressW()
    print (vtx_color_tag)
    print (data)
    points = new_obj.GetAllPoints()
    normals = new_obj.GetAllPoints()
    colors = new_obj.GetAllPoints()

    with open(pts_file,"r") as pts:
        idx = 0
        for line in pts:
            values = line.split(" ")
            points[idx] = c4d.Vector(float(values[0]),float(values[1]),float(values[2]))
            colors[idx] = c4d.Vector(float(values[3]),float(values[4]),float(values[5]))
            # Use this code line to convert integer RGB values to float values.
            # colors[idx] = c4d.Vector(float(values[3]/255.0,),float(values[4]/255.0,),float(values[5]/255.0,))
            c4d.VertexColorTag.SetColor(data, None, None, idx, colors[idx])
            idx += 1
        vtx_color_tag[c4d.ID_VERTEXCOLOR_DRAWPOINTS] = True

# Execute main()
if __name__=='__main__':

Share your thoughts