2 Replies Latest reply on Apr 25, 2018 7:44 PM by John Alexander

    Get Centermark from DisplayDimension

    John Alexander

      I'm trying to detect when a particular Centermark has a dimension attached to it.

       

       

      I've written the following (incomplete) function that I would like to return true when swDisplayDimension is attached to swCenterMark.

       

               private bool IsAttachedToCenterMark(DisplayDimension swDisplayDimension, CenterMark swCenterMark){

                   Annotation swAnnotation = (Annotation)(swDisplayDimension.GetAnnotation());

                   if(swAnnotation !=  null){

                       object[] oEntities  = (object[])(swAnnotation.GetAttachedEntities3());

                       int[] entityTypes = (int[])(swAnnotation.GetAttachedEntityTypes());

                       for(int i = 0; i < oEntities.Length; i++){

                           object oEntity = oEntities[i];

                           int entityType = entityTypes[i];

                           if(entityType == (int)swSelectType_e.swSelEXTSKETCHSEGS){

                               //This appears to be the value that is returned for centermarks, I'm interpreting this to mean "Extension Line"

                               SketchSegment swSketchSeg = (SketchSegment )oEntity;

                               swSketchSeg.Select4(false,null);

                               //I'm not sure what to do with this from here. Selection doesn't reveal what this is.

                           }else if(entityType == (int)swSelectType_e.swSelEDGES){

                               Entity attachedEntity = (Entity)oEntity;

                               attachedEntity.Select4(false, null);

                               //When I put the breakpoint here, I can observe that it successfully selects the edge.

                           }

                       }

                   }

                   return false;

               }

       

      When I put the breakpoint in the swSelEDGES block, it successfully selects that edge.

       

      What I can't figure out is whether or not the dimension's Extension line is being returned or if the CenterMark's line is being returned and it just decides to call it a swSelEXTSKETCHSEGS. Also, in either case, I have no idea how I'm going to go from either of those objects to the CenterMark in question without using some ugly selection Manager stuff.

       

       

      I've looked through the API documentation for CenterMark, Annotation, Dimension, DisplayDimension, SketchSegment, and I'm not finding anything promising. Does anyone have any ideas?

        • Re: Get Centermark from DisplayDimension
          John Alexander

          So this is what I came up with. The workflow is a little bit different than the original post - I couldn't find a method that doesn't rely on selection.

           

          It seems to work reliably, albeit slowly because of the selection calls.

           

          There is more context in the attached C# class.

           

                   private List<Surface> GetSurfacesForDisplayDimension(DisplayDimension swDisplayDimension, View swView){

                       List<Surface> swSurfaces = new List<Surface>();

                      

                       double[] viewPosition = (double[])swView.Position;

                       Annotation swAnnotation = (Annotation)(swDisplayDimension.GetAnnotation());

                       swAnnotation.Select3(false,null);

                      

                       if(swAnnotation !=  null){

                           object[] oEntities  = (object[])(swAnnotation.GetAttachedEntities3());

                           int[] entityTypes = (int[])(swAnnotation.GetAttachedEntityTypes());

                           for(int i = 0; i < oEntities.Length; i++){

                               object oEntity = oEntities[i];

                               int entityType = entityTypes[i];

                              

                               if(entityType == (int)swSelectType_e.swSelEXTSKETCHSEGS){

                                   SketchSegment swSketchSeg = (SketchSegment )oEntity;

                                   Curve swCurve = (Curve)swSketchSeg.GetCurve();

                                   if(swCurve.IsLine()){

                                       SketchLine swSketchLine = (SketchLine)swSketchSeg;

                                       SketchPoint swSketchPointStart = (SketchPoint)swSketchLine.GetStartPoint2();

                                       SketchPoint swSketchPointEnd = (SketchPoint)swSketchLine.GetEndPoint2();

                                       double midPointX = ((swSketchPointStart.X + swSketchPointEnd.X) / 2) * swView.ScaleDecimal + viewPosition[0];

                                       double midPointY = ((swSketchPointStart.Y + swSketchPointEnd.Y) / 2) * swView.ScaleDecimal + viewPosition[1];

                                       double midPointZ = ((swSketchPointStart.Z + swSketchPointEnd.Z) / 2) * swView.ScaleDecimal;

                                      

                                       swModel.ClearSelection2(true);

                                       bool selectionSuccess =swModel.Extension.SelectByID2("", "CENTERMARKS", midPointX, midPointY, midPointZ, false, -1, null, 0);

                                       if(!selectionSuccess){

                                           selectionSuccess = swModel.Extension.SelectByID2("", "CENTERMARKSYMS", midPointX, midPointY, midPointZ, false, -1, null, 0);

                                       }

                                       if(selectionSuccess){

                                           for(int j = 1; j <= ((SelectionMgr)swModel.SelectionManager).GetSelectedObjectCount2(-1); j++){

                                               object selectedObject = ((SelectionMgr)swModel.SelectionManager).GetSelectedObject6(j,-1);

                                               if((((SelectionMgr)swModel.SelectionManager).GetSelectedObjectType3(j,-1) == (int)swSelectType_e.swSelCENTERMARKS) | (((SelectionMgr)swModel.SelectionManager).GetSelectedObjectType3(j,-1) == (int)swSelectType_e.swSelCENTERMARKSYMS)){

                                                   if(selectedObject != null){

                                                       double[] ArrayDataIn = new double[3]{midPointX, midPointY, midPointZ};

                                                       MathPoint midPoint = (MathPoint)swMathUtil.CreatePoint(ArrayDataIn);

                                                      

                                                       swSurfaces.Add(GetHoleSurfaceCenteredOnPoint(midPoint, (CenterMark)selectedObject, swView));

                                                       //return GetHoleSurfaceCenteredOnPoint(midPoint, (CenterMark)selectedObject, swView);

                                                   }

                                               }

                                           }

                                       }

                                       swModel.ClearSelection2(true);

                                   }

                               }else if(entityType == (int)swSelectType_e.swSelEDGES){

                                   //this is the edge that the hole is dimensioned with respect to!

                                   //For the time being, we don't use it but we should do some further analysis in the future to

                                   //determine whether or not it is a datum or a fully constrained edge/surface.

                                  

                                   //Entity attachedEntity = (Entity)oEntity;

                                   //attachedEntity.Select4(false, null);

                               }

                           }

                       }

                       return swSurfaces;

                   }

                  

          private Surface GetHoleSurfaceCenteredOnPoint(MathPoint checkPoint, CenterMark swCenterMark, View swView){

                       Annotation swAnnotation = swCenterMark.GetAnnotation();

                       double checkPointX = ((double[])checkPoint.ArrayData)[0];

                       double checkPointY = ((double[])checkPoint.ArrayData)[1];

                       double checkPointZ = ((double[])checkPoint.ArrayData)[2];

                       object[] oEntities = (object[])(swAnnotation.GetAttachedEntities3());

                       int[] entityTypes = (int[])(swAnnotation.GetAttachedEntityTypes());

                       for(int i = 0; i < swAnnotation.GetAttachedEntityCount3(); i++){

                           int entityType = entityTypes[i];

                           if(entityType == (int)swSelectType_e.swSelEDGES){

                               object oEntity = oEntities[i];

                               Edge swEdge = (Edge)oEntity; //there is a good chance that htis will throw, it seems to be stable so far.

                               Surface swSurface = GetHoleSurfaceFromEdge(swEdge);

                               if(swSurface != null){

                                   Curve swCurve =(Curve)swEdge.GetCurve();

                                   if(swCurve.IsCircle()){

                                       MathPoint position = GetPosition(swCurve);

                                       position = (MathPoint)position.MultiplyTransform((MathTransform)swView.ModelToViewTransform);

                                       double testPointX = ((double[])position.ArrayData)[0];

                                       double testPointY = ((double[])position.ArrayData)[1];

                                       double testPointZ = ((double[])position.ArrayData)[2];

                                       if(IsEpsilonEqual(testPointX, checkPointX) && IsEpsilonEqual(testPointY, checkPointY) && IsEpsilonEqual(testPointZ, checkPointZ)){

                                           return swSurface;

                                       }

                                   }

                               }

                           }

                       }

                       return null;

                   }