sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    FredoBend | Powerful new bending tool for SketchUp Download

    Context Menu Question

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

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better đź’—

          Register Login
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement