import DAE, place it to center and save SKP

import DAE, place it to center and save SKP

Postby stanDM » Fri Apr 06, 2018 11:41 am

Hi guys,

I am familiar with Python in C4D, but I was asked to do a small script for SketchUp, so I have to fight with Ruby and SketchUp itself :) So I apologize for some newbie questions:

I need to batch import DAE files and save it to SKP. I have found some sample scripts around here, so batch import is working fine. But after import, object does not get placed in scene, but I can find it in compoments.

Code: Select all
if file_ext==".dae"
    newFilePath = f + "/" + file_name + ".skp"
    Sketchup.active_model.import(File.join(f,d),false)
    Sketchup.active_model.save(newFilePath)
    entities.clear!
  end


Q1: Sketchup.active_model.save saves empty scene, which is expected, because model is not in the scene. Is there any way to place imported object to world center, make object active and save the scene?

Q2: upon import of DAE, can I change info of the component - like its name and description?

Thank a lot for your help.

Stan
0

stanDM 
 

Re: import DAE, place it to center and save SKP

Postby TIG » Sat Apr 07, 2018 3:48 pm

We are missing some of your code.
Here's a simplistic example to import dae, place an instance and export the definition...
Code: Select all
model=Sketchup.active_model
model
.start_operation('DAE import', true)
# block to ensure defn gets cleared on commit.
dae="full_path_to_file.dae"
model.import(dae, false)
# you can also assemble a hash to set options etc and pass that instead...
Sketchup.send_action('selectSelectionTool:')
# this activates another tool and stops manual placement option
defn=model.definitions[-1]
# this is the newest [unused] component definition
# We can place an instance with:
#inst=model.active_entities.add_instance(defn, ORIGIN)
# IF it's needed ! Remove inintial #
# BUT for now let's assume you don't want or need it !
defn.name=File.basename(dae, ".*") # or any other name
defn.description="Imported from DAE" # or other text
skp=dae.gsub(/[.]dae$/, '.skp')
# use .skp in lieu of .dae in file-name and 
defn.save_as(skp)
defn.entities.clear! # delete unwanted defn IF NO inst added
model.commit_operation
See API guidance pages, e.g.
http://ruby.sketchup.com/Sketchup/Model ... nce_method
http://ruby.sketchup.com/Sketchup/Compo ... ition.html
1
TIG
User avatar
TIG 
Global Moderator
 

Re: import DAE, place it to center and save SKP

Postby stanDM » Thu Apr 12, 2018 2:30 pm

Hi TIG,

sorry for the late reply - I have been busy finishing another project project. I have just tested your code and it works perfectly! Thank you million times!

Best regards,

Stan
0

stanDM 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 4 guests

Visit our sponsors: