SketchUcation Plugin Store

 

 

[Plugin]Export Collada with texture names 1.2b [30/9/11]

[Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby Aerilius » Thu Sep 29, 2011 5:04 pm

This plugin allows to export the whole model or the selection to Collada file format while preserving/restoring the the texture's original file and the material's screen names.
This is useful since SketchUp's Collada exporter creates generic names which don't allow to identify materials anymore when you want to use the file in another software.
SketchUp also creates new textures images for each face with distorted texture coordinates; however these won't receive the original material's name.
If you need specific export options (from SketchUp's options dialog), feel free to edit the options_hash.
Unfortunately, SketchUp also creates generic material names (<auto>1) when you import Collada files into SketchUp.

Version: 1.2b

Date: 30.09.2011

Usage:
(Menu) File -> 'Export Collada with texture names'
Please, register (free) to access all the attachments on the forums.
Last edited by Aerilius on Fri Sep 30, 2011 5:39 pm, edited 6 times in total.
Aerilius
Top SketchUcator
 
Posts: 1128
Joined: Tue Dec 23, 2008 11:00 pm
Location: Kaiserslautern

Re: [Plugin] Export Collada with texture names

Postby McGyver » Thu Sep 29, 2011 8:19 pm

FANTASTIC!! I just started using the dae export option and the texture renaming is extremely frustrating! Thank you!!



EDITED TO ADD- Unfortunately it does not work for me. I get an "Error Loading" warning. I have the latest FREE version of SU 8... and I am running it on a Mac using OS 10.5. I tried it to see if it works in earlier versions but even though it shows up in the menu in SU 6, it does not respond... but does not give a error loading warning though.
Hope it works for other folks.
Please, register (free) to access all the attachments on the forums.
McGyver
 
Posts: 114
Joined: Wed Feb 04, 2009 5:46 pm

Re: [Plugin] Export Collada with texture names

Postby Gaieus » Thu Sep 29, 2011 9:17 pm

It works for me - on Windows. I wonder if there is anything on the Mac...
Gai...
User avatar
Gaieus
Administrator
 
Posts: 27626
Joined: Sat Oct 20, 2007 8:24 am
Location: Pécs, Hungary
Name: Csaba Pozsárkó
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: historical reconstruction
Level of SketchUp: Advanced

Re: [Plugin] Export Collada with texture names

Postby Aerilius » Thu Sep 29, 2011 9:38 pm

Hi,
file_loaded is a method that almost all scripts use. Do you have any other plugins that show this error?
In your SketchUp/Tools folder should exist a file "sketchup.rb" where line 41 defines file_loaded. Maybe it's something else but I don't know what it could be.
If you see it in SU6, can you open the ruby console before running it?
Aerilius
Top SketchUcator
 
Posts: 1128
Joined: Tue Dec 23, 2008 11:00 pm
Location: Kaiserslautern

Re: [Plugin] Export Collada with texture names

Postby Jim » Thu Sep 29, 2011 10:07 pm

Aerilius,

...you didn't

require "sketchup"

Your plugin is loading before sketchup.rb, which is why it's a good idea to require "sketchup" in your plugins.
Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

Re: [Plugin] Export Collada with texture names

Postby TIG » Thu Sep 29, 2011 10:11 pm

You need to have the text require 'sketchup.rb'* at the very start of the script's code [outside of any module/class/def]... because those methods "file_loaded()/file_loaded?()" are defined by that script*; often there's no problem when you forget to 'require' it because some other script has already 'required' it before yours loads and it only needs to be required/loaded just once for it to be available to all scripts thereafter... BUT if not [e.g. your script loads early or there are few scripts loading or no others require it either!] you'll get that error :roll:
So add it around line #27 ! :roll:
TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin] Export Collada with texture names

Postby driven » Thu Sep 29, 2011 10:19 pm

Code: Select all
Error: #<NoMethodError: private method `gsub' called for nil:NilClass>
/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/ColladaWithTextureNames.rb:66:in `run'
/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/ColladaWithTextureNames.rb:140


moding line 66 gets rid of that and it runs, ref_dir = "#{( ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] ).gsub(/\\/,'/')}/skp_cwtn"

however, it's not clearing the temp directory so on second run I get.

Code: Select all
 Error: #<Errno::ENOTEMPTY: Directory not empty - /var/folders/lN/lNON23AjHxezeYON7yETPU+++TI/-Tmp-//skp_cwtn>
/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/ColladaWithTextureNames.rb:72:in `delete'
/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/ColladaWithTextureNames.rb:72:in `run'
/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/ColladaWithTextureNames.rb:140


but it does make the files... even though showing these errors.
on re-import some of the faces have been reversed and some of the materials only show up after draw event...

I hadn't added require 'sketchup' yet, but I think it's mainly a path issue on mac...
john
driven
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

Re: [Plugin] Export Collada with texture names

Postby TIG » Thu Sep 29, 2011 10:31 pm

The last trap sorts out PC and MAC variants...
The bald Dir.delete(ref_dir)
WILL fail IF the directory contains files... so use
Dir.entries(ref_dir).each{|f|
next if f=='.' or f=='..'
File.delete(File.join(ref_dir, f))
}if Dir.entries(ref_dir)[2]
Dir.delete(ref_dir)

This WILL delete any folder as it 'empties' it first...
EDIT: typo fixed :o
TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin] Export Collada with texture names

Postby driven » Thu Sep 29, 2011 10:48 pm

@TIG,

I get : undefined method `Dir' with that?

john
driven
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

Re: [Plugin] Export Collada with texture names

Postby driven » Thu Sep 29, 2011 11:06 pm

...and something else I find odd, a new Material folder was created and populated with materials, but none of these are in the 'undeleted' tmp Dir.

To clarify:
If I remove the 'tmp' Dir from the system. Start SU, open a drawing and RC, and then use this plugin.

I get a .dae and a populated Materials folder and I also have a new tmp Dir with the same materials inside, and the no method error.

if I then open a second drawing and use this plugin again I get another .dae and another populated Materials folder, bur the tmp Dir does not add these new materials and I get another no method error for Dir.

I don't understand....

john
driven
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

Re: [Plugin] Export Collada with texture names

Postby Aerilius » Fri Sep 30, 2011 12:58 am

I fixed all issues above (hope now it's right).
I also added that the plugin prefers the material's screen name as long as it's not generic.
This time I must have forgotten the require Sketchup. Thanks to all for the tips.


@driven: It works with
Dir.foreach(d){|f|
}

and
Dir.entries(d)[2]
Aerilius
Top SketchUcator
 
Posts: 1128
Joined: Tue Dec 23, 2008 11:00 pm
Location: Kaiserslautern

Re: [Plugin]Export Collada with texture names 1.1 [30/9/11]

Postby McGyver » Fri Sep 30, 2011 3:14 am

It works now, but when I checked the material names after importing them in Blender and Poser they are being renamed again.
There are no other plugins loaded into SU8... I just downloaded 8 and this is the first Ruby I added.
Please, register (free) to access all the attachments on the forums.
McGyver
 
Posts: 114
Joined: Wed Feb 04, 2009 5:46 pm

Re: [Plugin] Export Collada with texture names

Postby TIG » Fri Sep 30, 2011 9:53 am

driven wrote:@TIG,

I get : undefined method `Dir' with that?

john
Sorry, stupid typo - fixed original so as not to confuse latecomers to the party ;)
TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin]Export Collada with texture names 1.1 [30/9/11]

Postby Morten » Fri Sep 30, 2011 10:26 am

Excellent plugin (and initiative), Aerilius!

There seems to be a small problem with the texture paths though:

<init_from>Boxes_MaterialTest/C:/Users/ABC/Desktop/Boxes_MaterialTest/_Asphalt_Stamped_Brick_1.jpg</init_from>

As you can see it seems to add the name of the exported DAE file to the texture path. Once I've removed that I can easily import the DAE file with textures in Lumion :thumb:
Morten
Lumion3D
 
Posts: 3
Joined: Tue Jun 08, 2010 10:04 am

Re: [Plugin]Export Collada with texture names 1.1 [30/9/11]

Postby driven » Fri Sep 30, 2011 12:19 pm

Silex3D wrote: Once I've removed that I can easily import the DAE file with textures in Lumion :thumb:


the folder does stop all the texture being scattered over you desktop, so maybe putting the dae file into it programatically would be better...

john
driven
Top SketchUcator
 
Posts: 1409
Joined: Fri May 01, 2009 11:50 pm
Name: John
Operating system: Mac
SketchUp version: 8
License type: Pro
SketchUp use: engineering and mechanical design
Level of SketchUp: Intermediate

Re: [Plugin]Export Collada with texture names 1.1 [30/9/11]

Postby TIG » Fri Sep 30, 2011 1:16 pm

<init_from>daetest/C:/Users/TIG/Desktop/daetest/Palm14x.png</init_from>
should be either
<init_from>C:/Users/TIG/Desktop/daetest/Palm14x.png</init_from>
or for a [better] more general solution where the dae has its images in a folder 'kept with it' even when moved
<init_from>daetest/Palm14x.png</init_from>
The code is readily tweaked thus
fileNames.each{|old,new|
colladaContent.gsub!(old,new)
colladaContent.gsub!(/#{dir+'/'}/,'')
}
to remove the unneeded path...

:roll:
TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin]Export Collada with texture names 1.1 [30/9/11]

Postby Morten » Fri Sep 30, 2011 2:58 pm

Thanks for that, TIG - the textures work great now without the need to manually edit the paths!

Any idea how to preserve the original SketchUp material names in the DAE file?
Morten
Lumion3D
 
Posts: 3
Joined: Tue Jun 08, 2010 10:04 am

Re: [Plugin]Export Collada with texture names 1.2 [30/9/11]

Postby Aerilius » Fri Sep 30, 2011 3:11 pm

Morten wrote:Any idea how to preserve the original material names in the DAE file?

That's what I've been working on (while I hadn't read all new posts here). I've also found the mistake myself and fixed it (I had mixed up the file base name and full path).
So now the plugin not only replaces texture file names, but also the material's screen names. It wasn't simple because collada has several different material names (<material>, <instance_material>) that are scattered over the whole file.

driven wrote:maybe putting the dae file into it programatically would be better

So you mean to put the collada file into the same folder where the textures are? I understand how that would be useful, for now I did only modify the contents of the dae and kept the file structure how SketchUp produced it.
Aerilius
Top SketchUcator
 
Posts: 1128
Joined: Tue Dec 23, 2008 11:00 pm
Location: Kaiserslautern

Re: [Plugin]Export Collada with texture names 1.2 [30/9/11]

Postby Gaieus » Fri Sep 30, 2011 3:22 pm

Aerilius wrote:So you mean to put the collada file into the same folder where the textures are? I understand how that would be useful, for now I did only modify the contents of the dae and kept the file structure how SketchUp produced it.

Indeed it could be useful however note that it would be rather unusual. Most of the exporting packages I know place the materials into a subfolder under where the model file is. Would it not cause confusion rather than ease of use? When exporting, most (experienced) users create a folder to collect all exported files and subfolders anyway.
Gai...
User avatar
Gaieus
Administrator
 
Posts: 27626
Joined: Sat Oct 20, 2007 8:24 am
Location: Pécs, Hungary
Name: Csaba Pozsárkó
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: historical reconstruction
Level of SketchUp: Advanced

Re: [Plugin]Export Collada with texture names 1.2 [30/9/11]

Postby Morten » Fri Sep 30, 2011 3:34 pm

Aerilius wrote:I've also found the mistake myself and fixed it (I had mixed up the file base name and full path). So now the plugin not only replaces texture file names, but also the material's screen names.

Hmm, after replacing your Ruby script with the latest version, the imported DAE object appears without textures in both Blender and Lumion.

I'm testing a simple box with 1 brick material + 1 default white material on the inside of the box, and as far as I can tell, there's still a slight discrepancy between the material names throughout the DAE file:

Code: Select all
<instance_material symbol="[Brick_Rough_Tan]" target="#ID5">
<instance_material symbol="Material3" target="#ID15">
...
Code: Select all
<triangles count="12" material="Material2">
<triangles count="12" material="Material3">

The texture re-appears if I replace "Material2" with "[Brick_Rough_Tan]", so it's almost working.
Morten
Lumion3D
 
Posts: 3
Joined: Tue Jun 08, 2010 10:04 am

Re: [Plugin]Export Collada with texture names 1.2 [30/9/11]

Postby TIG » Fri Sep 30, 2011 4:15 pm

I too have noticed this BUT the SKP dae-importer works just fine :? :shock:
Perhaps these other apps need the image files to be with the dae - but the normal SKP dae-exporter version writes to a similar textures subfolder too ? :roll:

I have also played around with trying to adjust the material's names in the xml - you can convolutedly connect the textures to the materials and thereby get the real material's name... BUT changing them in the xml [manually] seems to do nothing because when you import the materials they are still called '<auto>1' etc anyway :?
TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby pep75 » Wed Oct 05, 2011 10:42 am

F I N A L L Y !!!!!!!!!!!!!! :berserk: :berserk: :berserk: :berserk: :berserk: :berserk: :ecstatic: :ecstatic: :thumb: :thumb:

I LOVE YOU!
pep75
 
Posts: 86
Joined: Mon May 05, 2008 1:14 pm

Re: [Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby pep75 » Wed Oct 05, 2011 11:32 am

mmm....the love is over.....it doesn't do anything! Is it working? I'm importing the Collada-file into Cinema4d but I just got the "normal" material names...... :cry:
pep75
 
Posts: 86
Joined: Mon May 05, 2008 1:14 pm

Re: [Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby Gaieus » Wed Oct 05, 2011 12:46 pm

What do you mean by "normal" materials names? Texture0, texture1 etc.?
Are you using this exporter? (File > "Export collada with texture names" and not File > Export > 3D...)?
Gai...
User avatar
Gaieus
Administrator
 
Posts: 27626
Joined: Sat Oct 20, 2007 8:24 am
Location: Pécs, Hungary
Name: Csaba Pozsárkó
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: historical reconstruction
Level of SketchUp: Advanced

Re: [Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby pep75 » Wed Oct 05, 2011 1:38 pm

Hey Gaius,

In Cinema4D I normally get "Material 1, Material 2, etc" instead of the material names I use in SketchUp. When I use the collada-plugin (file > export collada with material names) it really doesn't export it with the material names. I'm working with Windows and version 8...mmm

grtzz
Pep
pep75
 
Posts: 86
Joined: Mon May 05, 2008 1:14 pm

Re: [Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby TIG » Wed Oct 05, 2011 1:47 pm

We can't see how to rename 'Materials' in a DAE file.
We can rename their 'Texture' files however.
SO depending on the app that you import into - all materials will become something like material0, material1 etc, or in a SKP <auto>1 etc.
Assigning a name to a material in the DAE is simply ignored and the app's imported materials are named using their simple numerical order in the DAE file.
However, if the material has a texture many apps will list that against the material, so you can then spot it by that image-name IF you've used this exporter-tool and had used sensible image names for textured-materials. With the native DAE exporter material1 will have a texture called perhaps texture1.png etc... but at least this tools gives material1 with 'brick_666.png'...
TIG
User avatar
TIG
Global Moderator
 
Posts: 13987
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby pep75 » Wed Oct 05, 2011 1:55 pm

Aaaaaah...so only the names of TEXTURED materials will show up...mmm...well that means no improvement for me...:(....grrr....I could already see the linked texture-names in Cinema and the textures are clear to me wich material it is....well...

Thanks though!!
Grtzz
Pep
pep75
 
Posts: 86
Joined: Mon May 05, 2008 1:14 pm

Re: [Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby Aerilius » Wed Oct 05, 2011 2:30 pm

TIG wrote:SO depending on the app that you import into

That could be a explanation (I can't check because I don't have C4D).

It seems collada files contain several "similar" elements like <image>, <effect>, <material> and <instance_material>. SketchUp's exporter applies generic IDs and names ("Material2") to these elements and generic names to the texture files.
I added already the capability to apply the original material's name to <material name="..."> and <instance_material symbol="..."> (although that was risky and caused lots of the errors in the posts above, but it should work now). I regret if those names aren't imported into other applications.
Aerilius
Top SketchUcator
 
Posts: 1128
Joined: Tue Dec 23, 2008 11:00 pm
Location: Kaiserslautern

Re: [Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby pep75 » Thu Oct 06, 2011 8:05 am

Hey Aerilius, please don't apologise for this...you did a great job, and I was getting used for waiting on a more streamlined import method to C4D. It will come! :)

Thanks anyway!
Grtz
Pep
pep75
 
Posts: 86
Joined: Mon May 05, 2008 1:14 pm

Re: [Plugin]Export Collada with texture names 1.2b [30/9/11]

Postby nightstrike » Wed Oct 12, 2011 1:02 am

First of all Thanks for your efford!

I am having 2 problems with this particular plugnin
1) The normal collada file from the native exporter in sketchup is about 62mb but with your is more that 250mb. Is there anything, like filenames, material names or whatever matter when exporting?
2) Importng it to Lumion doesn't seem to show up the names of the materials. Has anyone make it to work properly with lumion? Meaning lots of re-sync with correct materials?

p.s. I don't know if that matters but I am notusing "textres" in sketchup just color "materials" that I change the name (!)

Thanks for your time!

edit: I also tried with "textured" materials and some materials got idd renamed in the first time, but 1) The texture seamed to go to more surfaces than i put it 2) The names on a second export seemed to seize renamed and go to a generic material01, material03...

Although as I understanding there is not a perfect solution here. Has anyone understood what order sketchup uses in order to apply the generic material names? My first thought was alphabetical but this seems not to be the case...Plz help me.... :(
nightstrike
 
Posts: 3
Joined: Thu Sep 09, 2010 12:07 pm
Name: stamatis

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Need SketchUp Books, Models, Styles or Textures? Check out our One Stop Shop for SketchUp.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012

Next

Return to Plugins

Who is online

Users browsing this forum: CadFather, fwu014, giosrd, Huggkruka, iwazz, nikibg2002, OuchOuchOuch and 12 guests