- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone
I have an ilogic rule that creates PDF files from an iam.
now I also want to have an overhaul.
I have added revision but unfortunately this is not working.
Does anyone know what I did wrong
DI-A-0030-00026 SHU.idw (Sheet-1) rev1
Sub Main()
'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
Dim oAsmName As String
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
'get user input
RUsure = MessageBox.Show ( _
"This will create a PDF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create PDF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
oPath = ThisDoc.Path
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oRevNum = iProperties.Value("Project", "Revision Number")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
ExPath = "C:\Users\j.kleijnjans\Documents\PDF_DXF_STP\" & "PDF_DXF_STP"
If Not System.IO.Directory.Exists(ExPath) Then
System.IO.Directory.CreateDirectory(ExPath)
End If
' Define the active document As an Assembly file
oIdwPathName = ThisDoc.ChangeExtension(".idw")
'ThisApplication.CommandManager.ControlDefinitions.Item("AppFileCloseCmd").Execute
' Look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document
' Work the the drawing files for the referenced models. This expects that the model has a drawing of the same path and name
For Each oRefDoc In oRefDocs
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
' Check to see that the model has a drawing of the same path and name
If(System.IO.File.Exists(idwPathName)) Then
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
i = 1
'blader door sheets en exporteer
For Each oSheet In oDrawDoc.Sheets
ThisApplication.ActiveDocument.Sheets.Item(i).Activate
ThisApplication.ActiveView.Fit
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim iSheet As Sheet
iSheet = oDoc.ActiveSheet
Dim oFileName As String
oFileName = Left(oDoc.DisplayName, Len(oDoc.DisplayName) - 4)'0
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim iSheetNumber As Integer
Dim ExportFolder As String
'find the seperator in the sheet name:number
lPos = InStr(iSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(iSheet.Name)
'find the sheet name
sSheetName = Left(iSheet.Name, lPos -1)
'find the sheet number
iSheetNumber = Right(iSheet.Name, sLen -lPos)
'set PDF Options
'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oRevNum = iProperties.Value("Project", "Revision Number")
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
'oDataMedium.FileName = ExPath & "\" & "(" & sSheetName & "-" & ").pdf"
oDataMedium.FileName = ExPath & "\" & oFileName & " " & "(" & sSheetName & "-" & i & ")" & "_" & oRevNum & ".pdf"
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'sheet index ophogen
i=i+1
Next
oDrawDoc.Close ' Close the file
End If
Next
'idw van opstaande samenstelling exporteren
If(System.IO.File.Exists(oIdwPathName)) Then
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.Documents.Open(oIdwPathName, True)
i = 1
'blader door sheets en exporteer
For Each oSheet In oDrawDoc.Sheets
ThisApplication.ActiveDocument.Sheets.Item(i).Activate
ThisApplication.ActiveView.Fit
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
Dim iSheet As Sheet
iSheet = oDoc.ActiveSheet
Dim oFileName As String
oFileName = Left(oDoc.DisplayName, Len(oDoc.DisplayName)-4)
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim iSheetNumber As Integer
Dim ExportFolder As String
'find the seperator in the sheet name:number
lPos = InStr(iSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(iSheet.Name)
'find the sheet name
sSheetName = Left(iSheet.Name, lPos -1)
'find the sheet number
iSheetNumber = Right(iSheet.Name, sLen -lPos)
'set PDF Options
'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oRevNum = iProperties.Value("Project", "Revision Number")
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
'Set the PDF target file name
oDataMedium.FileName = ExPath & "\" & oFileName & " " & "(" & sSheetName & "-" & i & ")"& "_" & oRevNum &".pdf"
'oDataMedium.FileName = ExPath & "\" & oFileName & " " & "(" & sSheetName & "-" & i & ").pdf"
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'sheet index ophogen
i=i+1
Next
oDrawDoc.Close ' Close the file
End If
'MessageBox.Show("PDF-bestanden opgeslagen")
MessageBox.Show("PDF FILES ARE READY")
proceed1 :
End Sub
Solved! Go to Solution.