sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Context Menu Question

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 96 Views 2 Watching
    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

      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
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        
        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

          Thanks Dan that worked and was just what I needed.

          Keith

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

          Advertisement