6 Replies Latest reply on Oct 4, 2017 5:12 AM by Marco Maso

    EqualSegment always returns false

    Marco Maso

      Hello,

      I'm trying to use the EqualSegment method on some splines but it always returns false.

       

      I'm in the AfterClose() of a PropertyManager. I can retrieve the sketch, enter inside it, recover all sketch segments but, foreach sketch segment, EqualSegment fails.

       

      Varying the number of points doesn't change the outcome. Of course the API only returns a generic 'false'..

       

      Do you have any clue on this? Thanks in advance.

        • Re: EqualSegment always returns false
          Manikandan Babu

          Hi Marco,

           

          I have worked out the example it is working fine in SolidWorks 2017.

           

          Can you provide the sample set of files to check your workflow.

           

          Thanks

          Manikandan

            • Re: EqualSegment always returns false
              Marco Maso

              Hi Manikandan, thanks for the reply.

               

              I extracted the relevant code.

               

              public void SplineSmoothingClicked()
              {
                  // <retrieving Solidworks components (e.g. swSelectionManager)>
              
                  List<Feature> features = new List<Feature>();
              
                  for (int i = 1; i <= swSelectionManager.GetSelectedObjectCount2(-1); i++)
                  {
                      if (swSelectionManager.GetSelectedObjectType3(i, -1) == (int)swSelectType_e.swSelSKETCHES)
                      {
                          features.Add((Feature)swSelectionManager.GetSelectedObject6(i, -1));
                      }
                  }
              
                  foreach (Feature feat in features)
                  {
                      swModel.ClearSelection2(true);
                      feat.Select2(false, 1);
                      swModel.InsertSketch2(false);
              
                      Sketch activeSketch = (Sketch)swModel.GetActiveSketch2();
              
                      // <retrieving sketch segments with activeSketch.GetSketchSegments() and casting them to an array>
              
                      foreach (SketchSegment skSeg in sketchSegments)
                      {
                          skSeg.EqualSegment((int)swSketchSegmentType_e.swSketchSegmentType_sketchpoints, 50);
                      }
              
                      swModel.ClearSelection2(true);
                      swModel.InsertSketch2(true);
                  }
              }
              

               

              Thanks.

                • Re: EqualSegment always returns false
                  Jacob Corder

                  you never instantiated SketchSegments

                   

                  Dim SketchSegments as object

                  SketchSegments = ActiveSketch.GetSketchSegments

                   

                  or simply replace

                  foreach (SketchSegment skSeg in sketchSegments) 

                  Foreach (SketchSegment SkSeg in ActiveSketch.GetSketchSegments)

                    • Re: EqualSegment always returns false
                      Marco Maso

                      Hi Jacob, thanks for the answer. Sorry, I wasn't clear enough. I actually retrieve the SketchSegments but I omitted the code (replaced with a '// <retrieving sketch segments with activeSketch.GetSketchSegments() and casting them to an array>') for simplicity sake. Sorry about that. I'm sure I'm targeting the exact segments because GetName() retrieves the effective names but EqualSegment still doesn't work.

                    • Re: EqualSegment always returns false
                      Manikandan Babu

                      Hi Marco,

                       

                      I think failed to select the sketch segment before EqualSegment in your code.

                       

                      Try this code with part which has sketch1 holds some splines.

                       

                         SldWorks SwApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("sldworks.Application");

                                  ModelDoc2 SwModel = (ModelDoc2)SwApp.ActiveDoc;

                                  PartDoc SwPart = (PartDoc)SwModel;

                                  Feature SwFeat = SwPart.FeatureByName("Sketch1");

                                  SwFeat.Select2(true, 0);

                                  SwModel.SketchManager.InsertSketch(true);

                                  Sketch Swsketch= (Sketch)SwModel.GetActiveSketch2();

                                  SwModel.ClearSelection2(true);

                                  foreach (SketchSegment Sketchseg in Swsketch.GetSketchSegments())

                                  {

                                      SelectData Seldata=null;

                                      Sketchseg.Select4(false, Seldata);

                                      Sketchseg.EqualSegment((int)swSketchSegmentType_e.swSketchSegmentType_sketchpoints, 50);

                                  }

                                  SwModel.ClearSelection2(true);

                                  SwModel.InsertSketch2(true);

                       

                      Manikandan