New to SW API
Currently running SW 2019 SP5 in a non PDM enviroment
I am trying to find a way to modify this macro I found so that it only would print the assembly drawings from the model and not any of the part drawings
Code is as follows
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swComp As SldWorks.Component2
Dim strstrDwgPath As String
Dim CurrentDoc As SldWorks.ModelDoc2
Dim swDrawToPrint As SldWorks.ModelDoc2
Dim CurrentDocQuit As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
While Not swFeat Is Nothing
If swFeat.GetTypeName2 = "Reference" Then
Set swComp = swFeat.GetSpecificFeature2
If UCase(Right(swComp.GetPathName, 3)) = "ASM" Then strDwgPath = Replace(UCase(swComp.GetPathName), "SLDASM", "SLDDRW")
'If UCase(Right(swComp.GetPathName, 3)) = "PRT" Then strDwgPath = Replace(UCase(swComp.GetPathName), "SLDPRT", "SLDDRW")
Set swDrawToPrint = swApp.OpenDoc6(strDwgPath, swDocDRAWING, swOpenDocOptions_Silent, "", Empty, Empty)
If Not swDrawToPrint Is Nothing Then
swApp.ActivateDoc swDrawToPrint.GetPathName
Set swPageSetup = swDrawToPrint.PageSetup
swPageSetup.ScaleToFit = True
swPageSetup.PrinterPaperSize = 1
Debug.Print swDrawToPrint.GetPathName
Else
End If
swApp.QuitDoc swDrawToPrint.GetTitle
End If
Set swFeat = swFeat.GetNextFeature
Wend
End Sub
I tried to comment out
If UCase(Right(swComp.GetPathName, 3)) = "PRT" Then strDwgPath = Replace(UCase(swComp.GetPathName), "SLDASM", "SLDPRT")
then it would output multiple instances of the assembly drawing preceeding any sldprt features
and if i try to print by replacing Debug.Print swDrawToPrint.GetPathName with
CurrentDoc.PrintDirect
I receive
SolidworksApi/macrosRun Time error '91':
Object variable or With block variable not set