• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Context Menu Question

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 96 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    ktkoh
    last edited by 24 Apr 2012, 23:35

    For a context menu could I determine that the selection is a component within a parent component? I found the enity parent but can't figure out how determine that the parent is a component.

    Thanks Keith

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 25 Apr 2012, 03:11

      
      require('sketchup.rb')
      
      module K2K;;SomePlugin
      
        COMMAND_NAME = "Nested Component Command Title Here"
      
        class << self
        
          def nested_component_command(obj)
            #
            # command code here
            #
          end
        
        end # proxy class
      
        ### RUN ONCE
        #
        unless file_loaded?(File.basename(__FILE__))
        
          ### CONTEXT MENU HANDLER
          #
          UI.add_context_menu_handler do |popup|
      
            sel = Sketchup.active_model.selection
            unless sel.empty?
              if sel.single_object?
                obj = sel[0]
                if obj.is_a?(Sketchup;;ComponentInstance) &&
                obj.parent.is_a?(Sketchup;;ComponentDefinition)
                  popup.add_item(COMMAND_NAME) {
                    #
                    nested_component_command(obj)
                    #
                  }
                end # component test
              end # single_object?
            end # unless empty?
            
          end # add_context_menu_handler
        
          file_loaded(File.basename(__FILE__))
          
        end # RUN ONCE
        
      end # module
      
      

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • K Offline
        ktkoh
        last edited by 25 Apr 2012, 12:20

        Thanks Dan that worked and was just what I needed.

        Keith

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement