Fundamentals. Help. Rhinoscriptsyntax in Python. Object's ID from geometry

If i have an object of type ‘Point3d’ returned by a function. e.g.:
rs.DivideCurve(curve_id, 10)
How can i get it’s GUID?
Thank You

You can’t. The Point3D objects that are the result of DivideCurve() are just “virtual” point objects, they are not added to the document as Rhino objects. If you want to add the point objects to the document and get their IDs, you can then use rs.AddPoints():

div_pts=rs.DivideCurve(curve_id,10)
point_ids=rs.AddPoints(div_pts)
1 Like

Thanks!
Should I always use add*** function for different types of objects? Isn’t there a generic function to get GUID of any geometry object?

There are two types of things that you are confusing here - one is virtual geometry objects like point3d’s, which don’t actually exist in the document, the other is Rhino objects which do exist in the document. Only objects which exist in a document have GUID’s. Virtual geometry must be kept track of by storing them in a variable until needed.

Most rhinoscriptsyntax methods actually take object id’s as input - i.e. they work with objects that already exist in the document - and they automatically add any resulting new objects to the document and return their id’s.

However, not all the methods do this - for example your rs.DivideCurve() does not automatically add points to the document - so you need to see what your particular method returns and adapt your script to that.

1 Like

I have this code:

import rhinoscriptsyntax as rs
curve_id = rs.GetObjects(“Select a curve”, 4)
points=rs.DivideCurve(curve_id, 10, True)
rs.EditBox(str(type(points[0])))

It creates a list of objects <type ‘Point3d’> and actually does create the points in the document (see image)
On the other hand. If i write DivideCurve() method with “False” parameter: points=rs.DivideCurve(curve_id, 10, False)
Then it does not create points in the document. But the objects are still <type ‘Point3d’>

My question is: is there a way to find out wether objects in the list were instanced in the rhino document or not from within python? Since both created ones and virtual ones have the same type. And if they were created, is there a way to get their GUID?

OK, this is an odd one actually… You have specified the “CreatePoints” argument as True, so the points are created. This option was added at some point - I don’t remember when actually - but apparently they didn’t do a very complete job. So the points are added, but there is no way to get the method to return the point object ID’s. Even rs.LastCreatedObjects() does not work to get them.

So I am at a loss as to how to get the points ID’s in an easy way… There is a sort of neanderthal way I can think of:

import rhinoscriptsyntax as rs
curve_id = rs.GetObjects("Select a curve", 4)
count=10
points=rs.DivideCurve(curve_id, count,True)

point_ids=[]
obj=rs.FirstObject()
for i in range(count+1):
    point_ids.append(obj)
    obj=rs.NextObject(obj)
rs.SelectObjects(point_ids)

Basically it knows how many points you created with the variable count, (Divide creates count+1 points) then it steps backwards through the file that many objects getting each ones ID… :confused:

But it does seem in this case that the method is incompletely programmed…

@dale?

1 Like

@Alain, can you look at this?

– Dale

The relevant part of the method from curve.py is this:

image

So you can see that the points are added, but the ID’s are not referenced or returned…

Hi,
The function could be modified to return IDs when adding the point. I think it was made to work like the RhinoScript version which also doesn’t return IDs.
Does Mitch’s suggestion:

div_pts=rs.DivideCurve(curve_id,10)
point_ids=rs.AddPoints(div_pts)

work for you?
Alain

1 Like

Works fine. Thank You, guys.

Well, I think that it would be good if the method could return the point object ID’s if it adds them to the document.

@Helvetosaur @Alain
I have one more question. More a theoretical one. What is the connection between virtual objects and instanced in the rhino document ones? Is there some kind of an ID of a virtual object that is connected to an instanced object?
If I have a virtual object and then create instances of that object in rhino multiple times, I wouldn’t get duplicate objects, right?

e.g.:
curve_id = rs.GetObjects(“Select a curve”, 4)
points=rs.DivideCurve(curve_id, 10,True)
point_ids=rs.AddPoints(points)

“DivideCurve” with “True” parameter creates points in Rhino document, but after that
“AddPoints(points)” does not create more points in rhino document
However
“DivideCurve” with “False” parameter does not create points in Rhino document, just virtual points
“AddPoints(points)” does create points in Rhino document.
Where can I read more about this in depth?

There isn’t really. Virtual geometry is only stored as bits and bytes in memory, and when the script ends it is deleted and the memory space freed. Only when you actually add the objects to the document do you get an ID you can track. Otherwise, with virtual geometry, you keep track of it during the script because it is referenced in a variable. Your variable “points” contains a list of 3d points which can be reused somewhere else in the script - notably on the next line where you use AddPoints(points) to add the point objects to the document.

Yes, you will.

import rhinoscriptsyntax as rs
curve_id = rs.GetObjects(“Select a curve”, 4)
points=rs.DivideCurve(curve_id, 10,True)
point_ids=rs.AddPoints(points)

If you run that and then do a SelDup in Rhino you will see that you have duplicate points.

It does.

Correct.

Correct.

I guess the best is to start here: https://developer.rhino3d.com/guides/rhinopython/

1 Like

Hey Mitch, I agree that it seems like the logical thing to do. One concern is that changing the API would break existing scripts.
Logged here.

If you add an extra optional argument at the end it might not…

DivideCurve(curve_id, segments, create_points=False, return_points=True, return_ids=False)

if create_points, return_points and return_ids are all True, it returns ids. Otherwise it runs as it does today.

Sure, the function signature signature becomes pretty messy in my opinion but it would work.
Cheers