Problem loading/running scripts


#1

Hi,

I had a bit of computer meltdown recently and had to do a clean install of windows 7. Since then, some of my scripts fail to load, while some work as usual. For the ones that fail I receive the following message:

I’m struggling to find any information. so far I have changed my user permissions to allow full control, but no joy.

Any help would be greatly appreciated.

Thanks,

John.


(Dale Fugier) #2

What does the code in and around line 64 look like?


(Pascal Golay) #3

Hi John- can you post an example that does not work? How are you launching the scripts? Is the script writing a text file to disc at line 64 in this example?

-Pascal


#4

Thanks for the quick responses!

Here is the script in full:

Option Explicit
'Script written by peter harris
'www.peterwhatcreates.com
'Modified By Don Lewis

	
Call Main()

Sub Main()

	Call Rhino.Print("V1.0 - script created by Peter Harris - www.peterwhatcreates.com")
	Call Rhino.Print("Modified By Don Lewis")
		
	Dim arrObjects, MaterialOptions, X, Y, Z, Material, DensityTest, CBtext, TextChunk, strObject
	Dim ObjectWeight, ObjectMaterial, Density, ObjectName, TestMaterial, arrMP, ObjectVolume, ObjectLayer
	Dim TextChunkForClipboard, ObjectNote
	
	'check if file exists - if not, create it
	
	Dim DefaultText
	DefaultText = "How To Edit The Materials List:" & _
		vbCrLf & "To edit the list, just add your materials, Then an equal sign, and the specific gravity of your material." & _
		vbCrLf & "Do Not begin a material name With a number Or other characters - just letters." & _
		vbCrLf & "Do Not put In multiple materials that have the same name, and Do Not put spaces In the material names" & _
		vbCrLf & "Leave the EditMaterialsList=EditMaterialsList line intact.  You can re-arrange the order as much as you would like." & _
		vbCrLf & "To add materials for which you do not know the specific gravity, convert them to grams per cubic cm." & _
		vbCrLf & "To convert from whatever units you know, go to google and type in something like:" & _
		vbCrLf & CHR(34) & "40 pounds per cubic foot in grams per cubic cm" & CHR(34) & " ...and google will return the number to enter here." & _
		vbCrLf & "You can also move materials from the MaterialsToHide list to the MaterialsList list and vise-versa," & _
		vbCrLf & "which can keep your options simple and customized for you without getting rid of materials that you might need someday." & _
		vbCrLf & vbCrLf & "Here are some websites that list specific gravities of various materials:" & _
		vbCrLf & "http://www.plasticsusa.com/specgrav2.html" & _
		vbCrLf & "http://www.reade.com/Particle_Briefings/spec_gra.html" & _
		vbCrLf & "http://www.tesarta.com/www/resources/library/weights.html" & _
		vbCrLf & vbCrLf & vbCrLf & "[MaterialsList]" & _
		vbCrLf & "ppr=0.900100225" & _
		vbCrLf & "abs=1.05082887" & _
		vbCrLf & "his=1.03740365" & _
		vbCrLf & "eva=0.945868033" & _
		vbCrLf & "lpe=0.945868033" & _
		vbCrLf & "mis=1.03740365" & _
		vbCrLf & "nyl=1.11063214" & _
		vbCrLf & "pvc=1.28149863" & _
		vbCrLf & "EditMaterialsList=EditMaterialsList" & _
		vbCrLf & vbCrLf & vbCrLf & "[MaterialsToHide]" & _
		vbCrLf & "water=1" & _
		vbCrLf & "Renshape_BM5440=0.55" & _
		vbCrLf & "Renshape_BM70=0.7" & _
		vbCrLf & "Renshape_450=0.65" & _
		vbCrLf & "Renshape_460=0.77" & _
		vbCrLf & "Axson_ProLab_65=0.65" & _
		vbCrLf & "Gold=19.32" & _
		vbCrLf & "Silver=10.5" & _
		vbCrLf & "Platinum=21.45"
	
				  	
			
	
	Dim FileLocation : FileLocation = Rhino.InstallFolder + "MaterialSpecificGravityList.ini"
	
	Set objFso = CreateObject("Scripting.FileSystemObject")
	If Not objFso.FileExists(FileLocation) Then
		objFso.CreateTextFile(FileLocation)
		Set objFso = Nothing
		
		
		Dim objFSO, objFile
		Set objFSO = CreateObject("Scripting.FileSystemObject")
		If (objFSO.FileExists(FileLocation)) Then
			Set objFile = objFSO.OpenTextFile(FileLocation, 8, True, -2)
			Call objFile.Write(DefaultText)
			Call objFile.Close()
		
			Set objFile = Nothing
			Set objFSO = Nothing
		End If
	End If
	Set objFso = Nothing
	
	' done --------------------------------

	
	
	MaterialOptions = Rhino.GetSettings(Rhino.InstallFolder & "MaterialSpecificGravityList.ini", "MaterialsList")

	If IsArray(MaterialOptions) Then			
		X = 0
		For Each Material In MaterialOptions
			ReDim Preserve arrDensity(X)
			arrDensity(X) = Rhino.GetSettings(Rhino.InstallFolder & "MaterialSpecificGravityList.ini", "MaterialsList", Material)

			DensityTest = EVAL(arrDensity(X))
			
			If DensityTest <= 0 Then arrDensity(X) = 0 

			X = X + 1
		Next
	Else
		Exit Sub
	End If	
	
	
	arrObjects = Rhino.GetObjects("Select objects to create Cut Sheet ", 8 + 16 + 32 + 4096,, True)
	

	If IsArray(arrObjects) Then
		'-------------------------------------------------------------------
		'figure out conversion factor
		Dim CurrentUnits, TotalConversionFactor, LengthConversion
		'find out current unit system
		CurrentUnits = Rhino.UnitSystemName(, vbtrue)
		'convert them all to cubic cm - multiply by this number!
		Select Case CurrentUnits
			Case "millimeter"
				LengthConversion = .001
			Case "centimeter"
				LengthConversion = 1
			Case "meter"
				LengthConversion = 1000000
			Case "inch"
				LengthConversion = 16.387064
			Case "foot"
				LengthConversion = 28316.8466
			Case Else	
				Msgbox "Sorry - this will not work with your unit system!"
				Exit Sub
			
		End Select

		TotalConversionFactor = LengthConversion * 0.00220462262

		'---------------------------------------------------------------------
		
		Z = 0
		CBtext = ""
		TextChunk = ""
		TextChunkForClipboard = ""
		
		For Each strObject In arrObjects
			
			ObjectMaterial = Rhino.GetObjectData(strObject, "ObjectProperties", "Material")
			ObjectNote = Rhino.GetObjectData(strObject, "ObjectProperties", "ObjectNote")
			ObjectName = Rhino.ObjectName(strObject)
			ObjectLayer = Rhino.ObjectLayer(strobject)
			If IsNull(ObjectName) Then
				ObjectName = Rhino.ObjectName(strObject)
			End If

			'get size
			Dim BoundBox, ObjectSize, ObjectSizea,ObjectSizeb
			BoundBox = Rhino.BoundingBox(strObject)
			Dim dimX : dimX = rhino.Distance(BoundBox(0), BoundBox(1))
			Dim dimY : dimY = rhino.Distance(BoundBox(0), BoundBox(3))
			Dim dimZ : dimZ = rhino.Distance(BoundBox(0), BoundBox(4))
			'Sort size smallest to largest
			dimX = ROUND((dimX), 3)
			dimY = ROUND((dimY), 3)
			dimZ = ROUND((dimZ), 3)
			ObjectSizea = Array(dimX, dimY, dimZ)				
			ObjectSizeb = Rhino.SortNumbers(ObjectSizea)
			ObjectSize = Objectsizeb(0) & ", " & Objectsizeb(1) & ", " & Objectsizeb(2)

			If IsNull(ObjectName) Then
				ObjectName = "unnamed"
			End If

			'Object details
			If Rhino.ObjectName(strObject) = "SG" Then
				TextChunkForClipboard = ObjectName & CHR(9) & ObjectSizeb(0) & CHR(9) & ObjectSizeb(1) & CHR(9) & ObjectSizeb(2) & CHR(9) & ObjectLayer
			ElseIf Rhino.ObjectName(strObject) = "LG" Then
				TextChunkForClipboard = ObjectName & CHR(9) & ObjectSizeb(0) & CHR(9) & ObjectSizeb(2) & CHR(9) & ObjectSizeb(1) & CHR(9) & ObjectLayer
			Else
				TextChunkForClipboard = ObjectName & CHR(9) & ObjectSizeb(0) & CHR(9) & ObjectSizeb(1) & CHR(9) & ObjectSizeb(2) & CHR(9) & ObjectLayer
			End If
			
			If Z > 0 Then
			
				'Make Every Line After First Line
				CBtext = CBtext & vbCrLf & TextChunkForClipboard
			Else
				'Make Header and First Line
				CBtext = "Name" & CHR(9) & "Thickness" & CHR(9) & "Width" & Chr(9) & "Length" & Chr(9) & "Material" & vbCrLf & TextChunkForClipboard
			End If
					
			Z = Z + 1

		Next
		
		'Copy text to clipboard		
		Rhino.ClipboardText CBtext
		'Call Excel sub 
		SendToExcel(CBtext)
				
	Else 
		Rhino.Print "nothing selected"
	End If

End Sub

Sub SendToExcel(CBtext)
	
	Dim LineAdder, X, PageTitle, app, wb, xlSheet, xlCenter
	
		
	' -------------------- Launch Excel --------------------

	'create excel object
	Set app = CreateObject("Excel.Application")
	app.Visible = True

	'Add a new workbook
	Set wb = app.workbooks.add
	
	With app.Worksheets("Sheet1")


		Set xlSheet = app.Worksheets("Sheet1")
		xlSheet.Activate 'The sheet needs to be active
		xlSheet.Range("A1").Select
		xlSheet.Paste
						
		' --------------------------- format cells ---------------------------
		For X = 1 To 8
			.Cells(1, X).EntireColumn.AutoFit
		Next
		            
	End With	
	' ---------------------------- end format -----------------------------
	' Clean up
	Set wb = Nothing
	Set app = Nothing

End Sub

I’ve tried loading from the plugin/script menu, and also from a button that i created with the text in it.

I’ve looked at the script at line 64, but not sure what it is up to! I’m not an expert with scripts, I’m afraid.

Hope this helps.


(Pascal Golay) #5

The script is writing a file and it is pointing at a location, Program Files, that is not writable on Windows 7… It looks to me like this line

Dim FileLocation : FileLocation = Rhino.InstallFolder + "MaterialSpecificGravityList.ini"

needs to point to a writable location, like (on my system)

Dim FileLocation : FileLocation = "C:\Users\Pascal\Documents\Test\MaterialSpecificGravityList.ini"

-Pascal


(Pascal Golay) #6

@jmgh, any luck with that? You can edit the script file using a text editor, or EditScript in Rhino. You can also run the script from EditScript, to see if your changes work…

-Pascal


#7

Thanks Pascal,

Do you think it matters where I point the it to?

I’ve changed the line to the following:

Dim FileLocation : FileLocation = “E:\My Documents\01. JOBS\MaterialSpecificGravityList.ini”

Now the error message is as follows:

Thanks again.

J


#8

Its strange because the script is identical to one that is being used successfully on my colleague’s machine and to the one that I was using before the re-install. Changing the path to:

Dim FileLocation : FileLocation = “C:\Program Files (x86)\Rhinoceros 5.0\Plug-ins\Scripts\MaterialSpecificGravityList.ini”

gives an unknown command error in rhino command bar.

John.


#9

Undelete xD

But uhm.

Dim FileLocation : FileLocation = Rhino.InstallFolder + "MaterialSpecificGravityList.ini"

will return

 "C:\Program Files (x86)\Rhinoceros 5.0\MaterialSpecificGravityList.ini" 

not

"C:\Program Files (x86)\Rhinoceros 5.0\Plug-ins\Scripts\MaterialSpecificGravityList.ini"

Possible that that’s the problem?

P.S. Side question why do you need to use Dim FileLocation : FileLocation. What does the : do?


#10

Thanks for your reply Jordy.

I didn’t write the script myself… It was a peter harris and don lewis production!

I have only started playing with it since it no longer works on my re-installed windows 7. So the original script (posted in full above) worked fine. When Pascal suggested putting a location into the path I just chose an arbitrary location. I not even sure what the script is trying to achieve in this line.

As to your P.S, I’ve no idea! All I know is that the script worked wonderfully for me pre re-install, now it doesn’t work at all.

For what it’s worth, I have a feeling it is to do with my windows setup, and not the script itself, as it is running without problems on other machines in our studio, but not the two which have just been given clean installs of windows.

J


#11

Probably first the settings like MaterialSpecificGravityList was in your rhino installation path. After reinstalling the folder was deleted and created again. After this the file is missing. Maybe try placing the MaterialSpecificGravityList in Rhino’s main folder will solve the problem.

And 2nd. Rhino.InstallFolder + “MaterialSpecificGravityList.ini” is used in more than 1 place. So if you got another location. maybe you need to read through the script and replace it everwhere instead of 1 place. :slight_smile:


#12

Jordy,

That’s only gone and worked!

Thank you so much. I have been pulling my hair out over this for 24 hours.

John.


#13

No problem.

Good luck with it :stuck_out_tongue:

Jordy


#14

Glad someone is fixing this, because I’ve been too busy! I’ll try to get it into the ‘official’ peterstools plugin soon.