I’ve used Rhino for a long time, but I’m fairly new to scripting.
I’m trying to automate a process of opening a file, importing another file and moving the imported part to a new location in the original file.
In the original file I have a point named “Point1” (this is the destination point for the imported part)
In the file I’m importing I have a point named “Point0” (this is the origin point)
I’ve named these objects within their respective files Properties panel under Object Name
This is the code I have so far but Im getting the following error.
“Type mismatch in parameter. String required.”
For Each folderIdx In files
Rhino.Command "-Import " & Chr(34) & strFolder & folderidx.name & Chr(34) & " Enter Enter", True
'Set up for VIEW 1 (SIDE BY SIDE)
arrObjs = Rhino.NormalObjects
If Not ISNull(arrObjs) Then
'import and move object from Point1 to Point0
Rhino.Command "-Import C:\Template\lever.3dm Enter"
Rhino.Command "-selLast Enter"
arrSelected = Rhino.SelectedObjects
arrPointOrigin = Rhino.ObjectsByName("Point0", True)
arrPointDestination = Rhino.ObjectsByName("Point1", True)
arrSelected = Rhino.MoveObject(arrSelected, arrPointOrigin, arrPointDestination)
End If
Rhino.UnselectAllObjects
Next
I didn’t test the code with your file but looking at it you may need to change the following:
arrPointOrigin = Rhino.ObjectsByName("Point0", True) arrPointOrigin=Rhino.GetPointCoordinates(Rhino.ObjectsByName("Point0", True)(0))
( ObjectsByName returns array, so you need the 1st element of it (0) and the method to get actual coordinates of the point, not the point itself
Same would go to the 2nd line of PointDestination.
Also, you will need to change Rhino.MoveObject to Rhino.MoveObjects to avoid same error as you are feeding it with array of objects and not a single object ID string.
Just off the top of my head, you are using Rhino.MoveObject which expects a single object ID (string) when you should be using Rhino.MoveObjects which will accept an array of objects…
Thanks guys, I edited the script with the suggestions you both offered and still got the error. Its finding the points because they highlight, but I get the same mismatch error.
Ive also tried a few other things. Im including the attempts (commented out). Any help is appreciated.
~J
Dim arrStart
Dim arrEnd
Dim arrTranslation
'Rhino.NormalObjects should be all selectable objects'
arrObjs = Rhino.NormalObjects
If Not ISNull(arrObjs) Then
'import and move lever
Rhino.Command "-Import C:\template\lever.3dm Enter"
'Rhino.UnselectAllObjects
arrLever = Rhino.ObjectsByLayer("MoveObject", True)
arrSelected = Rhino.SelectedObjects
If IsArray(arrSelected) Then
arrStart = Rhino.GetPointCoordinates(Rhino.ObjectsByName("Point0", True)(0))
If isArray(arrStart) Then
arrEnd = Rhino.GetPointCoordinates(Rhino.ObjectsByName("Point1", True)(0))
If IsArray(arrStart) Then
arrTranslation = Rhino.VectorCreate(arrStart, arrEnd)
Rhino.MoveObjects arrSelected, arrTranslation
End If
End If
End If
' 'arrPointOrigin = Rhino.ObjectsByName("Point0", True)
' arrPointOrigin = Rhino.GetPointCoordinates(Rhino.ObjectsByName("Point0", True)(0))
' ' arrPointDestination = Rhino.ObjectsByName("Point1", True)
' arrPointDestination = Rhino.GetPointCoordinates(Rhino.ObjectsByName("Point1", True)(0))
' arrLever = Rhino.ObjectsByLayer("MoveObject", True)
' arrSelected = Rhino.SelectedObjects
' arrSelected = Rhino.MoveObjects(arrSelected, arrPointOrigin, arrPointDestination)
End If
How about a simple version like that (sorry, in my suggestion it should have been PointCoordinates and not GetPointCoordinates). In general, it’s better to use Option Explicit at the beginning and declare (Dim) all variables so you can debug later on if the script grows:
Option Explicit
Call Main()
Sub Main()
Dim arrStart, arrEnd, arrLever
'import lever
Rhino.Command "-_Import " & chr(34) & "C:\template\lever.3dm" & chr(34) & " _Enter"
'assign imported object to array variable
arrLever = Rhino.LastCreatedObjects()
If IsArray(arrLever) Then
'get lever point origin coordinates
arrStart = Rhino.PointCoordinates(Rhino.ObjectsByName("Point0", True)(0))
If isArray(arrStart) Then
'get file origin point coordinates
arrEnd = Rhino.PointCoordinates(Rhino.ObjectsByName("Point1", True)(0))
If IsArray(arrEnd) Then
'move newly imported stuff
Rhino.MoveObjects arrLever, arrStart, arrEnd
End If
End If
End If
End Sub