I get the following message when trying to connect tosolidworks.
System.Security.SecurityException was unhandled
Message="Request for the permission of type'System.Security.Permissions.SecurityPermission, mscorlib,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'failed."
When I use this in a class it works, but when I use it in a moduleit does not work. How can I get around this? Here is my code -
Imports SldWorks
Imports SwConst
Public Module Module1
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sub main()
swApp = GetObject("", "SldWorks.Application")
If swApp Is Nothing Then
MsgBox("Error getting SolidWorks Handle")
Exit Sub
End If
swModel =swApp.NewDocument("I:\Libraries_SW8\gh_library\parts\part-plate.prtdot",0, 0, 0)
If swModel Is Nothing Then
MsgBox("Error creating new part")
Exit Sub
End If
Dim IErrors As Long = 0
Dim Iwarnings As Long = 0
Dim bRet As Boolean =swModel.Extension.SaveAs("h:\temp\test.sldprt",swSaveAsVersion_e.swSaveAsCurrentVersion _
, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, IErrors,Iwarnings)
'If Not bRet Then
' MsgBox("Error Saving new part")
'End If
End Sub
End ModuleSolidworksApi macros
System.Security.SecurityException was unhandled
Message="Request for the permission of type'System.Security.Permissions.SecurityPermission, mscorlib,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'failed."
When I use this in a class it works, but when I use it in a moduleit does not work. How can I get around this? Here is my code -
Imports SldWorks
Imports SwConst
Public Module Module1
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sub main()
swApp = GetObject("", "SldWorks.Application")
If swApp Is Nothing Then
MsgBox("Error getting SolidWorks Handle")
Exit Sub
End If
swModel =swApp.NewDocument("I:\Libraries_SW8\gh_library\parts\part-plate.prtdot",0, 0, 0)
If swModel Is Nothing Then
MsgBox("Error creating new part")
Exit Sub
End If
Dim IErrors As Long = 0
Dim Iwarnings As Long = 0
Dim bRet As Boolean =swModel.Extension.SaveAs("h:\temp\test.sldprt",swSaveAsVersion_e.swSaveAsCurrentVersion _
, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, IErrors,Iwarnings)
'If Not bRet Then
' MsgBox("Error Saving new part")
'End If
End Sub
End ModuleSolidworksApi macros