Import file, group everything and save as previous version

Import file, group everything and save as previous version

Postby eugenio_miolo » Thu Feb 13, 2020 6:02 pm


I'm totally knew to sketchup and Ruby, but what I need to do something should be very simple. Given an input file (dae, obj, etc) I need to import, group everything and (preferentially) save as some previous version.

Most of my code comes from this topic:

Here's what I have:
# get the active_model as a variable and clears the scene
model = Sketchup.active_model

# imports the file and change tool to stop manual placement
dae = "file_import_path.dae"
model.import(dae, {:merge_coplanar_faces => false})

# creates a definition (whatever it is) and save it to a new file
defn=model.definitions[-1], ".*")
defn.description="Imported from DAE"
skp=dae.gsub(/[.]dae$/, '.skp')

#opens the saved file, group everything and save as a previous version
model.entities.add_group(model.entities.to_a), Sketchup::Model::VERSION_2017)

This code get's me pretty close to what I need. The main problem is that I can't get rid of the popup dialog that prompts to save the current file when "Sketchup.open_file" command is called. I can't even call "Sketchup.quit()" or similar commands for the same problem. So is there a way to make Sketchup run commands and supress any possible dialog to pop up? In 3dsmax many commands have a "quiet" mode, or we can suppress everything by setting "silentMode true" at the beggining of the code. I need something similar here.

Still, there are multiple problems going on here which I would really like to have a better understanding:

  1. After running the "model.import" and "Sketchup.send_action('selectSelectionTool:')" commands, the model doesn't show in viewport for the current Sketchup session. Why is that?
  2. Oddly, creating a definition (no idea what's exactly a definition) and saving it, the model is there in the file.
  3. Because of problem number one, I can't group objects after import neither save the file as a previous version through the "save_copy" method, which is only present for the "Model" class.
  4. Therefore I'm forced to open the file from step number 2, which I can't automate because doing so pops up the save scene dialog since the scene has changed.

And one final question, Sketchup will be called by command line "Sketchup.exe -RubyStartup my_ruby_code.rb". How do I get rid of the welcome screen by code? I'm using Sketchup 2020 Pro Trial for now.

Sorry for the long post.

Thanks in advance,


SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Ad Machine 


Return to Developers' Forum


Who is online

Users browsing this forum: No registered users and 5 guests

Visit our sponsors: