• Login
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.
  • L Offline
    lbsswu
    last edited by 13 Jul 2012, 01:54

    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
    • T Offline
      thomthom
      last edited by 13 Jul 2012, 10:49

      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
      • T Offline
        TIG Moderator
        last edited by 13 Jul 2012, 12:11

        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
        • L Offline
          lbsswu
          last edited by 14 Jul 2012, 06:01

          @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
          • L Offline
            lbsswu
            last edited by 14 Jul 2012, 06:02

            @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
            1 / 1
            • First post
              2/5
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement