1 Reply Latest reply on Jun 7, 2016 10:02 AM by William Cruz

    Code select faces of only one part

    Alone A.

      Hello everyone

      I got code for selecting all the faces of the part. But when I have more than two parts it only select faces of one part only.

      it it possible to select faces of all the parts ??

      Please suggest any suitable changes in code.

      Along with attach the image giving the output showing that it select faces of part in left side only. Also I want to select the faces of part in right side along with left part.

      Code which I am using is as fallows.

      Thank You.

      //*****************************************************************************************

      1. using SolidWorks.Interop.sldworks; 
      2. using SolidWorks.Interop.swconst; 
      3. using System.Runtime.InteropServices; 
      4. using System; 
      5.  
      6.  
      7. namespace CS.csproj 
      8.     public partial class SolidWorksMacro 
      9.     { 
      10.         public void Main() 
      11.         { 
      12.             IModelDoc2 model = swApp.IActiveDoc2; 
      13.  
      14.             if (model is IPartDoc) 
      15.             { 
      16.                 SelectData selData = model.ISelectionManager.CreateSelectData(); 
      17.  
      18.                 object[] bodies = (model as IPartDoc).GetBodies2( 
      19.                     (int)swBodyType_e.swAllBodies, true) as object[]; 
      20.                  
      21.                 if (bodies != null && bodies.Length > 0)  
      22.                 { 
      23.                     IBody2 body = bodies[0] as IBody2; 
      24.  
      25.                     model.ClearSelection2(true); 
      26.  
      27.                     IFace2 face = body.GetFirstFace() as IFace2; 
      28.  
      29.                     while (face != null)  
      30.                     { 
      31.                         (face as IEntity).Select4(true, selData); 
      32.                         face = face.GetNextFace() as IFace2; 
      33.                     } 
      34.                 } 
      35.             } 
      36.         }
      37.         public SldWorks swApp; 
      38.     }