04-18-2018
11:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
04-18-2018
11:24 AM
1. The "basic" iProperty call only corresponds to the DOCUMENT of which the rule is run from. You need to add in a document identifier to get it to access iProperties from another file (only valid for files that are children of the current document).
iproperties.Value(System.IO.Path.GetFileName(filename), "Project", "Part Number")
2. You should probably remove the error catching surrounding the iProperties/save commands.
2. Use Application.SilentOperation = True at the start of the code, and Application.SilentOperation = False at the end.
Sub Main()
Dim oDoc As Document
oDoc = ThisDoc.Document
oDocName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kDrawingDocumentObject) Then
MessageBox.Show("Please run this rule from the assembly or assembly drawing file.", "iLogic")
Exit Sub
End If
Application.SilentOperation = True
'get user input
If MessageBox.Show ( _
"This will create a PDF file for all of the asembly components that have drawings files." _
& vbLf & "This rule expects that the drawing file shares the same name and location as the component." _
& vbLf & " " _
& vbLf & "Are you sure you want to create PDF Drawings for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then
Exit Sub
End If
Dim PDFAddIn As TranslatorAddIn
Dim oContext As TranslationContext
Dim oOptions As NameValueMap
Dim oDataMedium As DataMedium
Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
oPath = ThisDoc.Path
oFolder = "C:\PDF" & "\" & oAsmName & " PDF Files\"
oPath = System.IO.Directory.GetParent(oPath).FullName
If System.IO.Directory.Exists(oFolder) = False Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
Dim oRefDoc As Document
Dim fileName As String
For Each oRefDoc In oDoc.AllReferencedDocuments
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4)
For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw",System.IO.SearchOption.AllDirectories)
If fileName.EndsWith(oFileName + ".idw") = True Then
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.Documents.Open(fileName, True)
oRevNum = iProperties.Value(System.IO.Path.GetFileName(fileName), "Project", "Revision Number")
oDataMedium.FileName = oFolder & "\" & oFileName & "-R" & oRevNum & ".pdf"
Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
oDrawDoc.Close(True)
End If
Next
Next
'- - - - - - - - - - - - -
'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
Dim oAsmDrawingName As String = ThisDoc.FileName(False) 'without extension
For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw", System.IO.SearchOption.AllDirectories)
If fileName.EndsWith(oAsmDrawingName + ".idw") = True Then
Dim oAsmDrawingDoc As DrawingDocument
oAsmDrawingDoc = ThisApplication.Documents.Open(fileName, True)
oAsmRevNum = iProperties.Value("Project", "Revision Number")
oDataMedium.FileName = oFolder & oAsmDrawingName & "-R" & oAsmRevNum & ".pdf"
Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
oAsmDrawingDoc.Close(True)
End If
Next
Application.SilentOperation = False
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub
Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
oPath = ThisDoc.Path
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 1
'oOptions.Value("Custom_End_Sheet") = 1
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization

iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type