Scripting Sub Curve


#1

I am new to python and Rhino so please bear with me.

I am trying to write a script that extends a section of the edge of a mesh in a defined direction.

Without a script I can achieve this by: extracting mesh edges, trimming the resulting curve, copying and moving the curve to where I want it, creating a mesh between the two curves and then joining the meshes together.

So Far I have been able to create the outline in python however I would like to then trim this curve at a user defined position in a similar way to what the “Sub curve” tool does.

It does not seem like there is an “rs.SubCurve” command. Is there another way to do this?

I have seen that I could use “rs.Command(”_SubCrv")" however then I have to select the curve first and I dont know how to get the GUID of the resulting curve to continue the rest of the script.
I would rather the user just have to select the start and end points of the curve if this is possible.

Thanks!


(Willem Derks) #2

Hi Wattzie,

It reminds me of this recent topic; maybe it helps:

Maybe it is of help.
-Willem


#3

Thanks for the help Willem,

I managed to stumble my way through this. For anyone searching for something similar here is what I came up with:

import rhinoscriptsyntax as rs
import Rhino
import math

#load GUID of Mesh
Model=rs.GetObject('Select Mesh',32)

#Create outline of mesh
Outline=rs.DuplicateMeshBorder(Model)

#Trim Curve using command line
rs.Command("_SubCrv " + "selid " + str(Outline[0]))

#Get curve GUID
curve1=rs.LastCreatedObjects()

#Get offset
dy=rs.GetReal("Please enter the horizontal displacement in mm",35,1,100)
dz=rs.GetReal("Please enter the angle offset in degrees",5,-30,30)
dz=dy*math.tan(math.radians(dz))
print(dz)

#copy and move curve to point
curve2=rs.CopyObject(curve1,[0,dy,-dz])

#Create surface between curves
surfParam=(curve1,curve2) #Create turple
surfExtention=rs.AddEdgeSrf(surfParam)

#Mesh surface using command line
rs.Command("_Mesh " + "selid " + str(surfExtention) + " _enter ")

#Get mesh GUID
#MeshExtention=rs.LastCreatedObjects()

#weld all meshes
rs.Command("_weld " +"selall " +" _enter " + " _enter ")

#Join meshes
NewMesh=rs.JoinMeshes((Model,MeshExtention),True)

#delete surface and curves
rs.DeleteObject(surfExtention)
rs.DeleteObject(curve1)
rs.DeleteObject(curve2)

For now this does what I want however if anyone can help me improve this code it would be greatly appreciated.

There are two main things that I would like to improve. Firstly I don’t know how to select more than one object in the command line so I have to select all the objects to weld them (“selall”). This could be problematic if I have some meshes that I do not want to weld.

Additionally, the _Mesh command brings up a dialog box that I have to press enter to remove. Is there a way to script this?

Thanks for the help