0

Actually I am trying to connect to solidworks through visual studio 2013.I am getting an error stating:" A first chance exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe / Object reference not set to an instance of an object" . Showing Documents as nothing because of which getting error in line "For Each Doc As ModelDoc2 In Documents".

Public Sub New()
    SwApp = New SldWorks.SldWorks

    Dim Documents As Object = SwApp.GetDocuments()

    For Each Doc As ModelDoc2 In Documents

        _observableModeldoc.Add(New Modeldocs(Doc.GetPathName, _SwApp))

    Next

End Sub

Can anyone please suggest any solution..?

4
  • Based on this, one should have Solidworks open with 1 document, for the code to work. Have you the app open? Commented Jun 21, 2014 at 19:12
  • Yes I have opened a model doc file in solidworks Commented Jun 22, 2014 at 7:01
  • What does SwApp.GetDocuments().Count return? Please note that I havent worked on Solidworks. Commented Jun 22, 2014 at 7:21
  • Actually by Dim Documents As Object = SwApp.GetDocuments(), we get document currently opened in solidworks. But I m getting value of Documents as nothing though i have document opened in solidworks. Commented Jun 22, 2014 at 9:10

1 Answer 1

0

Check out this post from Artem Taturevich. If you write a standalone app (opposed to SW add-in or macro), then instead of

    SwApp = New SldWorks.SldWorks

you should use either of GetObject/CreateObject/Activator::CreateInstance functions

Sign up to request clarification or add additional context in comments.

2 Comments

Used SwApp = GetObject(, "SldWorks.Application") instead of SwApp = New SldWorks.SldWorks.. Showing Error Stating : Unhandled exception of type Sysetm.Exception occured and Cannot create activeX component in line "Dim Documents As Object = SwApp.GetDocuments()"
Actually error is coming the line "Dim Documents As Object = SwApp.GetDocuments()" itself. Error is: Cannot create an activeX component

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.