AnsweredAssumed Answered

Error while Converting VBA code into C#

Question asked by Alone A. on May 23, 2016
Latest reply on May 24, 2016 by Alone A.

Hi Everyone

I am getting bunch of error while converting VBA code into C# code for face selection

I am stuck with the error like nullReferenceException

plz help me to convert the code in C#

I am using solidworks 2015 version. Which libraries I need to import in VS for stand Alone Application.

 

VBA Code

**************************************************************************************************

Sub main()

 

    Dim swApp               As SldWorks.SldWorks

    Dim swModel             As SldWorks.ModelDoc2

    Dim swSelMgr            As SldWorks.SelectionMgr

    Dim swSelData           As SldWorks.SelectData

    Dim swPart              As SldWorks.PartDoc

    Dim swBody              As SldWorks.Body2

    Dim swFace              As SldWorks.Face

    Dim swEnt               As SldWorks.Entity

    Dim bRet                As Boolean

    Dim vBodies             As Variant

   

    Set swApp = CreateObject("SldWorks.Application")

    Set swModel = swApp.ActiveDoc

    Set swPart = swModel

    Set swSelMgr = swModel.SelectionManager

    Set swSelData = swSelMgr.CreateSelectData

    vBodies = swPart.GetBodies2(swAllBodies, True)

    Set swBody = vBodies(0)

   

    Set swFace = swBody.GetFirstFace

    swModel.ClearSelection2 True

   

    Do While Not swFace Is Nothing

        Set swEnt = swFace

        ' Select through Entity

        bRet = swEnt.Select4(True, swSelData): Debug.Assert bRet

        Set swFace = swFace.GetNextFace

    Loop

swModel.ClearSelection2 True

 

End Sub

******************************************************************************************************************

Outcomes