How to Import file.skp in a model?

Hy, I need import a premade model in a determinate position. How do it?
This is the premade model link Router D-link | 3D Warehouse

@DanRathbun @eneroth3 help me please

Learn to search the forum using the :mag: menu icon (at upper right. )

You’d find this topic where I answered this question 2 years ago …


For brevity in reading this thread, I’ll post some of that example code
with the 3DW url changes specific to this topic:

mod = Sketchup::active_model
url = "https://3dwarehouse.sketchup.com/model/8b897767f783df7c7bb6b7c16e3a2cab/Router-D-link"
cdef = mod.definitions.load_from_url(url)
return unless cdef # good practice
# could be "next unless cdef" inside a loop

point = Geom::Point3d::new( 10, 10, 0 )
cinst = mod.active_entities.add_instance(
  cdef,
  Geom::Transformation::new( point )
)

NOTE: The above example URL is not the actual working URL. (This is the link to the model’s 3DW page.) The real links can be found by clicking the “Download” button. The actual URLs have a SKP version parameter in them.

:information_source:

Coders should read the documentation for the Sketchup::DefinitionList#load_from_url method, and the explanation of how to write an abstract LoadHandler class for this method.

But in this way the panel opens. There is no way to do everything from code?

… in that example if you wish to load component definitions directly from the 3D Warehouse, then replace this line …

cdef = mod.definitions.load(skp)

… with these 2 lines …

url = "https://3dwarehouse.sketchup.com/model/8b897767f783df7c7bb6b7c16e3a2cab/Router-D-link"
cdef = mod.definitions.load_from_url(url)

NOTE: The above example URL is not the actual working URL. (This is the link to the model’s 3DW page.) The real links can be found by clicking the “Download” button. The actual URLs have a SKP version parameter in them.


@d.trepiccione93, you should read the documentation for the Sketchup::DefinitionList#load_from_url method, and the explanation of how to write an abstract LoadHandler class for this method.

1 Like

Do not use the openpanel lines …

skp = UI.openpanel("Import Model","","SketchUp Model (SKP)|*.skp||"))
return if skp.nil? # user cancelled

… as they are not needed.

thanks

1 Like

Hi
I want to load my model and to place where i click not on 3d point…

toolbar = UI::Toolbar.new "Component Menu"

cmd = UI::Command.new("Component") {
  mod = Sketchup::active_model
url = "D:/asd.skp"
cdef = mod.definitions.load_from_url(url)
return unless cdef 


point = Geom::Point3d::new( 10, 10, 0 )
cinst = mod.active_entities.add_instance(
  cdef,
  Geom::Transformation::new( point )
)

  UI.messagebox "loaded"
}
cmd.small_icon = ""
cmd.large_icon = ""
cmd.tooltip = "Component Toolbar"
cmd.status_bar_text = "Component"
cmd.menu_text = "running"
toolbar = toolbar.add_item cmd
toolbar.show

i’m unable to load directly from 3dWH… is it due to version change? i get
“Invalid component file”

mod = Sketchup::active_model
url = "https://3dwarehouse.sketchup.com/model/b57f1abb-e4ea-4958-8957-34900b401a32/BU-1-Drawer"
cdef = mod.definitions.load_from_url(url)
return unless cdef # good practice
# could be "next unless cdef" inside a loop

point = Geom::Point3d::new( 10, 10, 0 )
cinst = mod.active_entities.add_instance(
  cdef,
  Geom::Transformation::new( point )
)

How would I know what URL you have tried ? (ie, I cannot read minds …)


mod = Sketchup::active_model
url = "https://3dwarehouse.sketchup.com/model/b57f1abb-e4ea-4958-8957-34900b401a32/BU-1-Drawer"
cdef = mod.definitions.load_from_url(url)
return unless cdef # good practice
# could be "next unless cdef" inside a loop

point = Geom::Point3d::new( 10, 10, 0 )
cinst = mod.active_entities.add_instance(
  cdef,
  Geom::Transformation::new( point )
)

In the post above I clearly said …

… so no you cannot use the URL to the model display page as a download link.

from my notes …

KNOWN ERRORS from load_from_url() and the cause from 3DW:

"Invalid component file" - Caused by giving model html page url,
or the file type was not correct, or the file wasn’t found,
or the name param was set for Collada (DAE) ie, "&name=zip".

"Invalid component URL" - Giving wrong protocol like "ftp://",
or the version "&name=s#{integer}" was out of allowable range,
or the model id was invalid.

sorry i did’t understand before …
Now i got it
thank u so much

mod = Sketchup::active_model
url = "https://3dwarehouse.sketchup.com/warehouse/getpubliccontent?contentId=30c2129e-a8e5-4bdd-873d-a97d7cc5429f&fn=BMW_2002+%282%29.skp"
cdef = mod.definitions.load_from_url(url)
return unless cdef # good practice
# could be "next unless cdef" inside a loop

point = Geom::Point3d::new( 10, 10, 0 )
cinst = mod.active_entities.add_instance(
  cdef,
  Geom::Transformation::new( point )
)
Sketchup.active_model.place_component(cdef)

Will do this for you. please have a look at the documentation.

1 Like

Already answerd in his “sister” thread, complete with full example …

1 Like

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