0 Replies Latest reply on Sep 13, 2013 2:12 PM by Hersh Sridhar Iyer

    Add Datum to Dimensions - Alignment Issues

    Hersh Sridhar Iyer



      I am trying to add a datum to a dimension. In the UI I would do this by just selecting the dimension and adding a Datum object. The datum automatically snaps to the dimension as shown in the image attached (datumDimensionSnap.jpeg).


      When I try to do the same thing using the API, the datum snaps to 0,0 and fails to move.


      Here is the method I am using. All its doing is getting a displayDimension's location and adding the datum to it at a location offset by 0.1 on the Y. Assume this is being added for vertical dimension.


      public static bool AddDatumToDimension(DisplayDimension dispDim, String datumTag, ModelDoc2 swModel, string viewName)


                  SolidWorks.Interop.sldworks.Dimension dim = dispDim.GetDimension();

                  Annotation dispannotation = dispDim.GetAnnotation();

                  double[] loc = dispannotation.GetPosition();

                  string dimId = dim.FullName;

                  bool status = swModel.Extension.SelectByID2(dimId, MCADConstants.DIMENSION, 0, 0, 0, false, 0, null, 0);

                  if (!status)


                      return false;




                      DatumTag myDatumTag = null;

                      if (status)


                          Annotation myAnnotation = null;

                          myDatumTag = ((DatumTag)(swModel.InsertDatumTag2()));

                          if ((myDatumTag != null))


                              myDatumTag.FilledTriangle = true;

                              myDatumTag.Shoulder = false;

                              bool boolstatus = myDatumTag.SetLabel(datumTag);

                              myAnnotation = ((Annotation)(myDatumTag.GetAnnotation()));


                              status = myAnnotation.SetPosition(loc[0], loc[1]+0.1, loc[2]);




                      return status;




      Please advise. Is there any other way to attach a datum to the dimension?