Hi all
I'm trying to make a vb.net app to save all assemblies in a assembly as a edrawing file.
But i can't figure out why this code below isnt working.
There must be something obvious that i don't see but i spend quite some time now trying different ways but can't seem to figure it out.
could you please help?
Please find below the code:
sub main
Frm_start.Cursor = Cursors.AppStarting
Dim swApp As SldWorks
Dim swModel As ModelDoc2
Dim swConf As Configuration
Dim swConfMgr As ConfigurationManager
Dim swDerivConf As Configuration
swApp = GetObject(, "sldworks.application")
Dim swm As ModelDoc2 = swApp.ActiveDoc
'get model
swModel = swm
'check if assembly
Dim modeltype As Integer = swModel.GetType
If modeltype <> 2 Then
MsgBox("FUNCTIONNE UNIQUEMENT SUR DES ASSEMBLAGES")
Exit Sub
End If
Dim pathedrawing As String = fileloc("pathglobal") & "EASM\"
Dim filename As String = swModel.GetPathName
Dim fn As String = pathedrawing & gettextfromright(gettextfromright(filename, ".", 0), "\", 1) & "(" & SW_get_custom_properties("Description") & ").easm"
Dim fns As New List(Of String)
fns.Add(fn)
swModel.SaveAs4(fn, 0, 0, 0, 0)
Dim swass As AssemblyDoc = swModel
Dim vcomponents As Object = swass.GetComponents(True)
Dim swc As Component
Dim comc As Integer = swass.GetComponentCount(True)
'each component check
For a = 0 To comc - 1
swc = vcomponents(a)
Dim cn As String = swc.GetPathName
'check assembly
Dim assy As Boolean = False
If cn.Contains(".SLDASM") = True Then
assy = True
End If
If cn.Contains(".sldasm") = True Then
assy = True
End If
If assy = False Then
Continue For
End If
Dim refconfig As String = swc.ReferencedConfiguration
Dim fileerror As Integer
Dim filewarning As Integer
swModel = swApp.OpenDoc6(cn, swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, refconfig, fileerror, filewarning)
Dim pthea As String = pathedrawing & gettextfromright(gettextfromright(swModel.GetPathName, ".", 0) & ".easm", "\", 1)
swModel.SaveAs3(pthea, 0, 0)
fns.Add(pthea)
Next
Dim msg As String = ""
For Each f In fns
msg = msg & vbNewLine & f
Next
MsgBox("SAVED: " & msg)
Frm_start.Cursor = Cursors.Default
end sub