#259450
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
By JDHill
#259454
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
By firebird
#259486
thx JD,

yep that is what should do the job for maxwell!

what´s about other textures like auxpeckermaps does this work too?

cheers ;)
By JDHill
#259502
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

Last edited by JDHill on Mon Jan 28, 2008 9:35 pm, edited 1 time in total.
By firebird
#259563
Hi jeremy,

it does this

Image


;)
By JDHill
#259566
Works fine here, probably just a problem with the copy/paste...try running this...
By firebird
#259570
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???
By JDHill
#259572
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?
By firebird
#259573
I will keep an eye on it!

thx very much so far!!!

cheers
By firebird
#259575
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!
By JDHill
#259578
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.
By firebird
#259608
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"

;)
By JDHill
#259620
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.
By firebird
#259677
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
By JDHill
#259681
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.
render engines and Maxwell

well I don't think AI will remain like it is now. […]

Help with swimming pool water

Hi Andreas " I would say the above "fake[…]