3 Replies Latest reply on Sep 16, 2016 3:11 PM by Patrik MacHalec


    Zhu Shuyan

      Hi All:

      I want to use CreateFeatureFromBody3 in the assembly.

      1.Select component

      2.Go to edit mode: AssemblyDoc::EditPart2.


      Solid origin is the part of the originI, would like to place the assembly!




             Dim myFeature As Feature = AssDoc.FeatureByName("MoldCutRef-1")

              myFeature.Select2(False, 1)

              AssDoc.EditPart2(True, False, 0)

             Dim prtDoc As PartDoc = AssDoc.GetEditTarget


      prtDoc.CreateFeatureFromBody3(myBody, False, swCreateFeatureBodyOpts_e.swCreateFeatureBodyCheck + swCreateFeatureBodyOpts_e.swCreateFeatureBodySimplify)


      Thank you

        • Re: Assembly:::CreateFeatureFromBody3
          Amen Allah Jlili

          Assembly::CreateFeatureFromBody3 does not exist.
          This example might help you.



          ' Problem:
          '       This example shows how to use some of
          '       the geometry and topolgy APIs to
          '       construct a temporary API body from a
          '       set of selected faces and then create a solid
          '       body feature from this temporary body.
          ' Preconditions:
          '       (1) Part is open.
          '       (2) At least one face is selected.
          ' Postconditions: If the selected faces can be knitted into a solid,
          '           then a new part is created and the solid (from the
          '           selected faces) is inserted as an imported solid
          '           body feature.
          Option Explicit
          Public Enum swBodyType_e
              swAllBodies = -1
              swSolidBody = 0
              swSheetBody = 1
              swWireBody = 2
              swMinimumBody = 3
              swGeneralBody = 4
              swEmptyBody = 5
          End Enum
          Public Enum swCreateFeatureBodyOpts_e
              swCreateFeatureBodyCheck = &H1
              swCreateFeatureBodySimplify = &H2
          End Enum
          Sub main()
              Dim swApp                   As SldWorks.SldWorks
              Dim swModel                 As SldWorks.ModelDoc2
              Dim swPart                  As SldWorks.PartDoc
              Dim swNewPart               As SldWorks.PartDoc
              Dim swModeller              As SldWorks.Modeler
              Dim swSelMgr                As SldWorks.SelectionMgr
              Dim swSelFace()             As SldWorks.face2
              Dim vFaceList               As Variant
              Dim swBody                  As SldWorks.body2
              Dim swNewBody               As SldWorks.body2
              Dim swFeat                  As SldWorks.feature
              Dim nSelCount               As Long
              Dim i                       As Long
              Dim bRet                    As Boolean
              Set swApp = CreateObject("SldWorks.Application")
              Set swModel = swApp.ActiveDoc
              Set swPart = swModel
              Set swSelMgr = swModel.SelectionManager
              Set swModeller = swApp.GetModeler
              nSelCount = swSelMgr.GetSelectedObjectCount
              ReDim swSelFace(nSelCount - 1)
              For i = 1 To nSelCount
                  Set swSelFace(i - 1) = swSelMgr.GetSelectedObject5
              vFaceList = swSelFace
              Set swBody = swPart.CreateNewBody
              Set swNewBody = swBody.CreateBodyFromFaces(nSelCount, (vFaceList))
              If swNewBody Is Nothing Then
                  Debug.Print "Failed to form solid body from selected faces."
                  Exit Sub
              End If
              Debug.Assert swSolidBody = swNewBody.GetType
              Set swNewPart = swApp.NewPart
              ' Force creation of a solid body feature
              Set swFeat = swNewPart.CreateFeatureFromBody3(swNewBody, False, _
                              swCreateFeatureBodyCheck + swCreateFeatureBodySimplify)
              ' Must be able to create a solid body feature from a solid body
              Debug.Assert Not swFeat Is Nothing
          End Sub
            • Re: Assembly:::CreateFeatureFromBody3
              Goggoo Goggoo

              Amen Allah Jlili,thank you.

              In the assembly of the use of surface generation entities, you can use the InsertSewRefSurface method, the efficiency is too low!

              I use the following methods in the assembly to carry out parts of the reateFeatureFromBody3 method; but in parts of the coordinates of the wrong; all in parts of the origin!


              Dim myFeature As Feature = AssDoc.FeatureByName("PartFileName-1")

              MyFeature.Select2 (False, 1)

              AssDoc.EditPart2 (True, False, 0)


              PrtDoc.CreateFeatureFromBody3 (myBody, False, swCreateFeatureBodyOpts_e.swCreateFeatureBodyCheck + swCreateFeatureBodyOpts_e.swCreateFeatureBodySimplify)

            • Re: Assembly:::CreateFeatureFromBody3
              Patrik MacHalec

              Hi Zhu,


              you have to use  IBody2:ApplyTransform after copy of body/bodies.

              Check example how to use this method: 2013 SOLIDWORKS API Help - Combine Assembly Components into Part Example (VBA)