ilogic code to save a pdf copy of a dwg - but with revision extension

ilogic code to save a pdf copy of a dwg - but with revision extension

Anonymous
Not applicable
729 Views
2 Replies
Message 1 of 3

ilogic code to save a pdf copy of a dwg - but with revision extension

Anonymous
Not applicable

Hi All, 

 

First time posting on this forum and relatively new to all this ilogic code. I have searched extensively for solution to this problem and can't seem to find it exactly. 

 

I want to create a pdf copy of a dwg but with an added extension that details the revision number. The catch here is that the revision number needs to be from the assembly that the drawing is of and NOT the revision number from the drawing. ie. the revision number extension should be the number that you see in the title block of the drawing. 

 

This is the code that i have been working on but there is an error - i believe it is in the part of the code referring to the Sheet. 

 

SyntaxEditor Code Snippet

    '' Get the PDF translator Add-In.
    Dim PDFAddIn As TranslatorAddIn
    PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

    '' Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    '' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    '' Create a DataMedium object
    Dim oDataMedium As DataMedium
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    '' Check whether the translator has 'SaveCopyAs' options
    If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

       ' ' Options for drawings...
        oOptions.Value("All_Color_AS_Black") = 0
        oOptions.Value("Remove_Line_Weights") = 0
        oOptions.Value("Vector_Resolution") = 600
        oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
        '' oOptions.Value("Custom_Begin_Sheet") = 2
        '' oOptions.Value("Custom_End_Sheet") = 4
    End If

    '' Pick up the revision number
    Dim oSheet As Sheet
    oTitleblock = oSheet.TitleBlock
    oRevNum = oTitleBlock.GetResultText(oTitleBlock.Definition.Sketch.TextBoxes.Item(6))


    '' Set the destination file name
    oDataMedium.FileName = ThisDoc.Path & "\" & ThisDoc.FileName & "_rev" & oRevNum & ".pdf"
 

    '' Publish document.
    Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
    

 

I get an error saying this:

Error in rule: PDF Saver, in document: 812.100.70_Approval.dwg

Object reference not set to an instance of an object.

 

Can anyone help me out or shed any light? Any help would be greatly appreciated. 

 

Cheers, Finn

0 Likes
Accepted solutions (1)
730 Views
2 Replies
Replies (2)
Message 2 of 3

tdant
Collaborator
Collaborator
Accepted solution

You aren't setting oSheet to any object. There needs to be some line after "Dim oSheet as Sheet" that tells that variable what sheet you mean. If you're looking for the active sheet of the drawing, then it would be

 

oSheet = oDocument.ActiveSheet

assuming that oDocument is referring to a drawing file.

0 Likes
Message 3 of 3

Anonymous
Not applicable

Yeah that is great thanks a lot! It works perfectly after adding that line. 

 

To anyone else reading this: please note that this code is picked up from other stuff i have found on the internet and is not my own work! 

 

The Item number (in my case being 6) for the textbox containing the revision number was found using the helpful bit of ilogic from the following thread:

 

https://forums.autodesk.com/t5/inventor-customization/drawing-sheet-revision-ilogic/td-p/6751832

 

My overall code is this: (If anyone else looking to use something like this you just need to change your item number)

 

 

SyntaxEditor Code Snippet

'' Get the PDF translator Add-In.
    Dim PDFAddIn As TranslatorAddIn
    PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

    '' Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    '' Create a NameValueMap object
    Dim oOptions As NameValueMap
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    '' Create a DataMedium object
    Dim oDataMedium As DataMedium
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    '' Check whether the translator has 'SaveCopyAs' options
    If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

       ' ' Options for drawings...
        oOptions.Value("All_Color_AS_Black") = 0
        oOptions.Value("Remove_Line_Weights") = 0
        oOptions.Value("Vector_Resolution") = 600
        oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
        '' oOptions.Value("Custom_Begin_Sheet") = 2
        '' oOptions.Value("Custom_End_Sheet") = 4
    End If

    '' Pick up the revision number
    Dim oSheet As Sheet
    oSheet = oDocument.ActiveSheet
    oTitleblock = oSheet.TitleBlock
    oRevNum = oTitleBlock.GetResultText(oTitleBlock.Definition.Sketch.TextBoxes.Item(6))


    '' Set the destination file name
    oDataMedium.FileName = ThisDoc.Path & "\" & ThisDoc.FileName & "_rev" & oRevNum & ".pdf"
 

    '' Publish document.
    Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

 

 

 

0 Likes