sketchucation logo sketchucation
    • Login
    1. Home
    2. eugenio_miolo
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download
    E
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 1
    • Groups 1

    Posts

    Recent Best Controversial
    • Import file, group everything and save as previous version

      Hello,

      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:
      https://sketchucation.com/forums/viewtopic.php?f=180&t=69535#

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

      imports the file and change tool to stop manual placement

      dae = "file_import_path.dae"
      model.import(dae, {:merge_coplanar_faces => false})
      Sketchup.send_action('selectSelectionTool:')

      creates a definition (whatever it is) and save it to a new file

      defn=model.definitions[-1]
      defn.name=File.basename(dae, ".*")
      defn.description="Imported from DAE"
      skp=dae.gsub(/[.]dae$/, '.skp')
      defn.save_as(skp)
      defn.entities.clear!

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

      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,
      Eugenio

      posted in Developers' Forum
      E
      eugenio_miolo
    • 1 / 1