Drawing Export Macro
Drawing Export Macro
(OP)
Hello,
I am trying to write a macro that will help speed up the process of constantly saving drawings as dxf's for the machine shop. Here is what I have so far:
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim CPM As SldWorks.CustomPropertyManager
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set CPM = Part.Extension.CustomPropertyManager("")
Dim FilePath As String
Dim PathSize As Long
Dim PathNoExtension As String
Dim NewFilePath As String
Dim MyRevVal As String
Dim MyRevValEvaluated As String
CPM.Get2 "Revision", MyRevVal, MyRevValEvaluated
FilePath = Part.GetPathName & Revision
PathSize = Strings.Len(FilePath)
PathNoExtension = Strings.Left(FilePath, PathSize - 6)
NewFilePath = PathNoExtension & MyRevValEvaluated & "dxf"
Part.SaveAs2 NewFilePath, 0, True, False
MsgBox "File Exported " & NewFilePath
End Sub
I have two problems.
1) It exports the file as "filename.RevDXF
File name being the drawing's name and the revision being the custom property value. Obviously the "." needs to be 3 characters over to the right.
2) The macro gives the dxf the revision of the drawing file, not the part. When we rev a part, we update the revision of the part file, not the drawing. I would like the macro to get the revision from the part file or one of the drawing views.
Any help is greatly appreciated.
I am trying to write a macro that will help speed up the process of constantly saving drawings as dxf's for the machine shop. Here is what I have so far:
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim CPM As SldWorks.CustomPropertyManager
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set CPM = Part.Extension.CustomPropertyManager("")
Dim FilePath As String
Dim PathSize As Long
Dim PathNoExtension As String
Dim NewFilePath As String
Dim MyRevVal As String
Dim MyRevValEvaluated As String
CPM.Get2 "Revision", MyRevVal, MyRevValEvaluated
FilePath = Part.GetPathName & Revision
PathSize = Strings.Len(FilePath)
PathNoExtension = Strings.Left(FilePath, PathSize - 6)
NewFilePath = PathNoExtension & MyRevValEvaluated & "dxf"
Part.SaveAs2 NewFilePath, 0, True, False
MsgBox "File Exported " & NewFilePath
End Sub
I have two problems.
1) It exports the file as "filename.RevDXF
File name being the drawing's name and the revision being the custom property value. Obviously the "." needs to be 3 characters over to the right.
2) The macro gives the dxf the revision of the drawing file, not the part. When we rev a part, we update the revision of the part file, not the drawing. I would like the macro to get the revision from the part file or one of the drawing views.
Any help is greatly appreciated.






RE: Drawing Export Macro
CODE
NewFilePath = PathNoExtension & MyRevValEvaluated & ".dxf"
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: Drawing Export Macro
CODE
Dim swDoc As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim myRefDoc As SldWorks.ModelDoc2
Sub main()
Set swApp = Application.SldWorks
If swApp.ActiveDoc.GetType <> swDocDRAWING Then
MsgBox "Not a drawing"
Exit Sub
End If
Set swDoc = swApp.ActiveDoc
Set swView = swDoc.GetFirstView
While (Not (swView Is Nothing)) And (myRefDoc Is Nothing)
If swView.ReferencedDocument Is Nothing Then
Set swView = swView.GetNextView
Else
Set myRefDoc = swView.ReferencedDocument
End If
Wend
If myRefDoc Is Nothing Then
MsgBox "No referenced document found."
Else
MsgBox "Referenced document: " & myRefDoc.GetPathName
End If
End Sub
RE: Drawing Export Macro