How to Import file.skp in a model?


#1

Hy, I need import a premade model in a determinate position. How do it?
This is the premade model link https://3dwarehouse.sketchup.com/model/8b897767f783df7c7bb6b7c16e3a2cab/Router-D-link


#2

@DanRathbun @eneroth3 help me please


#3

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.


#4

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


#5

… 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.


#6

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.


#7

thanks


#8

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

#9

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 )
)


#10

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


#11

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 )
)

#12

In the post above I clearly said …

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


#13

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.


#14

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


#15
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 )
)

#16
Sketchup.active_model.place_component(cdef)

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


#17

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


#19

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