# Unable to load component to the file from installed folder

**URL:** <https://forums.sketchup.com/t/unable-to-load-component-to-the-file-from-installed-folder/63219>\
**Category:** Ruby API\
**Tags:** sketchup, import, components\
**Created:** [March 2, 2018, 11:05am UTC](https://forums.sketchup.com/t/unable-to-load-component-to-the-file-from-installed-folder/63219 "2018-03-02T11:05:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![levies4design](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@levies4design](https://forums.sketchup.com/u/levies4design)\
**Post date:** [March 2, 2018, 11:05am UTC](https://forums.sketchup.com/t/unable-to-load-component-to-the-file-from-installed-folder/63219/1 "2018-03-02T11:05:08Z")

</div>

Continuing the discussion from [How to Import file.skp in a model?](https://forums.sketchup.com/t/how-to-import-file-skp-in-a-model/57427/18):

i have created a rbz file that contain my rb file and component folder all the content in the file is unloading on the following link

" \THIS PC\AppData\Roaming\SketchUp\SketchUp 2017\SketchUp\Plugins\standard\_module\standard\_module\kitchen"

the component is not loading from this location for the given code  
instead it loading from following location

C:\ProgramData\SketchUp\SketchUp 2017\SketchUp\standard\_module\standard\_module\kitchen…

```ruby
kitchentool = UI::Toolbar.new "KITCHEN WITH HANDLE COMPONENT demo v2.2 "

KBU1DR = UI::Command.new("KBU1DR") {

	path = Sketchup.find_support_file "KBU1DR.skp",
	"standard_module/kitchen/"
	model = Sketchup.active_model
	definitions = model.definitions
	KBU1DR = model.definitions.load path
	model.place_component(KBU1DR)
	
}
KBU1DR.small_icon = "kitchen/icon/KBU1DR.png"
KBU1DR.large_icon = "kitchen/icon/KBU1DR.png"
KBU1DR.tooltip = "KBU1DR"
KBU1DR.status_bar_text = "KITCHEN BASE 1 DRAWER UNIT"
KBU1DR.menu_text = "KITCHEN BASE 1 DRAWER UNIT"
kitchentool = kitchentool.add_item KBU1DR
kitchentool.show

```

kindly help out

---

<div class="post-metadata">

**Author:** ![john\_drivenupthewall](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@john\_drivenupthewall](https://forums.sketchup.com/u/john_drivenupthewall)\
**Post date:** [March 2, 2018, 11:19am UTC](https://forums.sketchup.com/t/unable-to-load-component-to-the-file-from-installed-folder/63219/2 "2018-03-02T11:19:09Z")

</div>

add your .rbz so we can check it…

john

---

<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 2, 2018, 4:06pm UTC](https://forums.sketchup.com/t/unable-to-load-component-to-the-file-from-installed-folder/63219/3 "2018-03-02T16:06:12Z")

</div>

Please **do not** create duplicate posts !  
(_The Moderator has removed the duplicate post in the linked topic thread_.)

* * *

Your problem comes from using [**`Sketchup::find_support_file`**](http://ruby.sketchup.com/Sketchup.html#find_support_file-class_method),  
which is for searching the **application’s** support directories, **not** appdata directories.

* * *

Use the Ruby global [**` __dir__ `**](http://ruby-doc.org/core-2.2.4/Kernel.html#method-i- __dir__ ) method along with Ruby [**`File::join`**](http://ruby-doc.org/core-2.2.4/File.html#method-c-join) method.

Also, **always** test for valid paths **before** using them.

```ruby
  filename = "KBU1DR.skp" 
  path = File.join( __dir__ , "standard_module/kitchen", filename )
  if File.exist?(path)
    model = Sketchup.active_model
    definitions = model.definitions
    @kbu1dr = model.definitions.load( path )
    if @kbu1dr # nil if the definition could not load
      model.place_component(@kbu1dr)
    else
      UI.messagebox(
        "Error: Could not load component: \"#{File.basename(filename,".*")}\""
      )
    end
  else
    UI.messagebox(
      "Error: Could not find file: \"#{filename}\" at path:\n\"#{File.dirname(path)}\""
    )
  end

```

Your example has an error where you assign a **constant** reference `KBU1DR` to the command, but then in it’s execute block you assign a definition reference to the same constant name. Temporary references should **never** be constants. They should be local or instance variables.

---

<div class="post-metadata">

**Author:** ![levies4design](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@levies4design](https://forums.sketchup.com/u/levies4design)\
**Post date:** [March 3, 2018, 4:32am UTC](https://forums.sketchup.com/t/unable-to-load-component-to-the-file-from-installed-folder/63219/4 "2018-03-03T04:32:18Z")

</div>

sorry i created a duplicate post won’t happen again…

thank you so much for the solution

can you share some link where i can learn more about ruby starting from basic

---

<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 3, 2018, 6:30am UTC](https://forums.sketchup.com/t/unable-to-load-component-to-the-file-from-installed-folder/63219/5 "2018-03-03T06:30:14Z")

</div>

> [@levies4design](#):
>
> can you share some link where i can learn more about ruby starting from basic

Way ahead of you. It is a pinned topic right here in this category …

> [@Ruby Learning Resources \[WikiLists\]](https://forums.sketchup.com/t/ruby-learning-resources-wikilists/22861):
>
> All seven of the lists below are set as wikis. card_index INDEX [notebook PRIMERS & GUIDES](http://forums.sketchup.com/t/ruby-learning-resources/22861/2)[books BOOKS](http://forums.sketchup.com/t/ruby-learning-resources/22861/3)[mortar_board TUTORIALS](http://forums.sketchup.com/t/ruby-learning-resources/22861/4)[card_box REFERENCE](http://forums.sketchup.com/t/ruby-learning-resources/22861/5)[clipboard TEMPLATES](http://forums.sketchup.com/t/ruby-learning-resources/22861/6)[newspaper NEWS](http://forums.sketchup.com/t/ruby-learning-resources/22861/7)[bulb IDEAS](http://forums.sketchup.com/t/ruby-learning-resources/22861/8)

---

<div class="post-metadata">

**Author:** ![levies4design](https://avatars.discourse-cdn.com/v4/letter/l/58956e/32.png) [@levies4design](https://forums.sketchup.com/u/levies4design)\
**Post date:** [March 3, 2018, 9:27am UTC](https://forums.sketchup.com/t/unable-to-load-component-to-the-file-from-installed-folder/63219/6 "2018-03-03T09:27:09Z")

</div>

Thank you gret help

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sketchup/original/3X/f/2/f2a121500b085ed60806607a82720b092d800bb3.png) [@system](https://forums.sketchup.com/u/system)\
**Post date:** [June 3, 2018, 1:27am UTC](https://forums.sketchup.com/t/unable-to-load-component-to-the-file-from-installed-folder/63219/7 "2018-06-03T01:27:11Z")

</div>

Closed on June 3, 2018, 1:27am UTC

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.
