Hierarchy when importing a dynamic component into the outliner

Greetings, Ruby and programming are not all good. So I apologize for the trivial questions.

I’m making a primitive plugin to import dynamic components, from 3dwarhouse. Faced with the fact that, when imported into the scene - it goes nested in the structure. That can be seen in the screenshot.


What method is more correct to use, that the dynamic component was imported correctly.

I’m not sure what the problem is. Dynamic Components contain child-components. That is how the Dynamic Component plugin is designed.

no, if i open local skp i have this structure


if i import skp, or use api import i have parent level, and in child dc

upd: after import create parent level “model(number)”

Opening and loading are not the same thing. Loading adds the file as a component into the existing model, opening makes the file the open document.

I’m not sure where Model(4) comes from. Are you inside of a component when placing the Dynamic Component?

No, I am in an empty project.
Maybe I’m using the wrong method to import a dynamic component. I have them stored in skp, on an external server. My task is to import it so that the user can open the configuration window and configure it.

Right now, when importing, the component goes into a non-existent level. And it’s understandable that the component settings aren’t there, as they are on the wrong level.

Can you share your code for placing the component instance? Your image ends at loading the definition into the model’s DefinitionList.

class LoadHandler
  attr_accessor :error

  def onPercentChange(percent)
    Sketchup::set_status_text("loading: #{percent.round}%")
  end

  def cancelled?
    # You could, for example, show a messagebox after X seconds asking if the
    # user wants to cancel the download. If this method returns true, then
    # the download cancels.
    return false
  end

  def onSuccess
    Sketchup::set_status_text('')
  end

  def onFailure(error_message)
    self.error = error_message
    Sketchup::set_status_text('')
  end
end

# Replace this with a real URL...
url = "link"
model = Sketchup.active_model
load_handler = LoadHandler.new
definition = model.definitions.load_from_url(url, load_handler)
return unless definition # good practice

model.place_component(definition)
if definition.nil?
  puts "Error: #{load_handler.error}"
end

It looks as if you’ve gone into a component named “Mode(4)” before calling this code.

No, the list of actions is like this:
I open program
Create a new default project
Call the code

The code I provided is all of it. No more variables or calls. Similarly I don’t see any mention in the documentation that the imported object will be placed in some kind of level structure.

From there, the component goes like this. The same thing happens if you import simple models from 3dwarhouse. There they are also created by a sub-level, but there at least the level is available as a model name and it made me think that not quite the right method is used.

Oh, I got confused by the extra nesting level inside of your file and thought it corresponded to the file.

Model(4) simply corresponds to the file you imported. By default the component name matches the file name, but you can also set a custom component name for a file in Window > Model Info > File. If you open the file and empty this field, the name will match the file name when importing the component.

Yes, now I see that it is the name of the file and it will be the parent in the hierarchy when imported. Then the question is how to pass a dynamic component through the api, so that when imported into the project, it would pass the correct structure in the hierarchy.

Since the component settings are below, after the import.

It looks like the error lies in the file you are trying to load. This file doesn’t need an extra wrapping level. You can select the Dynamic Component inside a parent SketchUp model, right click it and select Save As to save it out.

1 Like

snx wery much, it’s work
after i import with ruby api imported normal