AnsweredAssumed Answered

Inconsistent API calls?

Question asked by Felix Sigwart on Jul 13, 2016
Latest reply on Jul 21, 2016 by Felix Sigwart

Hello,

the last few days I wrote my first SolidWorks macro in VB.NET and i found some (for me) strange behaviour. The macro works fine on the PC I developed it, but if I execute the macro on another PC some API functions doesn't seem to work. Their deprecated versions work on both PCs.
On both PCs is SolidWorks 2016 SP 3.0, Windows 7 Professional. On the development PC is the SDK installed, but i doubt that the missing SDK is the problem.

If I make a new macro on my second PC I can select the specific functions and pass the parameters. The compilation works also.

 

E.g. IDrawingDoc:NewSheet3 and IDrawingDoc:NewSheet4

Some testcode

Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System.Runtime.InteropServices
Imports System
Partial Class SolidWorksMacro
    Public Sub main()
        Dim swdoc As ModelDoc2 = swApp.ActiveDoc
        Dim swdraw As DrawingDoc = CType(swdoc, DrawingDoc)
        swdraw.NewSheet3("foo", swDwgPaperSizes_e.swDwgPapersUserDefined, _
            swDwgTemplates_e.swDwgTemplateNone, 1, 1, True, "", 100, 200, "")
        swdraw.ActivateSheet("foo")
        swdraw.NewSheet4("bar", swDwgPaperSizes_e.swDwgPapersUserDefined, _
            swDwgTemplates_e.swDwgTemplateNone, 1, 1, True, "", 100, 200, "", 0, 0, 0, 0, 0, 0)
        swdraw.ActivateSheet("bar")
    End Sub
    ''' <summary>
    ''' The SldWorks swApp variable is pre-assigned for you.
    ''' </summary>
    Public swApp As SldWorks
End Class

On my development PC both functions are working and they create the new sheets. On the second PC NewSheet4 fails with a System.AccessViolationException.
The same with the function ICustomPropertyManager:Get4 and ICustomPropertyManager:Get5.

Is this a known problem? Did I miss something vital?

 

Thanks in advance
Felix

Outcomes