[REQ] Export selected groups/comps to separate skp files

[REQ] Export selected groups/comps to separate skp files

Postby numerobis » Fri Jan 18, 2019 5:59 pm

Is there a plugin that lets you select one or more groups or components and export them separately as skp to a specific directory? I have found export plugins for other formats, but no skp.

I'm still searching for a good solution to "link" skp files to 3ds max. There is this import link manager for max that could work quite well for me...
http://www.mirarkitektur.com/mirzasoftw ... %20Manager

I could import the whole model, but this can take some time for bigger files, so i think splitting up the model in several parts would be helpful. If i modify the model only the changed parts need to be updated.

So my question is, if someone could set up an export routine where you can export (and overwrite on update) only selected parts to a folder.

The best thing would be if it would be possible to specify an export folder that is defined in the project (is it possible to store such attributes?) and export/update the selected groups or components with their definition names with click on a button or an entry in the right click menu.
(A more advanced option could be a link manager like "Cross Reference Organizer" (https://extensions.sketchup.com/en/cont ... -organizer) where all parts would be listed and could be refreshed)
0
Last edited by numerobis on Mon Jan 28, 2019 1:00 pm, edited 2 times in total.

numerobis 
 

Re: [REQ] Export selected groups/comps to separate skp files

Postby rv1974 » Fri Jan 18, 2019 6:32 pm

Hide unwanted, save file and open it in Max. Max skips hidden geometry
0

rv1974 
 

Re: Re: [REQ] Export selected groups/comps to separate skp f

Postby numerobis » Fri Jan 18, 2019 7:10 pm

Thanks for the suggestion, but i need separate files to link them in max. If i link the same file several times with different hidden parts the imported geo will be overwritten.
And if i have to hide parts first and then save the file i can also select the modified groups one by one and export them via right click menu, as i do it now. I was searching for a more automated solution for bigger models, where i would split the model in more parts to make it faster to update in max.
0
Last edited by numerobis on Sat Jan 19, 2019 12:12 am, edited 1 time in total.

numerobis 
 

Re: Re: [REQ] Export selected groups/comps to separate skp f

Postby rv1974 » Fri Jan 18, 2019 8:13 pm

link aux max files (containing skp geometry) in centralized (host) max file.
0

rv1974 
 

Re: Re: [REQ] Export selected groups/comps to separate skp f

Postby srx » Sat Jan 19, 2019 12:25 pm

You have the option from Component browser/In model Components - Save to local colection which saves all components from the model to SU components library
0
www.saurus.rs
User avatar
srx 
 

Re: [REQ] Export selected groups/comps to separate skp files

Postby rv1974 » Sat Jan 19, 2019 2:43 pm

It doesn't preserve location
0

rv1974 
 

Re: [REQ] Export selected groups/comps to separate skp files

Postby TIG » Sat Jan 19, 2019 4:41 pm

The attached code should do something like you want...
Note the following:
You must have saved the model before running this.
You must have at least a group and/or a component-instance preselected before running this.
Individual groups are exported using their given-name, or if unnamed as 'Group#N' where N is the count.
Individual instances are exported using their definition-name, with a '#N' count suffix added if there's more than one instance of that definition.
These exported SKPs are put into the same folder as the model itself.
It reports the files it has exported as it goes.
The exported file's thumbnails should be accurate.
It removes any backup files made during the process, and on completion it reverts to the original model's contents.
All temporary deletions etc are 'aborted', so that although the exported files get made successfully, the original model should remain unchanged.
To use the code simply copy all of it and paste it into the Ruby Console and press <enter>.
Note the preselection requirement !
If it works as you hope, then I can make it into a RB file, with a menu item etc for you...
Code: Select all
mo=Sketchup.active_model
pa=mo.path
if pa.empty?
  UI.messagebox("Save 'Untitled' Model Before Exporting...")
else
  d=File.dirname(pa).tr("\\", "/")
  es=mo.active_entities.to_a
  ss=mo.selection.to_a
  mo.selection.clear
  gs=ss.grep(Sketchup::Group)
  gis=gs.collect{|e| e.persistent_id }
  is=ss.grep(Sketchup::ComponentInstance)
  iis=is.collect{|e| e.persistent_id }
  unless gis[0] || iis[0]
    UI.messagebox("Select Groups and/or Instances Before Exporting...")
  else
    gis.each_with_index{|ii, i|
      e=nil
      mo.active_entities.to_a.each{|ee|
        if ee.persistent_id==ii
          e=ee
          break
        end
      }
      next unless e
      mo.start_operation("Export_group#{i}",true)
      n=e.name
      n="Group##{i+1}" if n.empty?
      p f=File.join(d, n+".skp")
      xs=es=mo.active_entities.to_a-[e]
      xs.each{|x|
        x.erase! if x.valid?
      }
      mo.save(f)
      if File.exist?(File.join(d, n+".skb")) #PC
        File.delete(File.join(d, n+".skb"))
      end
      if File.exist?(File.join(d, n+"~.skp")) #MAC
        File.delete(File.join(d, n+"~.skp"))
      end
      mo.abort_operation #revert model
    }
    iis.each_with_index{|ii, i|
      e=nil
      mo.active_entities.to_a.each{|ee|
        if ee.persistent_id==ii
          e=ee
          break
        end
      }
      next unless e
      mo.start_operation("Export_instance#{i}",true)
      n=e.definition.name
      n="#{n}##{i+1}" if e.definition.instances[1]
      p f=File.join(d, n+".skp")
      xs=es=mo.active_entities.to_a-[e]
      xs.each{|x|
        x.erase! if x.valid?
      }
      mo.save(f)
      if File.exist?(File.join(d, n+".skb")) #PC
        File.delete(File.join(d, n+".skb"))
      end
      if File.exist?(File.join(d, n+"~.skp")) #MAC
        File.delete(File.join(d, n+"~.skp"))
      end
      mo.abort_operation # revert model
    }
    mo.save(pa) # revert back to orignal model
  end
end
puts "Done."
1
TIG
User avatar
TIG 
Global Moderator
 

Re: Re: [REQ] Export selected groups/comps to separate skp f

Postby numerobis » Sat Jan 19, 2019 7:38 pm

Thank you very much TIG! But i'm getting an error message...
Code: Select all
Error: #<NoMethodError: undefined method `persistent_id' for #<Sketchup::ComponentInstance:0x0000002558bb80>>
<main>:12:in `block in <main>'
<main>:12:in `collect'
<main>:12:in `<main>'
SketchUp:1:in `eval'

I tried with components and groups.
0

numerobis 
 

Re: Re: [REQ] Export selected groups/comps to separate skp f

Postby numerobis » Sat Jan 19, 2019 7:51 pm

@srx This saves ALL components of a model.
0

numerobis 
 

Re: [REQ] Export selected groups/comps to separate skp files

Postby TIG » Sun Jan 20, 2019 1:47 pm

I just noticed that the SketchUp version you have is <2016.
Therefore "Persistent IDs" cannot be used - these are needed to circumvent the lost IDs during newer SketchUp processes...

Try this alternative [which will fail with >=2016 ! but should still work in older versions ?? ]
Code: Select all
mo=Sketchup.active_model
pa=mo.path
if pa.empty?
  UI.messagebox("Save 'Untitled' Model Before Exporting...")
else
  d=File.dirname(pa).tr("\\", "/")
  es=mo.active_entities.to_a
  ss=mo.selection.to_a
  mo.selection.clear
  gs=ss.grep(Sketchup::Group)
  gis=gs.collect{|e| e.guid }
  is=ss.grep(Sketchup::ComponentInstance)
  iis=is.collect{|e| e.guid }
  unless gis[0] || iis[0]
    UI.messagebox("Select Groups and/or Instances Before Exporting...")
  else
    gis.each_with_index{|ii, i|
      e=nil
      mo.active_entities.to_a.each{|ee|
        if ee.guid==ii
          e=ee
          break
        end
      }
      next unless e
      mo.start_operation("Export_group#{i}",true)
      n=e.name
      n="Group##{i+1}" if n.empty?
      p f=File.join(d, n+".skp")
      xs=es=mo.active_entities.to_a-[e]
      xs.each{|x|
        x.erase! if x.valid?
      }
      mo.save(f)
      if File.exist?(File.join(d, n+".skb")) #PC
        File.delete(File.join(d, n+".skb"))
      end
      if File.exist?(File.join(d, n+"~.skp")) #MAC
        File.delete(File.join(d, n+"~.skp"))
      end
      mo.abort_operation #revert model
    }
    iis.each_with_index{|ii, i|
      e=nil
      mo.active_entities.to_a.each{|ee|
        if ee.guid==ii
          e=ee
          break
        end
      }
      next unless e
      mo.start_operation("Export_instance#{i}",true)
      n=e.definition.name
      n="#{n}##{i+1}" if e.definition.instances[1]
      p f=File.join(d, n+".skp")
      xs=es=mo.active_entities.to_a-[e]
      xs.each{|x|
        x.erase! if x.valid?
      }
      mo.save(f)
      if File.exist?(File.join(d, n+".skb")) #PC
        File.delete(File.join(d, n+".skb"))
      end
      if File.exist?(File.join(d, n+"~.skp")) #MAC
        File.delete(File.join(d, n+"~.skp"))
      end
      mo.abort_operation # revert model
    }
    mo.save(pa) # revert back to orignal model
  end
end
puts "Done."
1
TIG
User avatar
TIG 
Global Moderator
 

Re: [REQ] Export selected groups/comps to separate skp files

Postby numerobis » Mon Jan 21, 2019 1:17 pm

TIG wrote:I just noticed that the SketchUp version you have is <2016.
Therefore "Persistent IDs" cannot be used - these are needed to circumvent the lost IDs during newer SketchUp processes...

Oh sorry, i wasn't aware of that.

Thanks for the update. It's working great now! Very cool. :D
Could you put it into the right click menu to the other export options?


Btw. is it possible to configure the right click menu? The list is getting very long and there are some entries that i never use. I somehow remember that this wasn't possible and you had to change it in the plugin code. If this is the case, is there a single command that can be commented out to deactivate it without generating problems or is it more complex?
0

numerobis 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Plugins

Who is online

Users browsing this forum: jsteacy and 28 guests

Visit our sponsors: