1 Reply Latest reply on May 29, 2018 5:27 PM by Nilesh Patel

    'Extrusion feature' using solidworks api using vb.net

    Ananth Balasubramanian

      Guys,I want to extrude a center rectangle using api.

       

      #To draw a center rectangle and exit the sketch

         swApp.Visible = True

              swModel = swApp.INewPart()

              swModel = swApp.IActiveDoc2

              swExt = swModel.Extension

              swSelMgr = swModel.SelectionManager

              skManager = swModel.SketchManager

              boolstatus = swExt.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)

              skManager.InsertSketch(True)

              Centerrectangle()  # sub program called for drawing a center rectangle

              skManager.InsertSketch(True)

       

      # Zoom to fit and isometric view, rotate the component

              swModel.ViewZoomtofit2()

              swModel.ShowNamedView2("*Trimetric", 8)

              swModel.ViewRotate()

       

      # Select all edges and points  for the current center rectangle

              boolstatus = swExt.SelectByID2("Edge", swSelectType_e.swSelEDGES, 0, 0, 0, False, 0, Nothing, 0)

              boolstatus = swExt.SelectByID2("Points", swSelectType_e.swSelSKETCHPOINTS, 0, 0, 0, False, 0, Nothing, 0)

       

       

       

      # Converting depths from 'm' to 'mm'

              Dim D1 As Double = depth1.Text / 1000

              Dim D2 As Double = depth1.Text / 1000

      # Extrusion feature

              myfeature = features1.FeatureExtrusion3(True, False, False, swEndConditions_e.swEndCondBlind, swEndConditions_e.swEndCondBlind, D1, D2, False, False, False, False, 0, 0, False, False, False, False, True, True, True, swStartConditions_e.swStartSketchPlane, 0, False)

       

      I've selected all the points and edges on the curve and given a  extrusion feature program, but the extrusion feature fails to execute.

      Did I miss something?

        • Re: 'Extrusion feature' using solidworks api using vb.net
          Nilesh Patel

          Hi Ananth,

           

          1. First of all, ISldWorks::INewPart is obsolete method. Use ISldWorks::NewDocument or 'SldWorks::INewDocument2 method to create a new document.

          2. You haven't posted codes for 'Centerrectangle' sub but I guess you're using ISketchManager::CreateCenterRectangle method to create the center rectangle. If this is the case, it will return an array of ISketchSegment which includes diagonals also. Use ISketchSegment::Select4 method to select these sketch segments. You can use ISketchSegment::ConstructionGeometry property to check whether the sketch segment is a construction line or not.

          3. Remove theselines:

          boolstatus = swExt.SelectByID2("Edge", swSelectType_e.swSelEDGES, 0, 0, 0, False, 0, Nothing, 0)

          boolstatus = swExt.SelectByID2("Points", swSelectType_e.swSelSKETCHPOINTS, 0, 0, 0, False, 0, Nothing, 0)

           

           

          I haven't tested it but it should work.

           

          Regards,

          Nilesh