Macro - Help
Macro - Help
(OP)
I currently have a macro that will create a PDF and save it to the active docs current directory. I am having trouble finding any reference to do a save as and change the directory that the file is saved in. The final result that I am looking for is to run the macro and have a PDF saved in a network directory so it can be accessed by manufacturing. I'm not sure SaveAs4 is what I am looking for. Any help is appreciated.
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
--Howard Aiken, IBM engineer






RE: Macro - Help
Remember...
"If you don't use your head,
your going to have to use your feet."
RE: Macro - Help
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
--Howard Aiken, IBM engineer
RE: Macro - Help
If you are saving to a predetermined directory, use a vba macro and edit the path to point to the required location.
If you want to be able to browse to the save location use VB so that you have easy access to the common dialog control, which will include a save window from which you can set the file name and browse to the appropriate folder.
RE: Macro - Help
BoolStatus = Doc.SaveAs4(\\Kmpdc\GROUP\~ENGINEERING\_Wip\DocName, 0, 0, e, w)
This is currently what I have in there and I get Syntax Error. I am at a loss.
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
--Howard Aiken, IBM engineer
RE: Macro - Help
Doc.SaveAs4("C:\Kmpdc\GROUP\~ENGINEERING\_Wip\DocName.pdf", 0, 0, e, w)
Remember...
"If you don't use your head,
your going to have to use your feet."
RE: Macro - Help
CODE
Dim w as Long
Doc.SaveAs4 "C:\Kmpdc\GROUP\~ENGINEERING\_Wip\DocName.pdf", 0, 0, e, w
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: Macro - Help
Option Explicit
Dim swApp, Doc As Object
Const swDocDRAWING = 3
Const swMbWarning = 1
Const swMbInformation = 2
Const swMbOk = 2
Dim BoolStatus As Boolean
Dim LongStatus As Long
Dim e As Long
Dim w As Long
Dim Description As String
Dim Msg As String
Dim DocName As String
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set Doc = swApp.ActiveDoc
If ((Doc Is Nothing) Or (Not (Doc.GetType Eqv swDocDRAWING))) Then
Msg = "A drawing document must be active to use this command!"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End
Else
Description = Doc.CustomInfo2("", "Description")
DocName = Doc.GetPathName
If (Not (DocName = "")) Then
DocName = Left(DocName, Len(DocName) - 7)
Else
Msg = "Please save drawing before creating pdf!"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End
End If
If (Not (Description = "")) Then
DocName = DocName & "_" & Description & ".pdf"
Else
DocName = DocName & ".pdf"
End If
BoolStatus = Doc.SaveAs4("g:\Kmpdc\GROUP\~ENGINEERING\_Wip\DocName", 0, 0, e, w)
If BoolStatus = False Then
Msg = "Failed to save PDF document!"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
Else
Msg = "Saved drawing as " & DocName
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End If
End If
Set Doc = Nothing
Set swApp = Nothing
End Sub
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
--Howard Aiken, IBM engineer
RE: Macro - Help
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
--Howard Aiken, IBM engineer
RE: Macro - Help
CODE
CODE
What's wrong is the way you are concatenating your string. You have a name for your document in DocName, but when you include that name inside the quotes defining your save path, it isn't recognized as a variable because it is just part of a string.
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: Macro - Help
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
--Howard Aiken, IBM engineer
RE: Macro - Help
With my limited knowledge of writing macros, it looks as if when DocName is created it has the full pathname from the original location. It then goes thru and gets the original extension (.slddrw) stripped off and a .pdf added, But the original path is still the same. So when it gets to the boolstatus line I think it is trying to save it to the specified directory with the DocName path still in the DocName. I think it looks something like: ("G:\~ENGINEERING\~Engineering Drawings\Vertical Beaters\Test Use\g:\Kmpdc\GROUP\~ENGINEERING\_Wip\Test Use Only.pdf"). So it gets confused if my thinking is correct and can't save the file. Now my question is how do I strip off the original path and keep only the file name. Would I use GetTitle?
Thanks,
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
--Howard Aiken, IBM engineer
RE: Macro - Help
1) Add this line above:
[code]
debug.print(docname)
[\code]
This will help you figure out if the path is still in the docname. If it is, use InStrRev for the last occurrence of "\", then Substring to remove the path, then Substring again to remove the extension.
2) Make sure the target path exists and is accessible for the currently logged in user. SaveAs4 will NOT create new folders
3) If you couldhave a multi-sheet drawing with differently sized sheeets, be sure to add this line:
[code]
swModel.Extension.UsePageSetup = SwConst.swPageSetupInUse_e.swPageSetupInUse_DrawingSheet
[\code]
That will force each page in the PDF to match the orientation of the drawing sheet.
Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
RE: Macro - Help
The help is much appreciated. Like I said earlier I am fairly new to using VB so your post confused me. I'm sorry but could you explain it so someone like me could understand.
Thanks,
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
--Howard Aiken, IBM engineer
RE: Macro - Help
[code]
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Doc As SldWorks.ModelDoc2
Const swDocDRAWING = 3
Const swMbWarning = 1
Const swMbInformation = 2
Const swMbOk = 2
Dim BoolStatus As Boolean
Dim LongStatus As Long
Dim e As Long
Dim w As Long
Dim Description As String
Dim Msg As String
Dim DocName As String
Sub main()
Set swApp = CreateObject("SldWorks.Application")
Set Doc = swApp.ActiveDoc
If ((Doc Is Nothing) Or (Not (Doc.GetType Eqv swDocDRAWING))) Then
Msg = "A drawing document must be active to use this command!"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End
Else
Description = Doc.CustomInfo2("", "Description")
DocName = Doc.GetPathName
If (Not (DocName = "")) Then
DocName = Left(DocName, Len(DocName) - 7)
Else
Msg = "Please save drawing before creating pdf!"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End
End If
If (Not (Description = "")) Then
DocName = DocName & "_" & Description & ".pdf"
Else
DocName = DocName & ".pdf"
'at this point, DocName still has the full path
DocName = Mid(DocName, InStrRev(DocName, "\") + 1)
'now, DocName is just Filename.pdf
End If
Dim TargetLocation As String
'don't forget the trailing "\"
TargetLocation = "c:\temp\"
'also, set the pagesetup to adjust on a sheet by sheet basis
Doc.Extension.UsePageSetup = SwConst.swPageSetupInUse_e.swPageSetupInUse_DrawingSheet
'concatenate the TargetLocation and Filename
'if the TargetLocation does not exist, the call will fail
BoolStatus = Doc.SaveAs4(TargetLocation & DocName, 0, 0, e, w)
If BoolStatus = False Then
Msg = "Failed to save PDF document!"
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
Else
Msg = "Saved drawing as " & DocName
LongStatus = swApp.SendMsgToUser2(Msg, swMbWarning, swMbOk)
End If
End If
Set Doc = Nothing
Set swApp = Nothing
End Sub
[\code]
Evan T. Basalik, MCSD
--------------------------------
It's all about prioritization...
RE: Macro - Help
That works great. Thanks for all your help. This will save us alot of time folder and Drive jumping.
Thanks Again
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.
--Howard Aiken, IBM engineer
RE: Macro - Help
PDF's I do a whole different way. My macro calls the print dialouge to use CUTE PDF (freeware) and then saves the file (retaining the name, in a predetermined location) and I use a third macro that prompts me for location and file name for those odd instances where I need to PDF to someplace other than my ready for release directory.