Made a script that's running every time I open rhino... what gives?


#1

This is probably obvious… Used the same sortof beginning lines as usual but first time I’ve had a problem:

Option Explicit
’Script written by Ryan Wynott
’Script version November 25, 2016 9:55:46 AM

Rhino.AddStartupScript Rhino.LastLoadedScriptFile()
Rhino.AddAlias “RenameToMaterials”, “_NoEcho _-Runscript (RenameToMaterials)”

Call RenameToMaterials()
Sub RenameToMaterials()

Dim arrObjects, strObject
arrObjects = Rhino.ObjectsByType(8 + 16 + 32)
	
For Each strObject In arrObjects
	
	Dim strObjectLayer: strObjectLayer = Rhino.ObjectLayer(strObject)
	
	Dim materialIndex: materialIndex = Rhino.LayerMaterialIndex(strObjectLayer)
			
	If materialIndex = -1 Then

		Rhino.Print "The object layer does not have a material assigned."

	Else
		Dim objectMaterial: objectMaterial = Rhino.MaterialName(materialIndex)
		
		Rhino.ObjectName strObject, objectMaterial
					
		Rhino.Print objectMaterial
		Rhino.Print "renamed object"
				
	End If
			
Next

End Sub


#2

Hi Ryan,

I recently learned what the problem is: if you are preloading the script but want it under alias, you need to remove the call to the main Sub from the script. So try removing this line:
Call RenameToMaterials()

hth,

–jarek


#3

So you think the others are running also and just exiting gracefully, instead of producing an error like this one when it doesn’t find any objects in the model I guess…


#4

I think so, if they have a call to the main sub they should run at startup if you are adding them to startup scripts…