# Import .dae failed on ruby extension

**URL:** <https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154>\
**Category:** Ruby API\
**Tags:** import, dae, ruby, collada\
**Created:** [March 24, 2021, 2:05pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154 "2021-03-24T14:05:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattda909](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mattda909](https://forums.sketchup.com/u/mattda909)\
**Post date:** [March 24, 2021, 2:05pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/1 "2021-03-24T14:05:24Z")

</div>

Hello,  
I try to import .dae file generated by Sketchup via ruby extension but i get error “Import failed”  
My error is not due to my dae files, (i export them from Sketchup). It’s specific to my ruby code extension i think.

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [March 24, 2021, 2:23pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/2 "2021-03-24T14:23:27Z")

</div>

Good to know…  
…and do you have a question? 😇

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [March 24, 2021, 2:29pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/3 "2021-03-24T14:29:16Z")

</div>

Can you provide a sample model and some simple code that reproduce this? Otherwise it’s very hard to guess at what might be going on.

Also, what SketchUp version and platform are you seeing this on?

---

<div class="post-metadata">

**Author:** ![mattda909](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mattda909](https://forums.sketchup.com/u/mattda909)\
**Post date:** [March 24, 2021, 2:59pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/4 "2021-03-24T14:59:01Z")

</div>

```
model=Sketchup.active_model
model.start_operation('DAE import', true)
dae="one_stair.dae"
imp = model.import(dae, false)
Sketchup.send_action('selectSelectionTool:')
defn=model.definitions[-1]
inst=model.active_entities.add_instance(defn, ORIGIN)
defn.name=File.basename(dae, ".*") 
defn.description="Imported from DAE" 
defn.entities.clear! 

```

Here is my code

---

<div class="post-metadata">

**Author:** ![mattda909](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mattda909](https://forums.sketchup.com/u/mattda909)\
**Post date:** [March 24, 2021, 3:00pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/5 "2021-03-24T15:00:09Z")

</div>

My OS: Windows  
Sketchup Version: 2021

---

<div class="post-metadata">

**Author:** ![mattda909](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mattda909](https://forums.sketchup.com/u/mattda909)\
**Post date:** [March 24, 2021, 3:02pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/6 "2021-03-24T15:02:26Z")

</div>

How to import .dae files on sketchup via ruby’s code?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 24, 2021, 3:08pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/7 "2021-03-24T15:08:02Z")

</div>

> [@mattda909](#):
>
> ```ruby
> Sketchup.send_action('selectSelectionTool:')
> 
> ```

Try **not** to use send actions in automated code. (It is mainly for toolbar buttons.)

To activate the SelectionTool, instead use:

```ruby
Sketchup.active_model.select_tool(nil)

```

_REF:_

- [`Sketchup::Model#select_tool()`](https://ruby.sketchup.com/Sketchup/Model.html#select_tool-instance_method)

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 24, 2021, 3:18pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/8 "2021-03-24T15:18:10Z")

</div>

> [@mattda909](#):
>
> `dae="one_stair.dae"`

I **do not** have this file in the current directory path of my active hard drive, so when I run your code, I **also** get the “Import failed” messagebox.

In Ruby, if you do not specify an absolute path, then file operations will default to using the current directory path, which is …

```ruby
Dir.pwd

```

So a simple test is …

```ruby
File.exist?(dae)

```

… to which I get `false` on my system.

**So you must pass an valid absolute pathname to an existing `dae` file.**

… OR you can **temporarily** change the directory to where you know the `dae` file resides …

```ruby
Dir.chdir(my_exports) {
  imp = model.import(dae, false)
}
```

---

<div class="post-metadata">

**Author:** ![mattda909](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mattda909](https://forums.sketchup.com/u/mattda909)\
**Post date:** [March 24, 2021, 3:52pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/9 "2021-03-24T15:52:24Z")

</div>

Thanks, i dont have any error message, but i cant see model on sketchup, here the new code

> ```
> model=Sketchup.active_model
> model.start_operation('DAE import', true)  
> dae="one_stair.dae"
> Dir.chdir("C:/Users/mattda/Documents/test_dae") {
> imp = model.import(dae, false)
> print(dae)
> }
> Sketchup.active_model.select_tool(nil)
> defn=model.definitions[-1]
> inst=model.active_entities.add_instance(defn, ORIGIN)
> defn.name=File.basename(dae, ".*") # or any other name
> defn.description="Imported from DAE" # or other text
> defn.entities.clear! 
> model.commit_operation
> 
> ```

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 24, 2021, 4:31pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/10 "2021-03-24T16:31:58Z")

</div>

No one will be able to test unless you post the `dae` test file.

---

<div class="post-metadata">

**Author:** ![mattda909](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mattda909](https://forums.sketchup.com/u/mattda909)\
**Post date:** [March 24, 2021, 4:48pm UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/11 "2021-03-24T16:48:17Z")

</div>

[one\_stair.zip](https://forums.sketchup.com/uploads/short-url/bNTKiY7WkxtFit8f4CnYqYUfwy1.zip) (1.2 MB)  
The dae test file

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [March 25, 2021, 9:07am UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/12 "2021-03-25T09:07:49Z")

</div>

> [@mattda909](#):
>
> ```auto
> dae="one_stair.dae"
> Dir.chdir("C:/Users/mattda/Documents/test_dae") {
> imp = model.import(dae, false)
> print(dae)
> }
> 
> ```

You can give a full path of the file like this as well e.g.:

```auto
dae="C:/Users/mattda/Documents/test_dae/one_stair.dae"

```

Since you are on SU2021, you should use the option hash as described here:  
[Model.import-instance\_method](https://ruby.sketchup.com/Sketchup/Model.html#import-instance_method)  
and the options of the different file types you can find here: [file.importer\_options](https://ruby.sketchup.com/file.importer_options.html). So for `dae` is like this:

```auto
options = { :validate_dae => true,
            :merge_coplanar_faces => true,
            :show_summary => true }

```

Therefor the import method should look like :

```auto
imp = model.import(dae, options)

```

> [@mattda909](#):
>
> `Sketchup.active_model.select_tool(nil)`

I have no idea why you are selecting the Select tool, but there is no influence to the import is fail or not…

> [@mattda909](#):
>
> `defn.entities.clear! `

The [#clear! method](https://ruby.sketchup.com/Sketchup/Entities.html#clear!-instance_method) is used to remove all entities from the collection of entities. Meaning that, you are clearing all of the entities of the imported component definition and you will get an empty component instance too. Actually an imported component is there, but without any geometry in it.  
Therefore you will see nothing in a modell. However you can still “hunt” for it in Outliner or in a Component tray.  
I would remove this line from the code.  
\_\_  
\_\_  
As a summary this code snippet should work if the `one_stair.dae` file there and the `moquette.jpg` is in a subfolder of `one_stair` like:  
 ![image](https://global.discourse-cdn.com/sketchup/original/3X/8/b/8b8ed010e33ca080643ab987cce9f5c4a5e76f7d.png)

```auto
model=Sketchup.active_model
model.start_operation('DAE import', true)  
dae="C:/Users/mattda/Documents/test_dae/one_stair.dae"
options = { :validate_dae => true,
            :merge_coplanar_faces => true,
            :show_summary => true }
imp = model.import(dae, options)

# What is this for?
Sketchup.active_model.select_tool(nil)

defn=model.definitions[-1]
defn.name=File.basename(dae, ".*") # or any other name
defn.description="Imported from DAE" # or other text
inst=model.active_entities.add_instance(defn, ORIGIN)

# Do not remove the entities!
#defn.entities.clear! 

model.commit_operation
```

---

<div class="post-metadata">

**Author:** ![mattda909](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mattda909](https://forums.sketchup.com/u/mattda909)\
**Post date:** [March 25, 2021, 9:37am UTC](https://forums.sketchup.com/t/import-dae-failed-on-ruby-extension/158154/13 "2021-03-25T09:37:00Z")

</div>

Yeah it’s work the code

> model=Sketchup.active\_model  
> model.start\_operation(‘DAE import’, true)  
> dae=“C:/Users/mattda/Documents/test\_dae/one\_stair.dae”  
> options = { :validate\_dae =\> true,  
> :merge\_coplanar\_faces =\> true,  
> :show\_summary =\> true }  
> imp = model.import(dae, options)
> 
> #It’s for deactivate the manual positionning of the imported model  
> Sketchup.active\_model.select\_tool(nil)
> 
> defn=model.definitions[-1]  
> inst=model.active\_entities.add\_instance(defn, ORIGIN)  
> defn.name=File.basename(dae, “.\*”) # or any other name  
> defn.description=“Imported from DAE” # or other text  
> model.commit\_operation
