Can't color point clouds after applying python script

Hi,
I run a short python script to split a large point cloud into two point clouds using a surface. After the large point cloud is split, i then make each individual point cloud a different color.
This worked in Rhino6, but for some reason it doesn’t work in Rhino8. In Rhino8, after running the script, the points in the point cloud just remain black no matter what color i apply to them. I even tried doing “Explode” and then “Create Point Cloud” to try to reset the point clouds to get them to accept a color. Not sure why that didn’t work.
Any ideas? Thanks in advance.
Here’s my sort python script:

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs

def test():

ptId = rs.GetObject("Select the point cloud",2, preselect=True)
if not ptId:return

srfId = rs.GetObject("Select the surface",8, preselect=True)
if not srfId:return

face = sc.doc.Objects.Find(srfId).Geometry.Faces[0]
srf = face.ToNurbsSurface()
ptCl = sc.doc.Objects.Find(ptId).Geometry

PC1 = Rhino.Geometry.PointCloud()
PC2 = Rhino.Geometry.PointCloud()
n = 0
m = 0

for item in ptCl:
    pt = item.Location
    color = item.Color
    par = srf.ClosestPoint(pt)
    
    vecNorm = srf.NormalAt(par[1], par[2])
    srfPt = srf.PointAt(par[1], par[2])
    
    vecDir = pt-srfPt
    vecDir.Unitize()
    
    vecDir.IsParallelTo(vecNorm)
    if vecDir.IsParallelTo(vecNorm) == -1:
        PC1.Add(pt, color)
        n = n + 1
    else:
        PC2.Add(pt, color)
        m = m + 1

if n>0: sc.doc.Objects.AddPointCloud(PC1)
if m>0: sc.doc.Objects.AddPointCloud(PC2)

sc.doc.Objects.Delete(ptId, False)
pass

if name == “main”:
test()

Your code didn’t run for me, so I edited it like this:

import Rhino
import scriptcontext as sc
import rhinoscriptsyntax as rs

ptId = rs.GetObject("Select the point cloud",2, preselect=True)

srfId = rs.GetObject("Select the surface",8, preselect=True)

face = sc.doc.Objects.Find(srfId).Geometry.Faces[0]
srf = face.ToNurbsSurface()
ptCl = sc.doc.Objects.Find(ptId).Geometry

PC1 = Rhino.Geometry.PointCloud()
PC2 = Rhino.Geometry.PointCloud()
n = 0
m = 0

for item in ptCl:
    pt = item.Location
    color = item.Color
    par = srf.ClosestPoint(pt)
    
    vecNorm = srf.NormalAt(par[1], par[2])
    srfPt = srf.PointAt(par[1], par[2])
    
    vecDir = pt-srfPt
    vecDir.Unitize()
    
    vecDir.IsParallelTo(vecNorm)
    if vecDir.IsParallelTo(vecNorm) == -1:
        PC1.Add(pt, color)
        n = n + 1
    else:
        PC2.Add(pt, color)
        m = m + 1

if n>0: sc.doc.Objects.AddPointCloud(PC1)
if m>0: sc.doc.Objects.AddPointCloud(PC2)

This do works here. What is your Rhino 8 version service release?

Can you attach the geometries (point cloud and surface) that do not work for you?

Thank you Riccardo. I have Rhino8 Version 8 SR14
(8.14.24345.15001, 2024-12-10)
I tried your script and it ran just fine and it successfully divided the point cloud into two. But for some reason the two point clouds are black and they stay black no matter what color i apply to them. I’m not sure what’s happening.
I have found that if I do “Explode” and then copy the points into another Layer, and then go into the Object Properties, i find that the Display Color is set on “Custom”. If i manually change the Display Color to “By Layer” then i am able to color the points.
I’m not sure why the color of the points gets set on “Custom”.
Here’s the point cloud i’m using.
80_points.txt (2.1 KB)
And i used a surface in Rhino that cuts the point cloud about in half.
Many thanks for your insights. I think i’m about halfway there.

Try using rs.ObjectColor() after creating the point clouds to explicitly set their colors and make sure the DisplayColor attribute for point clouds is set correctly. If that doesn’t work, you might want to check if any Rhino 8 updates have affected point cloud rendering.