Set Point of Curves Using Python Script

I would like to set preselected all curves at a specified point’s X value. I was trying to develop a python script.

id = rs.GetObject("Select Objects", filter = 1,  preselect = True, select = False, custom_filter = None)
rs.Command("!_SetPt")

However, after trying this I get a prompt box to select SetX, SetY or SetZ. How to pick up an option from the list using python? Could you please help with this?

Hi
If your script the hyphened command " !_-SetPt " you can create a macro for the options

eg:
“!_-SetPt X=Yes Y=No Z=No w0,0,0 _Enter”

Does this help?
-Willem

1 Like

This is really nice and helpful. But one problem I face is that I need to change the x value in the code to set points from time to time since I have to set points at different x values.

So, I prefer the command that asks me to select the point/ curve which x value I would like to use.

If you want to set a point’s coordinate directly, you can address each coordinate (X, Y, Z) of a point separately and assign a new value. So, if you wanted to set all the points in a list of points to 0 in Z for example, it would look like this:

for pt in pts:
    pt.Z=0

That’s it, simple. You can set the Z value as fixed in the script, or ask the user for it with rs.GetReal().

1 Like

I have made this code. It has worked for me. @Willem suggestion has helped me a lot.

import rhinoscriptsyntax as rs


def setPoint():
    #To Select the Curves or Points that needs to align
    object_id = rs.GetObjects("Select Objects", filter=0, group=True, preselect=True, select=False, objects=None, minimum_count=1, maximum_count=0, custom_filter=None)
    if not object_id:
        return
    else:
        
        #To Select destination's Point
        point_value = rs.GetPoint(message="Select Point", base_point=None, distance=None, in_plane=False)
        
        if not point_value:
            return
        else:
            print("not empty")
            x_value = point_value.X
            print(x_value)
            #To Execute the Command
            rs.SelectObjects(object_id)
            rs.Command("!_-SetPt X=Yes Y=No Z=No w"+str(x_value)+",0,0 _Enter")
        
    #rs.UnselectAllObjects()
    return
    
setPoint()

Not sure what you are trying to do, but this may fail or produce bad objects for some types of objects - for example an X-axis-aligned 3D boxlike structure or a polycurve that has elements that are parallel to the X axis in it.

If you are trying to “flatten” curves, then you can perhaps limit the choice in GetObject() to curves (4); or perhaps you are trying to align stuff and not necessarily flatten things?

1 Like

Thank you. I have got your points. I am an amateur in python scripting. I will try to develop it. Anyway, I am facing a problem with the existing code. It can not select block instance reference insertion point. Could you please tell me how to select reference the insertion point as well?