Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save as PDF 3

Status
Not open for further replies.

MachineSMMC

Industrial
May 7, 2004
70
Is there anyway to link the save as pdf option in the file --> Save As Pulldown to a button or something to make it a little faster to do?

Thanks
Chris Tellers
 
Replies continue below

Recommended for you

D'oh, I missed that somehow I had commented out the SaveAs line! I'm not sure when it happened but oops all the same. Either way, maybe this will lead me to learning a new programming language to augment my laziness--er, workload.

Thanks again, handleman--can't give you another star this week though.
 
No doubt the people who knew some VBScript before this thread don't need this next info, nor do people who have multiple page drawings for single parts, but I was getting annoyed with the " - Sheet1" being saved at the end so I adapted the macro some more for my own use. Anyways I modified a line to:

Code:
ModName = Left(Model.GetTitle, InStrRev(Model.GetTitle, "Sheet") - 3)

in order to truncate that annoying little bit when passing it on to whomever is machining the part (or at least saving me the trouble of renaming it).

Figured someone else might find it helpful--I also suspect there is a setting in Solidworks that would directly remove that from being added to the filename. I wasn't sure, however, so I took the "easy" way out by doing a dirty job of removing the unwanted characters manually.

 
BiPolarMoment,
That last bit was exactly what I was looking for!!!
Now I had one other thing I would like to accomplish. We add the Revision letter to the pdf file name: "PartnumberRev.pdf". So in our part properties we have a custom property that is "Revision". When pdf'ing out the drawing, I would like to pull that info from the part file and add it to the "getfile" info so it would look like the example I showed above. Any suggestions or ideas???

Thank You
 
This code gets the model referenced by the first view found and loads the value of the custom property "Part_Number" into string variable sPartNo. It's out of a macro unrelated to this one, but you should be able to hammer out what's going on and rename/declare variables as needed.

IDontCare is a "dummy" variable (you can declare it as a Variant) that OpenDoc6 loads with some information that I can't remember what it is and never cared, hence the name.

Code:
    Set swView = swDrawing.GetFirstView
    out = 0
    While swView.GetReferencedModelName = ""
        Set swView = swView.GetNextView
        out = out + 1
        If out = 10 Then Exit Sub
        If swView Is Nothing Then Exit Sub
    Wend


    sRefModelName = swView.GetReferencedModelName       'get name of referenced part
    If swView.IsModelLoaded = False Then
        swView.LoadModel                'load the model if it ain't
    End If
    Set TargetPart = swApp.OpenDoc6(sRefModelName, swDocASSEMBLY, swOpenDocOptions_Silent, "", IDontCare, IDontCare) 'activate the part
    sPartNum = TargetPart.CustomInfo2("", "Part_Number")
 
Crap. I just noticed some poor programming. Replace the line

If swView.IsModelLoaded = False Then

with

If Not swView.IsModelLoaded Then


It works for me as-is, but the second way is preferred. At least I'm pretty sure it is. Maybe someone who knows proper programming can weigh in.
 
Sorry, I probably left too much "as an exercise". You will need to add:

Dim swDocType As Long
Dim sRefModelName As String
Dim swDrawing As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim TempModelName As String
Dim IDontCare As Long
Dim out as Integer
Dim TargetPart as SldWorks.ModelDoc2
Dim sPartNum as String

Then, add a couple of lines to the last bit of code. I've reposted it below with the additional lines. The additions are the leading IF statement and the line
Set swView = Model


Code:
If swDocType = swDocDRAWING Then
    Set swDrawing = Model
    Set swView = swDrawing.GetFirstView
    out = 0
    While swView.GetReferencedModelName = ""
        Set swView = swView.GetNextView
        out = out + 1
        If out = 10 Then Exit Sub
        If swView Is Nothing Then Exit Sub
    Wend


    sRefModelName = swView.GetReferencedModelName       'get name of referenced part
    If Not swView.IsModelLoaded Then
        swView.LoadModel                'load the model if it ain't
    End If
    Set TargetPart = swApp.OpenDoc6(sRefModelName, swDocASSEMBLY, swOpenDocOptions_Silent, "", IDontCare, IDontCare) 'activate the part
    sPartNum = TargetPart.CustomInfo2("", "Part_Number")
End If
 
For me the posted code works great as a macro. I want to use the code in a VB app (not a VBA macro). SaveAs4 then returns an error 256 - invalid file extension. Any ideas on why the code works in a macro environment but not in a VB app?

Here is my test VB 6 code:

Private swApp As SldWorks.SldWorks
Private swMdl As SldWorks.ModelDoc2


Private Sub Command1_Click()
Dim sPath As String
Dim sName1 As String, sName2 As String, sName3 As String
Dim sFile As String, sPDF As String, swExt As String

sPath = "D:\Test1\Solidworks\"
sName1 = "E00234-0000-D"
sName2 = "E00235-0000-D"
sName3 = "E00236-0000-D"
swExt = ".SLDDRW"

Set swApp = New SldWorks.SldWorks

swApp.Visible = True

For i = 0 To 2
Select Case i
Case 0
sFile = sPath & sName1 & swExt
sPDF = sPath & sName1 & ".pdf"
Case 1
sFile = sPath & sName2 & swExt
sPDF = sPath & sName2 & ".pdf"
Case 2
sFile = sPath & sName3 & swExt
sPDF = sPath & sName3 & ".pdf"
End Select

Dim oe As Long, ow As Long

Set swMdl = swApp.OpenDoc6(sFile, 3, 32 Or 1, "", oe, ow)

Dim bRes As Boolean, se As Long, sw As Long

bRes = swMdl.SaveAs4(sPDF, 0, 0, se, sw)

MsgBox "File = " & sFile & vbCr & "PDF = " & sPDF & vbCr & _
"Open Error = " & oe & vbCr & "Open Warning = " & ow & vbCr & _
"Result = " & bRes & vbCr & "Save Error = " & se & vbCr & _
"Save Warning = " & sw

Next

swApp.ExitApp
End Sub


variable se is returning 256 and bRes is returning False when I test in VB 6, but works great in macro.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor