Message 1 of 7

Not applicable
08-15-2017
10:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The ThisApplication.Activeview.Fit line does not work on the first opened drawing. All of the others it corrects.
I've seen this issue around before, maybe there's some random thing I can run before fitting the view so that it snaps back and forth and gets it working.
Function fileExists(fname) As Boolean If Dir(fname) <> "" Then fileExists = True Else fileExists = False End Function Public Sub IDWtoPNG() Dim oAsmDoc As AssemblyDocument Set oAsmDoc = ThisApplication.ActiveDocument If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MsgBox "This code prints our drawings for assembly documents only.", vbExclamation Exit Sub End If If MsgBox("Did you hit print to PNG by accident?", vbYesNo + vbQuestion) = vbYes Then Exit Sub End If dirPath = Left(oAsmDoc.fullfilename, Len(oAsmDoc.fullfilename) - Len(oAsmDoc.DisplayName)) Dim oRefDocs As DocumentsEnumerator Set oRefDocs = oAsmDoc.AllReferencedDocuments Dim oRefDoc As Document 'numFiles = 0 Dim temp As String Dim temper As String Dim basefilename As String Dim fullfilename As String Dim prefix As String Dim prefixer As String For Each oRefDoc In oRefDocs idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw" If fileExists(idwPathName) Then 'numFiles = numFiles + 1 Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.Documents.Open(idwPathName, True) oDrawDoc.Activate Set oDrawDoc = ThisApplication.ActiveDocument 'Get the active view. Dim oView As View Set oView = ThisApplication.ActiveView ThisApplication.ActiveView.Fit ' Save the view as a jpg file. prefix = oAsmDoc.FullDocumentName temper = Right$(prefix, Len(prefix) - InStrRev(prefix, "\")) prefixer = Left(temper, Len(temper) - 4) fullfilename = idwPathName temp = Right$(fullfilename, Len(fullfilename) - InStrRev(fullfilename, "\")) basefilename = Left$(temp, InStrRev(temp, ".") - 1) oPngFileName = "C:\IDW's\" & prefixer & basefilename & ".png" Call oView.SaveAsBitmap(oPngFileName, 3000, 2320) oDrawDoc.Close (True) End If Next MsgBox "It is complete! It is complete." End Sub
Solved! Go to Solution.