LastCreatedObjects RhinoScript trouble


I am trying to generate some curves in a “For” loop, then select them all and add them to a group, but it seems that Rhino.LastCreatedObjects does not work in the same script. I took the example from Help and added a for loop to generate same curves after the circles and yet the 3rd circle is being selected.

Thank you very much!

Call Main()
Sub Main()
	Dim arrObjects, strObject, arrCrv(5), i

	Rhino.Command "_-Circle 0,0,0 10"

	Rhino.Command "_-Circle 10,0,0 10"

	Rhino.Command "_-Circle 20,0,0 10"
	For i=0 To 2
		arrCrv(i) = Rhino.AddLine(Array(0, i, 0), Array(10, i, 0))
	arrObjects = Rhino.LastCreatedObjects

	If IsArray(arrObjects) Then

		Rhino.SelectObjects arrObjects

	End If 
End Sub

Hi @cristina.b,

the method Rhino.LastCreatedObjects will only get the objects created using Rhino.Command and should be run right after using it.

You might select all the objects easier if you apply them to variables like below:

Option Explicit

Call Main()
Sub Main()
    Dim i, arrLines(2), arrPlane, arrCircles(2)

    For i = 0 To 2
        arrLines(i) = Rhino.AddLine(Array(0, i, 0), Array(10, i, 0))

    arrPlane = Rhino.WorldXYPlane()
    arrCircles(0) = Rhino.AddCircle(arrPlane, 10)

    arrPlane = Rhino.MovePlane(arrPlane, Array(10, 0, 0))
    arrCircles(1) = Rhino.AddCircle(arrPlane, 10)

    arrPlane = Rhino.MovePlane(arrPlane, Array(20, 0, 0))
    arrCircles(2) = Rhino.AddCircle(arrPlane, 10)

    Rhino.SelectObjects arrLines
    Rhino.SelectObjects arrCircles

End Sub

to get lines and circles into a single variable, you could use Rhino.JoinArrays like this:

    Dim arrObjects
    arrObjects = Rhino.JoinArrays(arrLines, arrCircles)
    Rhino.SelectObjects arrObjects


It works! Thank you very much! :slight_smile: