9 Replies Latest reply on Apr 26, 2018 6:59 AM by Sanket Pundge

    Centerline lenght control

    Dariusz Karcz

      Hello,

       

      is there a way to get drawing view centerline underlying sketch to control its length?

       

      I need to grab its ends (just like you do it manually by grabbing blue squares after clicking on centerline) and then, extend them.

        • Re: Centerline lenght control
          Jacob Corder

          i cant find anything.

           

          no access through IAnnotation

          Cannot be cast to anything else.

           

          you can get the location data from

          IAnnotaton.GetDisplayData.getLineAtIndex3(0)

          but this doesn't help you.

           

          2016 SOLIDWORKS API Help - GetLineAtIndex3 Method (IDisplayData)

           

          even recording a macro doesnt give you any information that is helpful

           

           

          using IView.GetSketch doesn't even work.

          • Re: Centerline lenght control
            Sanket Pundge

            first you select view after that ,  by using GetLine4() you get the details of your  Line  for eg. LINETYPE  , Start & end Point co-ordinate .

            But i don't know to change Start & end Point Co-ordinate of CenterLine . if you got it then please informe me .

              • Re: Centerline lenght control
                Dariusz Karcz

                Unfortunately, your suggestion is completely wrong.

                 

                How can i get lines in view, when centerline is a display data object, not a sketch?

                 

                try this short macro with preselecting drawing view with centerline in it:

                 

                Dim swApp As SldWorks.SldWorks

                Dim swmodel As SldWorks.ModelDoc2

                Dim swselmgr As SldWorks.SelectionMgr

                Dim swView As SldWorks.View

                 

                Sub main()

                 

                Set swApp = Application.SldWorks

                Set swmodel = swApp.ActiveDoc

                Set swselmgr = swmodel.SelectionManager

                Set swView = swselmgr.GetSelectedObject6(1, -1)

                 

                Debug.Print swView.GetLineCount2(0)

                Debug.Print swView.GetName2

                 

                End Sub

                 

                You will have 0 in line count, if you will identify selected object by GetSelectedObjectType3 Method (ISelectionMgr) and centerline preselected, you will have swSelCENTERLINES as your return type.

                 

                When you will try to assign centerline object thru ICenterLine, there is no way to get underlying sketch of this centerline, because it is display data object, not a sketch, you can get display data object start and end points, but there is no way to change it.

                 

                 

                  • Re: Centerline lenght control
                    Sanket Pundge

                    Check this, its work .

                    swViews = swDoc.GetFirstView();

                                        swViews = swViews.GetNextView();

                                          

                                            while (swViews != null)

                                            {

                                               // swViews = swSelMg.GetSelectedObject5(1);

                                                swViews.ScaleRatio = swScale;

                                                swModel.ForceRebuild3(true);

                                                double[] BoundaryBox = swViews.GetOutline();

                                                double Xmin = BoundaryBox[0];

                                                double Xmax = BoundaryBox[2];

                                                double XvalueForCenterLine = (Xmax + Xmin) / 2;

                                                double Ymin = BoundaryBox[1];

                                                double Ymax = BoundaryBox[3];

                                                double YvalueForCenterLine = (Ymax + Ymin) / 2;

                                                double[] OutBox = swViews.GetOutline();

                                                int count = swViews.GetLineCount2(1);

                                                Debug.Print("count" + count);

                                                if (count != 0)

                                                {   

                                                    double[] centerLine = swViews.GetLines4(1);

                                                    Sketch swSketch = swViews.GetSketch();

                                                    Object[] vswSketch = swSketch.GetSketchSegments();

                                                    int j = vswSketch.Length;

                                                    for (int i = 0; i < j; i++)

                                                    {

                                                        SketchSegment swSketchSeg = (SketchSegment)vswSketch[i];

                                                        swSketchSeg.Select4(true, null);

                     

                     

                                                    }

                                                   

                                                  //  SketchLine Line  = swSketchSeg

                                                    swModel.EditDelete();  // Delete line then Create New One .

                                                    SketchManager swSketchMg = swModel.SketchManager;

                                                    swSketchMg.CreateCenterLine(-XvalueForCenterLine, 0, 0, XvalueForCenterLine,0,0); // if center line is Horizontal

                     

                                                }

                    Note : - its is only Hoeizontal CenterLine ,