Title block Update and Print PDF

Title block Update and Print PDF

Anonymous
Not applicable
3,298 Views
15 Replies
Message 1 of 16

Title block Update and Print PDF

Anonymous
Not applicable

I am a novice at Ilogic. So for give me if there is a simple fix for this. 

 

Here is what I need to do.

I need to make pdfs for each of the components in the assembly. I have found some ones code for this. 

 

What I want to before it makes a PDF is this.

***indicate I have a working ilogic code

1. Copy old prompted entry***

3. Update the Scale***

4. Replace the Title Block***

5. Print PDF***

 

Shouldn't it just be as simple as adding the line below for each of the separate rules?

iLogicVb.RunExternalRule("ruleFileName")

 

When I add this to the code and run it I get and error code.

 

Please help

 

Thanks,

Josh

0 Likes
Accepted solutions (1)
3,299 Views
15 Replies
Replies (15)
Message 2 of 16

MechMachineMan
Advisor
Advisor

It should be. With PROPER programming.

 

You use "ActiveDocument" calls in your code. Active Document calls only grab the document that is at the forefront of the application, not the document the rule was called from.

 

You should be using ThisDoc.Document to get the document the rule is called from.

 

Also, you might not need to activate each sheet, which slows down code, and could probably just access them directly, but that depends on the capabilities of the functions called.

 

**The 2 rules below, the first is the modified version of OP's "PDF Print", the 2nd one is the verbatim text from OP's attached "Change Titleblock.txt"**

 

Sub Main()

On Error Resume Next
Dim oDrawingDoc As Inventor.DrawingDocument: oDrawingDoc = ThisDoc.Document If Err.Number <> 0 Then
MsgBox ("Please open a Drawing to work on.") Exit Sub
End if On Error GoTo 0 'reference template ThisDrawing.ResourceFileName = "C:\Work\InventorResources\Templates\R2017\XXXX.idw" 'XXXX removed name ThisDrawing.KeepExtraResources = False Dim SheetNumber As Integer 'Clear out the old Titleblocks & Sheetformats For SheetNumber = 1 To oDrawingDoc.Sheets.Count oDrawingDoc.Sheets(SheetNumber).Activate If Not oDrawingDoc.ActiveSheet.TitleBlock Is Nothing Then oDrawingDoc.ActiveSheet.TitleBlock.Delete End If Next SheetNumber
'Delete the previous title blocks as the API does not support replacing Sheet Formats.'DeleteSheetFormatsAll (oDrawingDoc)'DeleteBorders (oDrawingDoc) DeleteTitleBlocks (oDrawingDoc) Dim resu1t As String="Result" Dim T1TLE As New ArrayList T1TLE.Add("XXXX") 'XXXX removed name ActiveSheet.SetTitleBlock("XXXX", "", "", "") 'XXXX removed name End Sub Sub DeleteTitleBlocks(oActiveDoc As Inventor.DrawingDocument) 'Iterate through the collection deleting any titleblocks that are not referenced by the drawing object Dim oTitle As TitleBlockDefinition For Each oTitle In oActiveDoc.TitleBlockDefinitions If oTitle.IsReferenced = False Then oTitle.Delete End If Next End Sub
'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
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 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)

If RUsure = vbNo Then
Return
Else
End If

'- - - - - - - - - - - - -PDF setup - - - - - - - - - - - -
oPath = ThisDoc.Path
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If

'get PDF target folder path
oFolder = oPath & "\" & oAsmName & " PDF Files"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
'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)
    oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)
    
iLogicVb.RunExternalRule("CAD NAME")
iLogicVb.RunExternalRule("FINISH")
iLogicVb.RunExternalRule("SCALE X")
iLogicVb.RunExternalRule("CHANGE TITLE BLOCK")


    On Error Resume Next ' if PDF exists and is open or read only, resume next
     'Set the PDF target file name
    oDataMedium.FileName = oFolder & "\" & oFileName & "pdf"
    'Write out the PDF
    Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
    'close the file
    oDrawDoc.Close
Else
'If the model has no drawing of the same path and name - do nothing
End If
Next
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
oAsmDrawing = ThisDoc.ChangeExtension(".idw")
oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True)
oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3)
'write out the PDF for the Top Level Assembly Drawing file
On Error Resume Next ' if PDF exists and is open or read only, resume next
 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf"
'Write out the PDF
Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
'Close the top level drawing
oAsmDrawingDoc.Close
'- - - - - - - - - - - - -

MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new ffiles are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)

 


--------------------------------------
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
0 Likes
Message 3 of 16

Anonymous
Not applicable

Okay I have Updated the code for the Print Pdf. I am still getting the same error.

 

Why is "Change Title Block" trying to run only in the assembly and not the print that is pulled up?

0 Likes
Message 4 of 16

Anonymous
Not applicable

okay the following code will open every drawing,

how do i apply a rule after its open?

 

 

SyntaxEditor Code Snippet

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
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
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'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)
            oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)


                
Else
'If the model has no drawing of the same path and name - do nothing
End If
Next
'- - - - - - - - - - - - -



 

 

0 Likes
Message 5 of 16

MechMachineMan
Advisor
Advisor

M:Autodesk.iLogic.Interfaces.IiLogicAutomation.RunExternalRule(Inventor.Document,System.String)

 

Resources:

-https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2018...

- iLogic API Documentation link in my signature

 

Sub Main()
On Error Resume Next
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
If Err.Number <> 0 Then
MsgBox("This rules is only valid for assembly documents!",,"MacroMagic")
Exit Sub
End if
ON Error GoTo 0
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4) Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments Dim oRefDoc As Document For Each oRefDoc In oRefDocs idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
If(System.IO.File.Exists(idwPathName)) Then Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)

iLogicVb.RunExternalRule(oDrawDoc, "RuleNameHere")
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)
End if Next
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
0 Likes
Message 6 of 16

Anonymous
Not applicable

Error in rule: OPEN ALL DRAWINGS, in document: 24138-003-0005.iam

Unable to cast COM object of type 'Inventor._DocumentClass' to class type 'System.String'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

0 Likes
Message 7 of 16

MechMachineMan
Advisor
Advisor

The iLogic function call isn't working. 

 

It has in the past, and I even tried getting the applicationaddin, but it still wasn't working.


--------------------------------------
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
Message 8 of 16

Anonymous
Not applicable

Thanks for the help. 

Will try some different routes.

 

I might have to do some things with Code injector and drawing transfer wizard. 

0 Likes
Message 9 of 16

Anonymous
Not applicable

@Curtis_Waguespack could you take a moment and look this over for me?

Thanks,

Josh

0 Likes
Message 10 of 16

MechMachineMan
Advisor
Advisor

@MjDeck might be a better one to see if there is a bug or another issue, if he has time.


--------------------------------------
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
0 Likes
Message 11 of 16

Anonymous
Not applicable

I would appreciate any help. 

Basically I am trying to do the same thing as the Drawing Transfer Wizard, but keep the prompted entry's.

Thanks,

Josh 

 

0 Likes
Message 12 of 16

MechMachineMan
Advisor
Advisor

You could also just rewrite to rule to be everything within one rule, just utilizing various sub-routines... that way, you don't have to use the iLogic functionality.


--------------------------------------
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
0 Likes
Message 13 of 16

Anonymous
Not applicable

I would like to but I am not that good at writing and debugging code.

0 Likes
Message 14 of 16

MechMachineMan
Advisor
Advisor

Well then I guess that leaves you with a couple options.

 

1. Revise your needs

2. Find a solution online

3. Pay somebody to make you a solution

4. Learn how to make your own solution

5. Hope somebody passes you a solution for free out of the goodness in their heart.


--------------------------------------
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
0 Likes
Message 15 of 16

MjDeck
Autodesk
Autodesk
Accepted solution

Instead of this line:

iLogicVb.RunExternalRule(oDrawDoc, "RuleNameHere")

use this:

iLogicVb.Automation.RunExternalRule(oDrawDoc, "RuleNameHere")


Mike Deck
Software Developer
Autodesk, Inc.

Message 16 of 16

Anonymous
Not applicable

Thank you both for all your help!

0 Likes