Need to place the loaded component with my courser and place on a click

mousebuttons
sketchup
ruby
downloading
toolbar

#1

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
indent preformatted text by 4 spaces


How to Import file.skp in a model?
#2

#3

A local SKP filepath is not a remote location specified by URL.

For local files use: Sketchup::DefinitionList#load()

To interactively place components, use …

instead of …


#4

Example “InsertLocalComponent” command:

place_component_command.rb (1.9 KB)

… which looks like …

# encoding: UTF-8

module Author # <---<<< change to something unique
  module InsertLocalComponent

    extend self

    WIN =(Sketchup.platform == :platform_win rescue RUBY_PLATFORM !~ /darwin/i)
    OPEN_CAPTION ||= 'Choose Component ...'
    
    TOOLBAR_NAME ||= 'Component Menu'
    CMD_NAME     ||= {}
    CMD_NAME[:pc1]= 'Place Component'

    @@loaded ||= false
    @@cmd    ||= {}
    @@cdpath ||= "D:/"
    @@skp    ||= "asd.skp"

    def place_component_1()
      #
      if WIN
        # If an error occurs finding the directory path,
        # Windows will open in the directory last used.
        # If the 3rd filter argument is used, Windows
        # will open in the directory last used for the filter,
        # and ignore the second directory path argument.
        filepath = UI.openpanel(OPEN_CAPTION,File.join(@@cdpath,'*.skp'))
      else
        filepath = UI.openpanel(OPEN_CAPTION,@@cdpath,@@skp)
      end
      return unless filepath
      #
      mod = Sketchup::active_model
      # Creates a "Load Component" undo operation:
      cdef = mod.definitions.load(filepath)
      cdef ? @@cdpath=File.dirname(filepath) : return
      #
      # Model#place_component() creates it's own undo operation
      # that CANNOT be wrapped in a Sketchup::Model#start_operation.
      mod.place_component(cdef)
      #
    end


    if !@@loaded # RUN ONCE CODE:

      @@toolbar ||= UI::Toolbar.new(TOOLBAR_NAME)

      name = CMD_NAME[:pc1]
      cmd = @@cmd[:pc1] ||= UI::Command.new(name) {
        place_component_1()
      }
      cmd.small_icon = ""
      cmd.large_icon = ""
      cmd.tooltip   = name
      cmd.menu_text = name
      cmd.status_bar_text = name

      @@toolbar.add_item(@@cmd[:pc1]) unless @@toolbar.include?(@@cmd[:pc1])
      @@toolbar.show if @@toolbar.get_last_state != TB_HIDDEN

      @@loaded = true
    end

  end
end

#5

thank you so much helps lot


#7

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