10 Replies Latest reply on Nov 19, 2018 1:59 PM by Mirui Wang

    Traverse assembly to measure height of each component

    Mirui Wang

      Hi all,

       

      I am working on a printed circuit board project that want to measure the height relative to the PCB surface.

       

      PCA'd CAD is build by Circutworks by the way.

       

      Anyone know similar api that works?

       

      First challange is to seperate components that at top surface and bottom surface, this can be done by check their coordinates. bottom parts will have negative value at z direction.

       

      Second problem is that, how to measure each component's height relative to a specific surface.

      Case 1: componets that has CWX cordinates. This is the idea case because it has a coordiate, which make measurement easy. Just need measure the max distance at Z direction. (Componets could be signle part, or assembly)

      Case 2: componets that does not have CWX cordinates, need to figure out which side is the Z direction. This part I have no idea how to do it.

        • Re: Traverse assembly to measure height of each component
          Mandar Parkhi

          Check if you can get bounding boxes or centre of mass of all components in assembly. Then you can segregate.

          • Re: Traverse assembly to measure height of each component
            Artem Taturevych

            Just an addition to comments above regarding the precision on bounding box. Take a look at this example which demonstrates the possible issue with bounding box and the way to solve it: Create Precise Bounding Box

            • Re: Traverse assembly to measure height of each component
              William Cruz

              I don't know what language you use but this is what I use - I build my own box.

               

              private double[] GetCompBox(Component2 swConcComp)
                      {
                          double[] CompBox = new double[] { 0, 0, 0 };
                          try
                          {
                              if (swConcComp != null)
                              {
                                  object vBodyInfo = null;
                                  object[] vBodies = (object[])swConcComp.GetBodies3((int)swBodyType_e.swSolidBody/*.swAllBodies*/, out vBodyInfo);
              
                                  if (vBodies != null)
                                  {
                                      /*get base body*/
                                      Body2 b2 = vBodies[0] as Body2;
              
                                      if (b2 != null)
                                      {
                                          /*get all faces from this body*/
                                          object[] objFaces = b2.GetFaces();
              
                                          if (objFaces != null)
                                          {
                                              double xL, xR, yB, yT, zN, zF;
              
                                              /*bottom left*/
                                              xL = 0;
                                              yB = 0;
                                              zN = 0;
              
                                              /*top right*/
                                              xR = 0;
                                              yT = 0;
                                              zF = 0;
              
                                              /*get bottom left coords*/
                                              int intCounter = 0;
                                              foreach (var swface in objFaces)
                                              {
                                                  if (swface is Face2)
                                                  {
                                                      Face2 f2u = swface as Face2;
              
                                                      double[] facebox = (double[])f2u.GetBox();
              
                                                      if (intCounter != 0)
                                                      {
                                                          xL = facebox[0] < xL ? facebox[0] : xL;/*left*/
                                                          yB = facebox[1] < yB ? facebox[1] : yB;/*bottom*/
                                                          zN = facebox[2] < zN ? facebox[2] : zN;/*near*/
                                                      }
                                                      else
                                                      {
                                                          xL = facebox[0];
                                                          yB = facebox[1];
                                                          zN = facebox[2];
                                                      }
              
                                                      intCounter++;
                                                  }
                                              }
              
                                              /*reset*/
                                              intCounter = 0;
              
                                              /*get top right coords*/
                                              foreach (var swface in objFaces)
                                              {
                                                  if (swface is Face2)
                                                  {
                                                      Face2 f2u = swface as Face2;
              
                                                      double[] facebox = (double[])f2u.GetBox();
              
                                                      if (intCounter != 0)
                                                      {
                                                          xR = facebox[3] > xR ? facebox[3] : xR;/*right*/
                                                          yT = facebox[4] > yT ? facebox[4] : yT;/*top*/
                                                          zF = facebox[5] > zF ? facebox[5] : zF;/*far*/
                                                      }
                                                      else
                                                      {
                                                          xR = facebox[3];
                                                          yT = facebox[4];
                                                          zF = facebox[5];
                                                      }
              
                                                      intCounter++;
                                                  }
                                              }
              
                                              CompBox = new double[] { xL, yB, zN, xR, yT, zF };
                                          }
                                      }
                                  }
                              }
              
                              return CompBox;
                          }
                          catch (Exception ex)
                          {                
                              return CompBox;
                          }
                      }