Orient on surface

Hi

as a jeweller I often use " orient on surface" tool to place stones on surfaces. when I use orient on surface I hit the coordinate “0” in the Top viewport and then choose the surface I want to place. so instead of typing 0 and enter in top viewport I wrote a little macro script like this.

! _OrientOnSrf pause SetActiveViewport top 0 0,5,0

it works fine but the trouble is when it’s in perspective viewport which is expanded in full viewport it switches to top viewport so I have to minimize the top viewport and go back to the perspective viewport.
can you change that macro script to other type of the script so that when it is in perspective viewport it doesn’t switch to top viewport??
can you also change this one as well??
! _ArrayCrvOnSrf  pause SetActiveViewport top 0
Many thanks

As your input points are specified in world xy coordinates, there is no reason this should not work (too):

! _OrientOnSrf pause 0 0,5,0

that doesn’t work if I do it in the front viewport as you see the picture below. the stones place in wrong way.
also how would you change it to the python or vb script?? is it possible??

I see. OrientOnSrf require an initial orientation plane. And this plane is being taken from the Top view. So, it is important that your macro always start from the Top view.

A RhinoScript script might be helpful. Here is one you can start with:

Sub MyOrientOnSrf
	
	' Declare local variables
	Dim arrObjects, strObject
	Dim strView, blnMaximized
	Dim strCmd
	
	' Select objects to orient
	arrObjects = Rhino.GetObjects("Select objects to orient",, True, True)
	If IsNull(arrObjects) Then Exit Sub
	
	' If the current view is maximized, restore it
	strView = Rhino.CurrentView
	blnMaximized = Rhino.IsViewMaximized(strView)
	If (blnMaximized) Then
		Call Rhino.MaximizeRestoreView(strView)
	End If

	' Set the the active viewport to the "Top" viewport
	Call Rhino.Command("SetActiveViewport Top")
	
	' Build a command macro string
	strCmd = "OrientOnSrf"
	For Each strObject In arrObjects
		strCmd = strCmd & " SelId " & strObject
	Next
	strCmd = strCmd & " Enter 0 0,5,0"
	
	' Run the OrientOnSrf command macro
	Call Rhino.Command(strCmd)
	
	' If the current view was maximized, restore it
	If (blnMaximized) Then
		Call Rhino.MaximizeRestoreView(strView)
	End If
	
	' Done!
	
End Sub

More on RhinoScript.

Hi Dale
thanks for your help. I tried to make a button for it but it doesn’t work.here’s script

-_Runscript(
Sub MyOrientOnSrf

	' Declare local variables
Dim arrObjects, strObject
Dim strView, blnMaximized
Dim strCmd

	' Select objects to orient
arrObjects = Rhino.GetObjects("Select objects to orient",, True, True)
If IsNull(arrObjects) Then Exit Sub

	' If the current view is maximized, restore it
strView = Rhino.CurrentView
blnMaximized = Rhino.IsViewMaximized(strView)
If (blnMaximized) Then
	Call Rhino.MaximizeRestoreView(strView)
End If

	' Set the the active viewport to the "Top" viewport
	Call Rhino.Command("SetActiveViewport Top")

	' Build a command macro string
strCmd = "OrientOnSrf"
For Each strObject In arrObjects
	strCmd = strCmd & " SelId " & strObject
Next
strCmd = strCmd & " Enter 0 0,5,0"

	' Run the OrientOnSrf command macro
	Call Rhino.Command(strCmd)

	' If the current view was maximized, restore it
If (blnMaximized) Then
	Call Rhino.MaximizeRestoreView(strView)
End If

	' Done!

End Sub

what should it be fixed??

Hi junkim

Try putting a space between Runscript and the bracket and add ‘Call MyOrientOnSrf’

-_Runscript (
Call MyOrientOnSrf
Sub MyOrientOnSrf

and don’t forget to close the brackets at the end of the script

End Sub
)

A more efficient approach would be to add the script (I posted) the the list of scripts to run on start up.

http://4.rhino3d.com/5/rhinoscript/introduction/scripting_options.htm

Then, just create a command alias or button macro to run the already loaded script subroutine.

Reading through the Introduction section of the RhinoScript help file, where loading and running scripts is discussed, might be helpful to you.