I'm trying to use a macro to use the MBD plug-in to publish 3d PDFs. I was able to use the VBA example to publish an assembly to a 3d pdf using a theme, and got all my custom properties to show. But I can't figure out how to use the API to choose a note & use it to fill the Imported Note field in the 3d PDF (like I can using the Notes & Text Area when manually publishing to a 3d pdf using a theme)
Here's my code:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swMBDPdfData As SldWorks.MBD3DPdfData
Dim swTextAndCustomProperty As SldWorks.TextAndCustomProperty
Dim textAndCustomProperties As Variant
Dim nbrTextAndCustomProperties As Long
Dim status As Long
Dim errors As Long
Dim warnings As Long
Dim custProp As String
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Dim fileName as String
fileName = "C: emp\\box.sldasm"
Set swModel = swApp.OpenDoc6(fileName, swDocumentTypes_e.swDocAssembly, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
Set swModelDocExt = swModel.Extension
'Get MBD3DPdfData object
Set swMBDPdfData = swModelDocExt.GetMBD3DPdfData
'Set path and file name for SOLIDWORKS MBD 3D PDF
swMBDPdfData.filePath = "c: emp\\MBDPart1.PDF"
'Display SOLIDWORKS MBD 3D PDF
swMBDPdfData.ViewPdfAfterSaving = True
'Set SOLIDWORKS MBD 3D PDF theme
swMBDPdfData.ThemeName = "C:\\Program Files\\SolidWorks Corp\\SOLIDWORKS\\data hemes\\simple part (a4, portrait) heme.xml"
standardViews = viewIDs
swMBDPdfData.SetStandardViews (standardViews)
'Create and set custom views for SOLIDWORKS MBD 3D PDF
Dim viewnames as Variant
viewNames = swModelDocExt.Get3DViewNames()
swMBDyPdfData.SetMoreViews(viewNames)
'Get text and custom properties from theme for solidworks MBD 3D PDF
textAndCustomProperties = swMBDPdfData.GetTextAndCustomProperties
'Get Note
Dim annos As Variant
Dim ann As Variant
Dim note as SldWorks.note
annos=swModelDocExt.GetAnnotations
For Each ann In annos
If ann.GetType()=swAnnotationType_e.swNote Then
Set note = ann.GetSpecificAnnotation
If InStr(note.GetText(),"KEYWORD") Then
Exit For
End If
End If
Next ann
Dim impNotes as Variant
impNotes = swMBDPdfData.GetImportedNotes
Dim noteName As Variant
For Each noteName In impNotes
'following line causes crash when added in
boolstatus = swMBDPdfData.SetImportedNote(noteName,note)
Next noteName
'Create SOLIDWORKS MBD 3D PDF
status = swModelDocExt.PublishTo3DPDF(swMBDPdfData)
Debug.Print ("Status of publishing part to SOLIDWORKS MBD 3D PDF (0 = success): " & status)
End Sub
I edited out actual filenames I'm using. Adding in the line boolstatus = swMBDPdfData.SetImportedNote(noteName,note)causes solidworks to crash after capturing all the views , while generating the PDF. PDF with the theme but nothing else in it is generated.
If I don't include that line, everything is in the PDF except the imported note field.
