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!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    How to get the center of a ComponentDefinition array?

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 132 Views 3 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.
    • lbsswuL Offline
      lbsswu
      last edited by

      I have an array of ComponentDefinition. I want to find the center of these ComponentDefinitions.

      Maybe I should find the union bounds of these ComponentDefinitions, but I did not find the way πŸ˜• ... Could any one help me?

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        I don't understand the question. ComponentDefinitions doesn't exist in modelspace - so I do not see how you would get the centre of a collection of definitions.

        Can you describe the abstract of what you are trying to do?

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          If you meant ComponentInstance then they each have bounds.
          Make a new empty bounding-box object [ bb], and then add each of the instance.bounds to that bb.add(instance.bounds).
          The center is bb.center.........

          TIG

          1 Reply Last reply Reply Quote 0
          • lbsswuL Offline
            lbsswu
            last edited by

            @thomthom said:

            I don't understand the question. ComponentDefinitions doesn't exist in modelspace - so I do not see how you would get the centre of a collection of definitions.

            Can you describe the abstract of what you are trying to do?

            I'm sorry I made a mistake, the type is not ComponentDefinition, but a Group. I use the following code:
            model = Sketchup.active_model;
            groups = [];
            model.definitions.each{|d| groups << d if d.group? }
            name = "left_head"
            pgrp = [];
            groups.each{|d| pgrp << d.instances[0] if d.instances[0].name==name }
            the type of gprp is Sketchup::Group.

            Actually, I want to get the center of a group with the group name "left_head", but there are several groups with the name "left_head", so I have to find the union bounding box of them.

            1 Reply Last reply Reply Quote 0
            • lbsswuL Offline
              lbsswu
              last edited by

              @tig said:

              If you meant ComponentInstance then they each have bounds.
              Make a new empty bounding-box object [ bb], and then add each of the instance.bounds to that bb.add(instance.bounds).
              The center is bb.center.........

              Thanks for your tip. I will test the code.

              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