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


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."

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

End Sub


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()




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…


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…