Page 1 of 2
including material textures in rhino-file ???
Posted: Fri Jan 25, 2008 9:14 pm
by firebird
Hi JD,
is it possible to include all textures used in mxms in a file to this certain file.
This would be a knd of pack and go option, sort of.
I work sometimes on different computers with the same file, at work and both my computers at home.
Is there maybe a way to redifine the textures paths in rhino.
say, I´ve got a path at work
S://CADViz/Project2008/ProjectXYZ/Maps/Rhino_Auxpecker...
at home I have
D://Data/Work/Company/ProjectXYZ/Rhino_Auxpecker...
So I use a lot of Auxpecker Maps too, It would be nice to just redifine the Auxpeckerfolder for all maps, than go through every object and layer.
thx so far
cheers firebird
Posted: Fri Jan 25, 2008 9:52 pm
by JDHill
Hi firebird,
No, not possible to put them _in_ the file, but have you tried using 'Gather All Files'? (it's in the Scene Materials context-menu) This will bring all referenced texture/r2/ior files into an organized set of folders next to the current .3dm. All of the paths in the materials will be changed to relative - you will need to save immediately after using the feature (the command-line will tell you that) so that the relative paths which have just been created will be saved in the file. Now you can zip up the .3dm with the gathered files and move it to another location - all the materials inside now reference the gathered files using relative paths.
Let me know if that's what you're looking for.
JD
Posted: Sat Jan 26, 2008 12:29 pm
by firebird
thx JD,
yep that is what should do the job for maxwell!
what´s about other textures like auxpeckermaps does this work too?
cheers

Posted: Sat Jan 26, 2008 4:07 pm
by JDHill
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
Posted: Mon Jan 28, 2008 1:16 pm
by firebird
Hi jeremy,
it does this

Posted: Mon Jan 28, 2008 1:43 pm
by JDHill
Works fine here, probably just a problem with the copy/paste...try running
this...
Posted: Mon Jan 28, 2008 2:01 pm
by firebird
the machine at my office, has the same error prompt! maybe it is got something to do that our admin hasn´t installed sr2 yet, we still on sr1.
my machines runs the script, creates the folder, but the folder is emtpy.
prompt: no changes were neccessary
any clues (I am on SR2a)
EDIT
a new file works perfectly!!!
maybe there is something wrong with the other file, since it has got some dead paths due to copying it from machine to machine???
Posted: Mon Jan 28, 2008 2:12 pm
by JDHill
I don't really know - like I say I don't know much about scripting. If it says no changes were necessary, I guess it didn't find any textures?
Posted: Mon Jan 28, 2008 2:24 pm
by firebird
I will keep an eye on it!
thx very much so far!!!
cheers
Posted: Mon Jan 28, 2008 2:45 pm
by firebird
hi jd,
I gave the script a try with a new file on the office machines, always the eror prompt.
could it be that I have to install this vb script exe (vcredist_x86) , that comes with your plugin aswell?
since I got no admin rights its hard to figure out, if the script works on the office machines!
Posted: Mon Jan 28, 2008 2:56 pm
by JDHill
No you don't need to install anything - an .rvb file is just a .txt file renamed to .rvb - inside it's exactly the same code I posted above.
I guess it might be admin priveleges, or maybe the wscript.shell object isn't available on those machines. So...you can try this...open the script again in the editor and comment-out (i.e. type an apostrophe at the beginning of the line - the text will turn green and that line of code will be skipped) the two following lines:
'Set shell = CreateObject("WScript.Shell")
'shell.CurrentDirectory = root
If you do that, and it works - make sure you always open your files using File > Open, and not the 'recent files' list at the bottom of the File menu - when you open them from there, Rhino sometimes doesn't set the current directory for the process, and this will cause any relative paths to fail.
Posted: Mon Jan 28, 2008 7:30 pm
by firebird
thx jd,
the script kind of works now, only thing is that if you reopen the file, all texture tilings are gone and some materials are not applied, though they got the right path.
Is there a way to reload all textures and projectors, like in a browser "reload"

Posted: Mon Jan 28, 2008 9:33 pm
by JDHill
Like I said above, I would expect this to happen sometimes if you open a .3dm with relative paths using the 'recent files' list - but if you're using File > Open, then I'm not sure why they are lost...are the relative paths shown in Object Properties > Material correct? Anyway, I modified the script so that it asks you whether or not you want to make paths relative, or keep them absolute...I updated the .zip at the link previously posted.
I don't know about the re-load idea - I suppose you could ask on the Rhino newsgroup, but I doubt there's any way to do that, once the document has been saved.
Posted: Tue Jan 29, 2008 4:53 pm
by firebird
Hi JD,
I meant a kind of refresh button, not reloading the old paths.
as far as I figuered out now, the script only gathers textures that are directly related to objects, not related via a layer, and it sets all tilings back to default (UV 1,1). You see this when the script is running.
any clues to keep the set tilings? If I get some time I will go thruogh the script a bit closer. I already downloaded, the david rutten vbscript! Something to study on weekends, while I am bored due to no work, LOL
thx so far anyway
Posted: Tue Jan 29, 2008 5:14 pm
by JDHill
Yes, I see that now, and there doesn't seem to be any way to avoid it - this is apparently just how it works when you set texture paths through RhinoScript. The only modification to your material that the script is making is this:
Rhino.MaterialTexture index, relRoot & fName
What that means is (similar for the trans/bump/emap):
set: 'MaterialTexture' (the material's main texture)
at this: 'index' (the index of the material in Rhino's material table)
to: 'relRoot & fName' (add together the folder name and the file name)
This is the only control over textures available to script (afaik). So, you could post a wish to the newsgroup that when you set a texture path using script, that it would not also erase the tiling/offset data.