I am looking to automatically attach a file to the design binder of a solidworks model. I am using SW VB macro code but I cannot figure out how to get my program to automatically place an exiting file, (for example c:\sample.txt} into the binder.
Sorry for the delay in getting to this issue. You can use ModelDocExtension::InsertAttachment to add items to the design binder. Below is short example macro. Let me know if you have further questions.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swExt As ModelDocExtension
Dim swSelMgr As SelectionMgr
Dim swComp As Component2
Dim swFeat As Feature
Dim swView As View
Dim filePath As String
Dim macroPath As String
Dim swAssem As AssemblyDoc
Dim swPart As PartDoc
Dim swDraw As DrawingDoc
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swExt = swModel.Extension
Set swSelMgr = swModel.SelectionManager
Select Case swModel.GetType
Case swDocPART
Set swPart = swModel
Case swDocASSEMBLY
Set swAssem = swModel
Case swDocDRAWING
Set swDraw = swModel
End Select
filePath = ""
macroPath = CurDir & "\"
Dim bRes As Boolean
bRes = swExt.InsertAttachment("C:\sample.txt", False)
End Sub
Regards,
Robin Richter
SolidWorks Technical Support
SolidWorks Corporation | 300 Baker Avenue | Concord | MA | 01742 | USA
Resellers: When reporting customer issues to SolidWorks Technical Support please include customer name, contact name, e-mail address and serial number.