HistoryRecording In VBScript

Hi,
What I am trying to do in the following code is to deform an extruded Object (Polygon Based) by means of History Recording.
That means any upcoming changes to the polygon results in the deformation of the extrusion as well.
However, unlike the the initial polygon, the extruded surface maintains it previous form.
Any ideas what is missing?
Thanks in advance;
Here is the Code:

 Call Main()
 Sub Main()

	Dim strObject,cpoint,m,intcount

	strObject = Rhino.addPolygon(rhino.WorldXYPlane, 10, 6)

        If Not IsNull(strObject) Then
	
         	Rhino.EnableHistoryRecording True
	        Rhino.EnableObjectGrips strObject
	
	        Rhino.ExtrudeCurveStraight strObject, array(0, 0, 20)
		m = Rhino.ObjectGripLocation(strObject, 5)
	        m(0) = m(0) + 5
     		m(1) = m(1) + 0
      		m(2) = m(2) + 0
        	Rhino.ObjectGripLocation strObject, 5, m
		
 	End If

End Sub

Hi Vahab,

Rhino’s History history is command-based. That is, History-enabled commands store the connection between a command’s input geometry and the result so that when the input geometry changes, the result updates accordingly.

Being that History is command-based, it is not possible for a script to participate in History (other than to enable or disable its recording).

If you were to do the above in just Rhino, it would be the ExtrudeCrv command that would be recording the input history. So you might consider scripting this command using Rhino.Command.

– Dale

1 Like

@dale
Thanks for the note
But…
since I want to run it by code
I am still Confused.
Could you please be more specific about the Rhino.Command ?
I know how to apply it on “Commands” not in “Tabs” such as Gumball, Record History or Grid Snap

@Vahab, try the example below, then move the polygon in rhino to see history update:

Option Explicit

Call Main()
Sub Main()

    Dim arrPlane, strObject, dblDistance, strCmd

        arrPlane = Rhino.WorldXYPlane()
        strObject = Rhino.AddPolygon(arrPlane, 10, 6)
        If IsNull(strObject) Then Exit Sub
    
        Rhino.EnableHistoryRecording True
        Rhino.SelectObject strObject
    
        dblDistance = 20.0
        strCmd = "_ExtrudeCrv _Solid=Yes " & dblDistance
        Rhino.Command strCmd, False

 
End Sub

Note that i just used a extrusion distance as variable dblDistance. You can feed a direction vector as well using the _Direction option of the _ExtrudeCrv command if required.

c.

1 Like

Thanks @clement,

@Vahab, here is information on Rhino.Command.

http://4.rhino3d.com/5/rhinoscript/application_methods/command.htm

– Dale

1 Like

@clement
Thanks a lot for the Example, :ok_hand:
Regarding dblDistance I tried to insert a coordinate instead to be able to use ExtrudeCrvToPoint like this:

Sub Main()
Dim arrPlane, strObject, strCmd,arrPoint

arrPlane = Rhino.WorldXYPlane()
strObject = Rhino.AddPolygon(arrPlane, 10, 6)
If IsNull(strObject) Then Exit Sub

Rhino.EnableHistoryRecording True
Rhino.SelectObject strObject

arrPoint = array(100, 100, 100)
strCmd = " _ExtrudeCrvToPoint" & arrPoint
Rhino.Command strCmd, True

End Sub

Which ends to "Error = Type Mismatch"
Any ideas?

@dale
Many Thanks;
The link seems to be the same as what I found in RhinoScript Help.

Note that arrPoint is an array not a string. Commandline inputs are strings, so you’ll need to convert your point to a string to use it via Rhino.Command:

strCmd = "_ExtrudeCrvToPoint " & Rhino.Pt2Str(arrPoint)

btw. note the trailing space after the command _ExtrudeCrvToPoint, it is required.

c.

1 Like

@clement
Thanks for your note
I wonder if there is any syntax-directory of Rhino.Command including array to string conversion!

@Vahab,

vbscript does have a built in Join method which you can use as well. It allows to control the separator. If it is not defined a space is used, below is using a comma eg.:

Dim a, seperator
a = Array(1,2,3,4,5)
Rhino.Print "Result: " & Join(a, ",")

should print like below

Result: 1,2,3,4,5

The Rhino.Pt2Str method does basically the same, but offers a few more options for the precision and a trailing space, perfect to pass multiple 3d points to the commandline. You can find more about in the Utility methods section of the helpfile:

Help > Plugins > RhinoScript

c.

1 Like