6 Replies Latest reply on May 12, 2017 6:31 PM by Amen Allah Jlili

    How to delete a IDisplayDimension

    Nikola Malesevic

      While editing the sketch, I create a new dimension, and later I want to delete it. However, the dimension is never selected and thus never deleted.

       

      private readonly IModelDoc2 _document;
      private readonly IModelDocExtension _extension;
      private SketchSegment _lineSplineTangent;
      private ISketchPoint _pointRight;
      private IDisplayDimension _dimensionHeight;
      
      private void CreateDimension()
      {
        _lineSplineTangent.Select(false);
        _pointRight.Select(true);
        _dimensionHeight = (IDisplayDimension)_document.AddVerticalDimension2(0, 0, 0);
      }
      
      private void DeleteDimension()
      {
        _document.ClearSelection2(true);
        _document.Extension.SelectByID2(_dimensionHeight.GetNameForSelection(), "DIMENSION", 0, 0, 0, false, 1, null, 0);
        _extension.DeleteSelection2();
      }
      

       

      How to select a dimension stored in IDisplayDimension object to be able to delete it?

        • Re: How to delete a IDisplayDimension
          Amen Allah Jlili

          Hi Nick!

           

          GetNameForSelection() returns the selection string for the selected dimension. It appears that you are clearing the selection list before invoking GetNameForSelection(). For that matter,  I think it's not returning the proper selection string. Can you debug print the selection string to double check this?


          Thanks,
          Amen

          CADHero.com

            • Re: How to delete a IDisplayDimension
              Nikola Malesevic

              Hi Amen.

               

              The string retrieved by GetNameForSelection() is "D4@Sketch1".

              GetNameForSelection() returns the selection string for the selected dimension.

              I am not sure that this is correct. We should retrieve the selection string with GetNameForSelection() in order to pass it to SelectByID2() and select the object. If the object is already selected, why bother calling these two functions? Am I right?

               

              I have also found the following in the documentation for SelectByID2():

              Specify "D1@Sketch2@Part1.SLDPRT" rather than simply "D1@Sketch2"; otherwise, this method could return false. If you do not know the object name, or if it is an item that is not automatically named by SOLIDWORKS, you can pass an empty string.

              When I hover over the dimension in SW, it says D4@Sketch1 of Part2^WorkpieceDevel2<2>

               

              What is the fully qualified name in this case that I should use and pass to SelectByID2() method?

               

              Thanks for help.

            • Re: How to delete a IDisplayDimension
              Nikola Malesevic

              Solved it by using dimension's annotation object to select the dimension itself. IAnnotation is a parent class of many, if not all, types of objects that are used for annotation, including IDisplayDimension.

               

              IAnnotation annotation = _dimensionHeight.GetAnnotation();
              annotation.Select(false);
              _extension.DeleteSelection2(0);