Make rvb file into button


#1

Hi
I have a script that was posted here and it was rvb file. Now I want to make it as a button in Rhino5. could you tell me how I could make this as a button in rhino??

-_RunScript (

Call Rhino.AddAlias(Split(Split(Rhino.LastLoadedScriptFile, “”)(Ubound(split(Rhino.LastLoadedScriptFile, “”))), “.”)(0), "!_NoEcho _-Loadscript " & Chr(34) & Rhino.LastLoadedScriptFile & Chr(34))
Call Rhino.Print(“Alias " & Split(Split(Rhino.LastLoadedScriptFile, “”)(Ubound(split(Rhino.LastLoadedScriptFile, “”))), “.”)(0) & " added to Rhino”)

Call SlideOnCurve()
Sub SlideOnCurve()

Dim arrObj
arrObj = Rhino.GetObjects("Select Objects to slide on curve",,, True, False)
If isNull(arrObj) Then Exit Sub

Dim strCrv
strCrv = Rhino.GetObject("Select Curve to slide over", 4)
If isNull(strCrv) Then Exit Sub

Dim arrPtOc : arrPtOc = Rhino.GetPointOnCurve(strCrv, "Set refernce point on curve")
If isNull(arrPtOc) Then Exit Sub	

Call Rhino.EnableRedraw(False)


Dim arrCrvPlane : arrCrvPlane = Rhino.CurveFrame(strCrv, Rhino.CurveClosestPoint(strCrv, arrPtOc))

Dim XOrient: XOrient = Rhino.XformRotation(arrCrvPlane, Rhino.ViewCPlane(Rhino.CurrentView()))


Call Rhino.UnselectAllObjects()
Call Rhino.TransformObjects(arrObj, XOrient, False)
Call Rhino.SelectObjects(arrObj)

Dim str: str = "!_OrientOnCrv w" & Rhino.Pt2Str(Rhino.ViewCPlane(Rhino.CurrentView())(0)) & " SelID " & Chr(34) & strCrv & Chr(34) & " "

Call Rhino.EnableRedraw(True)
Call Rhino.Command(str)

End Sub

)


#2

Hi junkim,
Check these pages:
http://www.archipedia-uk.com/software/scripting/rhino-script/add-button-for-your-script-in-rhino
http://wiki.mcneel.com/developer/macroscriptsetup


#3

The following should work… The script was originally set up for drag-and-drop alias creation, so you want to deactivate or remove the lines that create the alias. Then the “Call” line will run the script in your button.

HTH,
–Mitch

! _NoEcho -_RunScript (

'comment out or remove the following two lines
'the ' is the comment character

'Call Rhino.AddAlias(Split(Split(Rhino.LastLoadedScriptFile, "\")(Ubound(split(Rhino.LastLoadedScriptFile, "\"))), ".")(0), "!NoEcho -Loadscript " & Chr(34) & Rhino.LastLoadedScriptFile & Chr(34))

'Call Rhino.Print("Alias " & Split(Split(Rhino.LastLoadedScriptFile, "\")(Ubound(split(Rhino.LastLoadedScriptFile, "\"))), ".")(0) & " added to Rhino")

'make sure you have the following "Call" line active (that makes the script run):
Call SlideOnCurve()
Sub SlideOnCurve()

Dim arrObj
arrObj = Rhino.GetObjects("Select Objects to slide on curve",,, True, False)
If isNull(arrObj) Then Exit Sub

Dim strCrv
strCrv = Rhino.GetObject("Select Curve to slide over", 4)
If isNull(strCrv) Then Exit Sub

Dim arrPtOc : arrPtOc = Rhino.GetPointOnCurve(strCrv, "Set refernce point on curve")
If isNull(arrPtOc) Then Exit Sub	

Call Rhino.EnableRedraw(False)


Dim arrCrvPlane : arrCrvPlane = Rhino.CurveFrame(strCrv, Rhino.CurveClosestPoint(strCrv, arrPtOc))

Dim XOrient: XOrient = Rhino.XformRotation(arrCrvPlane, Rhino.ViewCPlane(Rhino.CurrentView()))


Call Rhino.UnselectAllObjects()
Call Rhino.TransformObjects(arrObj, XOrient, False)
Call Rhino.SelectObjects(arrObj)

Dim str: str = "!_OrientOnCrv w" & Rhino.Pt2Str(Rhino.ViewCPlane(Rhino.CurrentView())(0)) & " SelID " & Chr(34) & strCrv & Chr(34) & " "

Call Rhino.EnableRedraw(True)
Call Rhino.Command(str)

End Sub

)

#4

I see the Call Rhino.AddAlias and Call Rhino.Print are for loading a script or something else.I wasn’t sure if I could delete or not but now I know. cool :smile:
thanks for the reply


#5

Hi junkim
which command should I add to move perpendicularly?
Thanks and Best regards,
Lam Nguyen


(Dale Fugier) #6

Move perpendicularly to what? Can you provide more details about what you want to do? Sometimes sample models and pictures help too.

– Dale


#7

Hello Dale,
I have a Closed NURBS curve (Red color) which is created from “Rhino.IntersectBreps” in Rhinoscripts. However , this Closed NURBS curve can’t be oriented with a line perpendicularly. Moreover, the normal Circle (green color) is oriented well as can be seen from the attached file.
Thank you so much for your help
Lam Nguyen
test.3dm (151.3 KB)


(Dale Fugier) #8

Hi Lam,

You can use this script as an example of how to orient the Red curve perpendicular to the line.

Sub TestLam
	
	Dim strCurve, arrCurvePlane, arrBox, arrCenter
	Dim	arrLine, dblParam, arrLinePlane
	Dim arrXform
	
	strCurve = Rhino.GetObject("Select planar curve to orient", 4, True)
	If IsNull(strCurve) Then Exit Sub
	
	arrCurvePlane = Rhino.CurvePlane(strCurve)
	If IsNull(arrCurvePlane) Then
		Call Rhino.Print("Curve is not planar.")
		Exit Sub
	End If
	
	arrBox = Rhino.BoundingBox(strCurve, arrCurvePlane) 
	arrCenter = Rhino.PointDivide(Rhino.PointAdd(arrBox(2), arrBox(0)), 2.0)
	arrCurvePlane = Rhino.MovePlane(arrCurvePlane, arrCenter)
	
	arrLine = Rhino.GetObjectEx("Select line to orient on", 4)
	If IsNull(arrLine) Then Exit Sub
	
	dblParam = Rhino.CurveClosestPoint(arrLine(0), arrLine(3))
	arrLinePlane = Rhino.CurvePerpFrame(arrLine(0), dblParam)
	
	arrXform = Rhino.XformRotation(arrCurvePlane, arrLinePlane)
	Call Rhino.TransformObject(strCurve, arrXform, True)

End Sub

– Dale


#9

Hello Dale,
Thank you so much,
you save my life.