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

    How to get a selected object center?

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 134 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.
    • M Offline
      Mcdull
      last edited by

      I Want to get a object center point, the object may be a mesh,face,or group.my method is

        UI.add_context_menu_handler do |context_menu|
         context_menu.add_separator
         context_menu.add_item("center point") {
      
          model = Sketchup.active_model
          entities = model.active_entities
          first_entity = entities[0]
          bbx=first_entity.bounds
      #    selection = model.selection
      #
      #          selection.each { |entity|
      #              $boundbox = entity.model.bounds
      #              UI.messagebox($boundbox.corner 0)
      #               UI.messagebox($boundbox.corner 1)
      #
      #              }
      #  puts selection.count
      #  puts $boundbox.center
      puts bbx.center.to_s
      

      but the result is always the same,would tell me why? thank u

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        because you are finding the bounding box for the first entitiy in the list of entities. What you want is to find the bounding box of the first entitiy in the selection set I would bet.

        model = Sketchup.active_model sel = model.selection first_entity = sel[0]

        try that

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • M Offline
          Mcdull
          last edited by

          @chris fullmer said:

          because you are finding the bounding box for the first entitiy in the list of entities. What you want is to find the bounding box of the first entitiy in the selection set I would bet.

          model = Sketchup.active_model sel = model.selection first_entity = sel[0]

          try that

          i got it ,thank u
          ~

          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