Hello everyone, currently I want to export a PDF file with its drawing name & revision that is got custom property from the model rather than drawing's revision, in this case, my revision is "AMERev". My macro is working with the model but I'm still being stuck with drawing. What I should modify in this case, please advice and thank you so much for your attention.
Here is my macro:
Option Explicit
Public swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swSheet As SldWorks.Sheet
Dim swView As SldWorks.View
Dim swDraw As SldWorks.DrawingDoc
Dim vConfNameArr As Variant
Dim sConfigName As String
Dim sPath As String
Dim sPath1 As String
Dim i As Long
Dim bRebuild As Boolean
Dim bRet As Boolean
Dim sRev As String
Dim sPathName As String
Dim vSheetNames As Variant
Dim CurrentSheet As String
Sub Main()
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
'------------------------------------ swModel=2 => call swAssy-------------
If swModel.GetType() = 2 Then
Set swAssy = swModel
sPathName = swAssy.GetPathName
sPathName = Left(sPathName, Len(sPathName) - 7)
sPath = UCase(Left(swAssy.CustomInfo2("", "AMERev"), 5))
swAssy.SaveAs (sPathName & "_" & sPath & ".x_t")
End If
'------------------------------------- swModel=1 => call swModel------------
If swModel.GetType() = 1 Then
sPathName = swModel.GetPathName
sPathName = Left(sPathName, Len(sPathName) - 7)
sPath = UCase(Left(swModel.CustomInfo2("", "AMERev"), 5))
swModel.SaveAs (sPathName & "_" & sPath & ".step")
End If
'-------------------------------------- swModel=3 => call swDraw------------
If swModel.GetType() = 3 Then
Set swDraw = swModel
sPathName = swDraw.GetPathName
sPathName = Left(sPathName, Len(sPathName) - 7)
sPath = UCase(Left(swModel.CustomInfo2("", "AMERev"), 5))
swDraw.SaveAs (sPathName & "_" & sPath & ".pdf")
End If
End Sub
Is the variable AMERev actually in the drawing file custom property table or do you have to pull this from the part that is referenced by the drawing?
If you are trying to get the variable from the part that is in a drawing view then you'll have to pull the reference model.
My code is in c# for this but the process and commands are essentially the same, you'll just have to adjust the syntax.
You will need to get the first view which is the sheet template
Then you'll need to get the next view which is your first drawing view containing a model
From there, you can get the referenced model in that view with:
Finally, you can get the data from that with:
Try to get something working with that and post the code back up here and we can fine tune it if needed. There are some additional checks you can do to make sure that the drawing view you're getting the model in is actually the drawing view that your title block is referencing. This only helps if you have views with different models though.