Sorry, but the plugin is only concerned about Maxwell paths...here's a quick RhinoScript that might do what you want, just:
- Tools > RhinoScript > Edit...
- paste the script in, save it as 'GatherAndRebaseTextures.rvb'
- use Tools > RhinoScript > Load.. and Run...
What it does is:
- take a selected set of objects
- read their textures
- copy them to a folder named for the 3dm + '_textures' at the same path as the 3dm
- change the paths of the textures (in the document) to be relative to the newly-copied files
Obviously I haven't tested this much, and I really don't know much about scripting, so let me know if it does what you want.
Cheers,
JD
Code: Select all
Public Sub GatherAndRebaseTextures
On Error Resume Next
Dim objects, object, index, fso, shell, root, name, relRoot, changed, doRel
doRel = GetBoolean("Would you like to make paths relative to the document?", Array("MakeRelative", "No", "Yes"), Array(False) )
If Not IsArray(doRel) Then
Exit Sub
End If
objects = Rhino.GetObjects("Select Objects", 56)
If IsArray(objects) Then
Set fso = CreateObject("Scripting.FileSystemObject")
root = Rhino.DocumentPath
If doRel(0) = True Then
' sometimes Rhino doesn't do this:
Set shell = CreateObject("sWScript.Shell")
shell.CurrentDirectory = root
End If
name = Split(Rhino.DocumentName, ".")
relRoot = name(0) & "_textures\"
root = root & relRoot
If doRel(0) = False Then
relRoot = root
End If
If Not fso.FolderExists(root) Then
fso.CreateFolder root
End If
For Each object In objects
index = Rhino.ObjectMaterialIndex(object)
If index <> -1 Then
Dim texture, transparency, bump, environment, fName
' check/copy main texture
texture = Rhino.MaterialTexture(index)
If Not IsNull(texture) Then
fName = CopyFile(texture, root, fso)
If fName <> "" Then
Rhino.MaterialTexture index, relRoot & fName
changed = True
End If
End If
' check/copy transparency texture
transparency = Rhino.MaterialTransparencyMap(index)
If Not IsNull(transparency) Then
fName = CopyFile(transparency, root, fso)
If fName <> "" Then
Rhino.MaterialTransparencyMap index, relRoot & fName
changed = True
End If
End If
' check/copy bump texture
bump = Rhino.MaterialBump(index)
If Not IsNull(bump) Then
fName = CopyFile(bump, root, fso)
If fName <> "" Then
Rhino.MaterialBump index, relRoot & fName
changed = True
End If
End If
' check/copy environment texture
environment = Rhino.MaterialEnvironmentMap(index)
If Not IsNull(environment) Then
fName = CopyFile(environment, root, fso)
If fName <> "" Then
Rhino.MaterialEnvironmentMap index, relRoot & fName
changed = True
End If
End If
End If
Next
If changed = True Then
Rhino.DocumentModified True
Rhino.Print("Textures for the selected objects have been gathered to: '" & root & "'")
Rhino.Print("Some texture paths may have been modified in the document, be sure to save your changes.")
Else
Rhino.Print("No changes were necessary.")
End If
Else
Rhino.Print("No objects were selected.")
End If
End Sub
GatherAndRebaseTextures
Private Function CopyFile(oldPath, targetDir, fso)
CopyFile = ""
If Not fso.FileExists(oldPath) Then
Rhino.Print("Unable to locate '" & oldPath & "'")
Else
Dim path, fName, newPath
path = Split(oldPath, "\")
fName = path(UBound(path))
newPath = targetDir & fName
If fso.FileExists(newPath) Then
CopyFile = fName
Else
Rhino.Print("Copying '" & oldPath & "' to '" & newPath & "'")
fso.GetFile(oldPath).Copy newPath, True
If fso.FileExists(newPath) Then
CopyFile = fName
Else
Rhino.Print("Copy failed for '" & newPath & "'")
End If
End If
End If
End Function