Place Coordinate value as a point in rhino file with incrementing number/string

Dear All,

I wrote a small script in python to place points with incrementing values in a rhino drawing.
Problems occur when I try to loop the while statement and try to increment the variable.

I wrote some comments in the python script:
Place-Point-ID.py (944 Bytes)

Thank you for your time.

Kind Regards,

Jaap Bijlstra

Here is some sample code with comments - post back if there is anything you don’t understand:

import rhinoscriptsyntax as rs

def placepoint():
    #loop pointcreate with name
    #Use an integer for nValue, not a string if you are going to increment
    nValue=rs.GetInteger("Starting Value")
    if nValue is None: return
    
    #define plane outside loop
    #Plane_loop= rs.WorldXYPlane()
    Plane_move= rs.WorldXYPlane()
    
    while True:
        #nValue=nLoop
        point_create=rs.GetPoint("Add Point")
        if point_create is not None: #this is a correct statement
            #could also be simply if point_create:
            pnt = rs.AddPoint(point_create)
            #print pnt
            #Plane_move= rs.MovePlane(Plane_loop,point_create)
            #can also do this like the following:
            Plane_move.Origin=point_create
            #convert integer to string for text
            rs.ObjectName(pnt,str(nValue))
            rs.AddText(str(nValue),Plane_move,300)
            #Increment one number,didn't succeed?
            #as you originally defined it nValue is a string
            #you can't increment a string!
            #Use an integer instead and increment it in the loop
            nValue+=1
        else: 
            #is it necessary to make bLoop Global? - No.
            #just break out of the loop with break
            break

# call the function defined above
placepoint()

Thank you for the remarks about the python code. It is better to wrap more code in the definition I guess. I just added a string prefix to the .ObjectName and .Addtext and I got no errors in the string concatenation.
The ‘nValue+=1’ looks weird for me but that is how Python reads the code I think.

Regards,

Jaap

import rhinoscriptsyntax as rs


#loop pointcreate with name 


def placepoint():
    nValue=rs.GetInteger("Starting Value")
    if nValue is None: return
    Plane_move= rs.WorldXYPlane()
    String_prefix=rs.GetString("Please enter Prefix")
    while True:
        point_create=rs.GetPoint("Add Point")
        if point_create is not None:  
            pnt = rs.AddPoint(point_create)
            Plane_move.Origin=point_create
            rs.ObjectName(pnt,String_prefix+str(nValue))
            rs.AddText(String_prefix+str(nValue),Plane_move,300)
            nValue+=1 # Increment one number 
        else: 
            break




if __name__ == "__main__":
    # call the function defined above
    placepoint()

Yes, n+=1 looks strange, it’s python shorthand for n=n+1 You can also do -=, *= etc.

ahh okay. Thank you for your explanation!