AnsweredAssumed Answered

.net code opens a new instance of SolidWorks

Question asked by Dennis Hvam on Jun 4, 2015
Latest reply on Jun 4, 2015 by Adam Hoffman

Hello Guys,


I'm working a little .net kode which first of all should just do a force rebuild of an open part in SolidWorks 2014:


Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swcommands

Imports SolidWorks.Interop.swconst

Imports System.Runtime.InteropServices



Module ForceRebuildSld



    Dim swModel As ModelDoc2

    Dim swApp As SldWorks.SldWorks

    Dim TopOnly As Boolean



    Sub StartRebuild()


        swApp = GetObject("", "SldWorks.Application")

        swModel = swApp.ActiveDoc


        'Forces a rebuild of all of the features in the model whether they need a rebuild.


        If swModel Is Nothing Then

            MsgBox("There was nothing in swModel:",, "Crowdforce")


            If swModel.ForceRebuild3(True) Then

                MsgBox("Forced rebuild successful",, "Crowdforce")


                MsgBox("This model has rebuild errors",, "Crowdforce")

            End If


            'save/close stuff



        End If

    End Sub


End Module

-----------------code end-----------------

It opens a second solidworks and therefore the swModel doesn't get any data, and it fails because there is nothing to rebuild.

I'm very new to .net, any help would be greatly appreciated.

Thanks in advance