Mirror quad


#1

Hi
I am trying to write a script that mirros x and y axis with history option on and off.
herer’s little macro script

-_mirror pause _history r enter x _sellast _mirror y _sellast _mirror x _history r _enter

if you write this in vb rhinoscript how would this be??I am just curious to learn.


#2

Perhaps something like the following…

–Mitch

Option Explicit
'Script written by Mitch Heynick
'Version Tuesday, January 14, 2014

Call MirrorXY()
Sub MirrorXY()
	Dim hState,objs,xMirObjs,yMirObjs
	hState = Rhino.EnableHistoryRecording(True)
	objs = Rhino.GetObjects("Select objects to quad mirror",,, True, True)
	Call Rhino.EnableRedraw(False)
	If Not IsArray(objs) Then Exit Sub
	Call Rhino.Command("_Mirror X _Enter", False)
	xMirObjs = Rhino.LastCreatedObjects()
	If IsArray(xMirObjs) Then
		Call Rhino.SelectObjects(xMirObjs)
		Call Rhino.Command("_Mirror Y _Enter", False)
	End If
	Call Rhino.UnselectAllObjects()
	Call Rhino.SelectObjects(objs)
	If Not hState Then
		Call Rhino.EnableHistoryRecording(False)
	End If
	Call Rhino.EnableRedraw(True)
End Sub

#3

cool!.I learn something today.many thanks


#4

Shouldn’t “If Not hState Then” be “If hState Then” ?
As hState was sat to True in the beginning.


#5

What the script is supposed to do is turn on History if it’s not already on and remember that so it can turn it back off again at the end; but if History is on to begin with, I assume the user doesn’t want to turn it off, so it needs to stay on.

hState = Rhino.EnableHistoryRecording(True)

turns history on, but hState stores the previous condition

There is a bug currently that if History isn’t on, Rhino.EnableHistoryRecording() returns Empty instead of False. So I set up the script to look at what hState is at the end - if it’s anything OTHER than True (this includes both False and Empty), it turns the history back off.

If Not hState Then
	Call Rhino.EnableHistoryRecording(False)
End If

This way, when the bug gets fixed, the script will still work…

–Mitch


#6

Ah, thanks for the info Mitch!