What is the scripting equivalent of positioning a cursor and clicking it?
rs.GetPoint?
That is cheating. Once the script runs the user cannot input anything. It must be self contained and automatic.
I don’t understand then… You said
positioning a cursor and clicking it
I assumed that meant user interaction. What are you trying to do exactly?
–Mitch
Write a “Self contained script” for the creation of say a fastener. All the input is done at
the begining and then user must let the script run to completion. In the script there will be occasions when an object is trimmed or split.The position of the object to be split or trimmed
is known as indeed will be the locations of the resulting objects. What is not known are the IDs
of the resulting objects so they are difficult to select. If one could script the cursor to move to
a specific location on the screen and then script the mouse click one might be able to select that object which one wishes to retain.
I believe that the screen action will involve Windows( for Mouse actions), rhino(Viewport) and
whatever it is that can combine the two to achieve the objective.
Generally you need to have an idea of what you are going to keep and what you are going to discard and where those pieces will end up - for an automatic script, you should then be able to run through the list of pieces resulting from a split operation and either keep or delete them based on some geometric or geographic criteria: size/bounding box, location/closest point, edges/points in common with something else, etc.
–Mitch
Tried “ClosestPoint” but I do not appear to be using it correctly as it is ignored as the third
argument for the “Trim” method.
import rhinoscriptsyntax as rs
import math
import Rhino
Line =rs.AddLine((-5,2,0),(5,2,0))
Box =rs.AddBox( ((-3,0,0),(3,0,0),(3,3,0),(-3,3,0),
(-3,0,3),(3,0,3),(3,3,3),(-3,3,3)) )
Point_Top =rs.AddPoint(0,5,0)
print " "
print "CuttingLine ", Line
print "Box ", Box
print “Point_Top”, Point_Top
print " "
rs.Command("_ClosestPt"+" selid “+str(Box)+” Enter selid “+str(Point_Top)+” Enter ")
print “Point closest to Box is :”, rs.PointClosestObject(Point_Top,Box)
print " "
LeftOver = rs.Command("_Trim" +" selid “+str(Line)+” selid “+str(Box)+” Enter “+” selid “+str(Point_Top)+” Enter ")
print " "
Well, in the case of trying to trim things automatically, I find it’s best to use Split and then try to detect which of the parts to keep and which to delete afterwards. So I used the rs.AddCutPlane method to create a cutting plane instead of a trim line. However, SplitBrep can also use any kind of surface/polysurface that you can create and reference, not just planes.
Following is an example - note, it’s a bit more complex then beginner level, but splitting/trimming generally is complicated… I also used all RhinoCommon/Rhinoscriptsyntax native methods and not rs.Command().
import rhinoscriptsyntax as rs
import Rhino
#make your box
d=3.0
points=[]
points.append(Rhino.Geometry.Point3d(-d,0,0))
points.append(Rhino.Geometry.Point3d(d,0,0))
points.append(Rhino.Geometry.Point3d(d,d,0))
points.append(Rhino.Geometry.Point3d(-d,d,0))
points.append(Rhino.Geometry.Point3d(-d,0,d))
points.append(Rhino.Geometry.Point3d(d,0,d))
points.append(Rhino.Geometry.Point3d(d,d,d))
points.append(Rhino.Geometry.Point3d(-d,d,d))
box =rs.AddBox(points)
#set up the cutting plane
p0=Rhino.Geometry.Point3d(-2*d,2,0)
p1=Rhino.Geometry.Point3d(2*d,2,0)
zVec=Rhino.Geometry.Vector3d(0,0,1)
cp=rs.AddCutPlane ([box], p0, p1, normal=zVec)
#split the object
#split_parts will be a list of the pieces, original is deleted
err_msg="Something went wrong"
split_parts=rs.SplitBrep(box,cp,delete_input=True)
rs.DeleteObject(cp)
if split_parts:
#find the piece closest to the pick point and delete all others
pick_point=Rhino.Geometry.Point3d(0,5,0)
co=rs.PointClosestObject(pick_point,split_parts)
if co[0]:
for element in split_parts:
if element != co[0]:
rs.DeleteObject(element)
rs.SelectObject(co[0])
else:
#no closest object found
print err_msg
else:
#no split happened...
print err_msg
Hi Mitch,
Wow! I do appreciate all the effort you have put into answering my query.
I will try your solution in the next few days and get back to you.
D