Move an imported DWG component using ruby

Hello Everyone,
Can anyone suggest what should I do in order to move an imported DWG component using ruby. I used below ruby code to import the DWG file.

model = Sketchup.active_model
options = {       :import_materials => true,
                  :merge_coplanar_faces => true,
                  :orient_faces => true,
                  :preserve_origin => true,
                  :show_summary => true }
filepath = 'C:/Users/tks/Desktop/Outer Frame.dwg'
status = model.import(filepath, options)

The DWG file (Outer Frame.dwg) is imported successfully. Now I want to move the imported DWG at a specific coordinate. Let’s say point p1 => (15,15,20) is the location where I want to move the DWG now, but I’m not sure how to achieve that. Kindly suggest. Any suggestions are welcome.
Outer Frame.dwg (35.9 KB)

As the documentation is suggesting in Model #import method:

See DefinitionList#import for importing a 3d model file as a component definition, without activating the UI for placing an instance.

So if you replace the last line of your code to:

definition = model.definitions.import(filepath, options)

Then you can insert instance of the definition by using the Entities #add_instance method :

continue the code e.g:

entities = model.active_entities
point =, 15, 20)
transform =
instance = entities.add_instance(definition, transform)

you can also activate the UI and let the user place the instance (repeatedly, in the example) using: The Model #place_component method:

definition = model.definitions.import(filepath, options)
model.place_component(definition, true)

@dezmo Thank you so much!

1 Like