UnrollWithTextCoords.rvb for Rhino 6 is not running on Rhino 8

Hi
I’ve been using this script for unrolling multiple surfaces, copiing it ran only as administrator in Rhino 7 and now that i use Rino 8 the script just stopped working. Note that the script is originally written in .rvb so i wonder if it is possible to rewrite it for python

Here is the Script:

Option Explicit
'Script written by Jaroslaw Bieda

Call Main()
Sub Main()

On Error Resume Next

'get surfaces to unroll
Dim arrM : arrM = Rhino.GetObjects("Surfaces to Unroll?", 8)
If isnull(arrM) Then Exit Sub

'get unroll start point
Dim arrBP : arrBP = Rhino.GetPoint("Unroll start point?")
If isnull(arrBP) Then arrBP = array(0, 0, 0)

Dim x : x = 0
Dim arrBB

Dim idM
Dim i,j,arrMV,arrDots(),arrNewMV(),arrUnrolled, idNewMesh
Dim c : c = 0
Dim arrNewMeshes()

Dim strTmpPath : strTmpPath = GetApplicationDataFolder() & "tmp.obj"

Call Rhino.EnableRedraw(False)
Call Rhino.StatusBarProgressMeter("Processing...", 0, Ubound(arrM), True, True)

'process each surface
For i=0 To Ubound(arrM)

	Call Rhino.StatusBarProgressMeter(i)
	
	If Rhino.IsSurfaceUnrollable(arrM(i)) Then
	
		'get underlying mesh
		idM = Rhino.ExtractRenderMesh(arrM(i))
		Rhino.UnselectAllObjects
		
		'export/import as OBJ to 'Bake' texture coordinates
		Call Rhino.SelectObject(idM)
		Call Rhino.Command("-_Export " & strTmpPath & " _ExportMeshTextureCoordinates=Yes _Enter _Enter", False)
		Call Rhino.DeleteObject(idM)
		Call Rhino.Command("_-Import " & strTmpPath & " _Enter", False)
		idM = Rhino.SelectedObjects()(0)
		
		'draw dot for each mesh vertex with number on the source surface
		arrMV = Rhino.MeshVertices(idM)
		ReDim arrDots(Ubound(arrMV))
		For j=0 To Ubound(arrMV)
			arrDots(j) = Rhino.AddTextDot(Cstr(j), Rhino.EvaluateSurface(arrM(i), Rhino.SurfaceClosestPoint(arrM(i), arrMV(j))))
		Next
	
		'select original surface and dots from mesh verts
		Call Rhino.UnselectAllObjects()
		Call Rhino.SelectObjects(arrDots)
		Call Rhino.SelectObject(arrM(i))
	
		'unroll...
		Call Rhino.Command("_UnrollSrf _Labels=No _Enter", False)
	
		'reconstructing mesh vertext locations from dots
		ReDim arrNewMV(Ubound(arrMV))
		arrUnrolled = Rhino.LastCreatedObjects()
		For j=0 To Ubound(arrUnrolled)
			If Rhino.ObjectType(arrUnrolled(j)) = 8192 Then
				arrNewMV(CInt(Rhino.TextDotText(arrUnrolled(j)))) = Rhino.TextDotPoint(arrUnrolled(j))
			End If
		Next

		'reconstruct unrolled mesh based on original vertices and text. coords
		idNewMesh = Rhino.AddMesh(arrNewMV, Rhino.MeshFaceVertices(idM),, Rhino.MeshTextureCoordinates(idM))
		Call Rhino.MatchMaterial(arrM(i), array(idNewMesh))
		
		ReDim Preserve arrNewMeshes(c)
		arrNewMeshes(c) = idNewMesh
		c = c + 1
		
		'move mesh no the new unroll location / arrange 
		arrBB = Rhino.BoundingBox(idNewMesh)
		Call Rhino.MoveObject(idNewMesh, arrBB(0), array(arrBP(0) + x, arrBP(1), arrBP(2)))
		x = x + Rhino.Distance(arrBB(0), arrBB(1))
		
		'cleanup 
		Call Rhino.DeleteObjects(arrUnrolled)
		Call Rhino.DeleteObject(idM)
		Call Rhino.DeleteObjects(arrDots)
		
		'refresh view
		Call Rhino.EnableRedraw(True)
		Call Rhino.EnableRedraw(False)
		
	Else 'mark non-unrollable surface as RED
		Call Rhino.ObjectColor(arrM(i), vbRed) 
	End If
	
	
	
Next

'finalize
Call Rhino.UnselectAllObjects()
If c > 0 Then Call Rhino.SelectObjects(arrNewMeshes)
Call Rhino.EnableRedraw(True)
Call Rhino.StatusBarProgressMeter()

End Sub

Private Function GetApplicationDataFolder()
Const APPLICATION_DATA = &H1a&
Dim objShell, objFolder, objFolderItem
Set objShell = CreateObject(“Shell.Application”)
Set objFolder = objShell.Namespace(APPLICATION_DATA)
Set objFolderItem = objFolder.Self
GetApplicationDataFolder = objFolderItem.Path & “”
End Function

@Jarek - want to help?

I have something similar in Python already I think, hang on a bit until I get back to my computer…

OK, have a go with this one… There are quite a number of command-line options that were perhaps not in the .rvb.

MultiUnroll_2.py (8.4 KB)

Let me know if something goes wrong or if it needs modification - I have’t messed with it in a number of years.

Thanks for the help! Seems to work for unrolling the surfaces, but the texture is missing. -ExtractRenderMesh- command is in the code of the problem script so i guess it changes the surface before the unroll and then bakes it, i don’t get how… Here we use it to unroll multiple simply-curved surfaces with an image applied as a material.

Yeah, sorry, didn’t read your post carefully enough. My script was always intended to unroll just the geometry, did not consider textures.

Hi Alejandro,

I use this excellent script occasionally also. It works perfectly if you select one surface.

I’ve always done one surface at a time, so I didn’t notice the problem you are talking about. It fails when selecting multiple surfaces.

I’m completely incompetent when it comes to scripting but I supect it has to do with how the selected objects array is being processed.

I’ll leave that to the bigger brains :wink:

Cheers, Steve

I can look into it, did not have a chance yet, but most likely it has to do with the OBJ Command Line export settings that changed from V6 to V8. Probably just that part of the script needs to be modified for this to work. (it’s been a while since I wrote it)