C++ code is rewritten as python code

Hello everyone! I have a piece of C++ code that I want to change to python code, I am new to Rhino.python, Can someone tell me how to rewrite it? Thanks!

//Joann

cf2830b2abe103c193ee8f79f9b6d45

Top post! or can someone tell me some tips(C++ code is rewritten as python code)

take a look here: https://developer.rhino3d.com/api/RhinoScriptSyntax/
many rhino common functionalities are already wrapped inside the script syntax. look below for an example on how to select many objects with filter.

import rhinoscriptsyntax as rs

objs = rs.GetObjects("Get Points", 1+2)

should give you a list of points or point sets.

Thanks! rgr I will try to learn to write !

Hi @15951991225,

How about this?

import Rhino

def test_joann():
    filter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.PointSet
    go = Rhino.Input.Custom.GetObject()
    go.GeometryFilter = filter
    go.GetMultiple(1, 0)
    if go.CommandResult() != Rhino.Commands.Result.Success:
        return False
    
    count = 0
    for objref in go.Objects():
        geometry = objref.Geometry()
        if isinstance(geometry, Rhino.Geometry.Point):
            count += 1
        elif isinstance(geometry, Rhino.Geometry.PointCloud):
            count += geometry.Count
    
    print("Total points: {}".format(count))
    return True
    
test_joann()

– Dale

Thanks! Dale This is very useful to me!

//Joann

@Dale

I rewritten this piece of code

but I do not know how to assign the coordinates of the pointcloud

798360b780298933f377da49e817370

Can you give me some advice? Thank you!

//Joann

You should use Pointcloud.Getpoints first and the iterate over the points.

hello Gijs! I know the logic. but …14262694d02ce0f1adf20ec7fb22072

Sorry : Check your capitals:
GetPoints

ok , Thank you! Gijs