AnsweredAssumed Answered

visual studio 2019

Question asked by Gian Luca Taroni on Apr 7, 2019
Latest reply on Apr 7, 2019 by Gian Luca Taroni



I'm working on a fresh environment with visual studio 2019 (free edition) and solidworks 2018 (installed on same machine).

I start from the beginning….but is not working and also all the example attached on documentation are non working.


I started a new project > console application

Added reference to Solidworks.Interop.sldworks and Solidworks.Interop.swconst

And this is my code


Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst

Module Module1
    Sub main()

        Dim swPart As PartDoc
        Dim swModel As ModelDoc2
        Dim swModelDocExt As ModelDocExtension
        Dim swImportStepData As ImportStepData
        Dim status As Boolean
        Dim errors As Integer
        Dim warnings As Integer
        Dim fileName As String
        Dim stepFileName As String
        Dim swApp As SldWorks = CreateObject("SolidWorks.Application")
        'Open the SOLIDWORKS part document to export to a STEP file
        fileName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\Toolbox\data\SteelLib\channel.sldprt"
        swPart = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
        swModel = swPart
        swModelDocExt = swModel.Extension

        'Export the SOLIDWORKS part document to a STEP file
        stepFileName = "C:\Users\Luca\Desktop\api\db9 male.STEP"
        status = swModelDocExt.SaveAs(stepFileName, 0, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, errors, warnings)
        swPart = Nothing

        swApp.CloseDoc("db9 male.sldprt")

        'Get import information
        swImportStepData = swApp.GetImportFileData(stepFileName)

        'If ImportStepData::MapConfigurationData is not set, then default to
        'the environment setting swImportStepConfigData; otherwise, override
        'swImportStepConfigData with ImportStepData::MapConfigurationData
        swImportStepData.MapConfigurationData = True

        'Import the STEP file
        swPart = swApp.LoadFile4(stepFileName, "r", swImportStepData, errors)
        swModel = swPart
        swModelDocExt = swModel.Extension

        'Run diagnostics on the STEP file and repair any bad faces
        errors = swPart.ImportDiagnosis(True, False, True, 0)

    End Sub

End Module


When I try to run I get the following error:




  Message=Cannot create ActiveX component.



   at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName)

   at ConsoleApp1.Module1.main() in C:\Users\Luca\Documents\Visual Studio 2019\Project\ConsoleApp1\ConsoleApp1\Module1.vb:line 19


on line highlighted in bold.

I did not find any fresh code on solidworks example.