14 Replies Latest reply on Mar 15, 2016 4:54 PM by Prarthana Bataju

    How to get sketch line information using dimension

    Saugat Kc

      I want to get sketch line information using dimension property. I was successful getting all sketch dimension values as well as sketch line information(start point, end point) separately using their own properties but I want to get a link between these two information for example if I have a dimension information, i should be able to get sketch information on which this dimension has been created. More details is shown in figure:

      dim.png

      Is there any way doing this. I was not able to get any concrete information from API as well.

        • Re: How to get sketch line information using dimension
          幸 柴 田

          I can't find the way to get line length directly too.

          But I think if you can get start point and end point, you can calculate length like below.

          sqrt(( end point x - start point x)^2+(end point y - start point y)^2)

          • Re: How to get sketch line information using dimension
            Artem Taturevych

            Try DisplayDimension::GetAnnotation and then Annotation::GetAttachedEntities3.

             

            Thanks,
            Atem

              • Re: How to get sketch line information using dimension
                Saugat Kc

                I will try and let you know if I can solve my problem with this. Thanx for stopping by

                • Re: How to get sketch line information using dimension
                  Saugat Kc

                  Ya it worked... thanx for your help

                  • Re: How to get sketch line information using dimension
                    Saugat Kc

                    Hello Artem,

                    There is a slight mistake on implementing correct dimension annotation. When I select the line segment after getting its entities, it is selecting following line segment rather than itself. for example.

                    err.png

                    When dimension L is selected, it is giving me red circled line as its line segment. Similarly when F is selected, it is giving blue circled as its line segment.

                    My implemented code is as follows:

                    public List<DimensionList> getSunpouData(Feature swFeature)

                            {

                                double value = 0.0;

                                DisplayDimension swDisplayDim = swFeature.GetFirstDisplayDimension();

                                List<DimensionList> ListDimension = new List<DimensionList>();

                     

                     

                                while (swDisplayDim != null)

                                {

                                    SolidWorks.Interop.sldworks.SketchSegment StartEndSegment = default(SolidWorks.Interop.sldworks.SketchSegment);

                     

                     

                                    Annotation swAnnotation = swDisplayDim.GetAnnotation();

                                    Dimension swDim = swDisplayDim.GetDimension();  //IT GETS CORRECT DIMENSION

                                   

                                    object[] annoEntities = swAnnotation.GetAttachedEntities3();

                                    var EntityType = swAnnotation.GetAttachedEntityTypes();

                                    int i = 0;

                     

                     

                                    foreach (object EntityObj in annoEntities)

                                    {

                                        if (EntityType[i] == 10) // ONLY FOR LINE SEGMENT AS ALL ANNOTATION DOES NOT PROVIDE POINT INFORMATION

                                        {

                                            StartEndSegment = (SolidWorks.Interop.sldworks.SketchSegment)EntityObj;

                                            StartEndSegment.Select(false);     //SELECT CIRCLED LINE SEGMENT.

                                            SolidWorks.Interop.sldworks.Sketch swSketch = StartEndSegment.GetSketch();

                                            SolidWorks.Interop.sldworks.SketchLine swSketchLine = (SolidWorks.Interop.sldworks.SketchLine)StartEndSegment;

                                            SolidWorks.Interop.sldworks.SketchPoint swSkStartPoint = swSketchLine.GetStartPoint2();   //CIRCLED LINE VERTICES ARE GIVEN

                                            SolidWorks.Interop.sldworks.SketchPoint swSkEndPoint = swSketchLine.GetEndPoint2();      //CIRCLED LINE VERTICES ARE GIVEN

                                        }

                                        i++;

                                    }

                     

                     

                                    value = swDim.GetSystemValue2("") * 1000;

                                    string swDimensionName = swDim.Name;

                                    ListDimension.Add(new DimensionList() { DimensionName = swDimensionName, DimensionValue = value});

                     

                     

                                    swDisplayDim = swFeature.GetNextDisplayDimension(swDisplayDim);

                                }

                                return ListDimension;

                            }

                     

                    What can be my possible mistake ?