• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor

    Reply
    Contributor
    GustavStigsohn
    Posts: 15
    Registered: ‎06-21-2011
    Accepted Solution

    Save PDF using iLogic and name after revision number?

    1551 Views, 24 Replies
    07-07-2011 07:48 AM

    Hello!

     

    My question: We want to use iLogic to save a PDF-file of the DWG-drawing every time we hit "save". We now use the following iLogic code:

     

    

    Spoiler
    oPath = ThisDoc.Path PN = iProperties.Value("Project", "Part Number") PDFAddIn = 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  If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1 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  'Set the destination file name oDataMedium.FileName = oPath & "\" & PN & ".pdf"  'Publish document PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions,oDataMedium)  'Confirmation message MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName ,"PDF Saved", MessageBoxButtons.OK)

     

    Question 1: Is it possible to save the PDF in a new folder that lies "one step up". For example: My DWG-file is placed in c:/drawings/thing4/DWG, I want the PDF to end up in c:/drawings/thing4/PDF. If I am in folder "c:/drawings/thing2/DWG" I want the PDF to end up in "c:/drawings/thing2/PDF" etc. Possible?

     

    Question 2: My DWG files is named "thing4.dwg" and it is the 2nd revision. I want the PDF-file to be named

    "thing4 Ed2.pdf". Possible?

     

    Any help would be very appreciated!

    /Gustav

     

    Please use plain text.
    Valued Contributor
    Posts: 56
    Registered: ‎02-28-2008

    Re: Save PDF using iLogic and name after revision number?

    07-07-2011 02:11 PM in reply to: GustavStigsohn

    1. Yes you can. You will just need to use a different path instead of oPath in this line: oDataMedium.FileName = oPath & "\" & PN & ".pdf"  'Publish document 

     

    2. Yes this is possible. You will need to get the revision of the file using iProperties.value("Project, "Revision Number") and set it as a variable. Then in your code when you give the PDF the file name, you will need to append that to the file name.

     

    So what you want to do can be done.

     

    BTW, this question may be best in the Inventor Customization forum.

     

    Dan

    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,964
    Registered: ‎03-08-2006

    Re: Save PDF using iLogic and name after revision number?

    07-07-2011 06:44 PM in reply to: GustavStigsohn

    Hi GustavStigsohn,

     

    You can find an example rule at this link:

    http://inventortrenches.blogspot.com/2011/07/ilogic-to-save-pdf-files-to-new.html

     

    I hope this helps,

    Best of luck to you in all of your iLogic and Inventor pursuits,

    Curtis

    http://inventortrenches.blogspot.com/

     

     



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    Contributor
    GustavStigsohn
    Posts: 15
    Registered: ‎06-21-2011

    Re: Save PDF using iLogic and name after revision number?

    07-07-2011 11:20 PM in reply to: Curtis_Waguespack

    Big thanks to you both! It works like a charm.

    Please use plain text.
    Valued Contributor
    Posts: 112
    Registered: ‎09-24-2009

    Re: Save PDF using iLogic and name after revision number?

    02-23-2012 05:07 PM in reply to: Curtis_Waguespack

    Hi Curtis,

     

    I tried the iLogic code from your link, and it works very well. I was able to modify the code to suit our pdf file naming conventions. Do you know how to change the code to get it to save a drawing to AutoCAD.dwg (2004) format as well?

     

    We also have quite a few Inventor drawings that have multiple drawing sheets per drawing file.

    The drawing number for each sheet is taken from the Part Number field of the part or assembly detailed on that sheet. These different sheets have individual revisions, which is driven by the <Sheet Revision> property.

    So we have an Inventor drawing file like this:

    ABC-123.dwg, which contains drawing numbers:

    ABC-123-01, ABC-123-02, ABC-123-03 etc.

    It would be a real time saver if we could export all sheets in one iLogic rule to separate PDF's, i.e.:

    ABC-123-01rev2.pdf

    ABC-123-02rev1.pdf

    ABC-123-03rev0.pdf

     

    I'm only just starting out with iLogic so am not yet equipped to take your code and customize to suit my needs.

    Appreciate any help!

    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,964
    Registered: ‎03-08-2006

    Re: Save PDF using iLogic and name after revision number?

    02-24-2012 08:24 AM in reply to: DVDM

    Hi DCDM,

     

    Here is an example rule that tranlsates an Inventor drawing to an AutoCAD 2004 DWG.

     

    I hope this helps.
    Best of luck to you in all of your Inventor pursuits,
    Curtis
    http://inventortrenches.blogspot.com

     

    '------- start of iLogic code ------------------- 
    ' Get the DWG translator Add-In. 
    Dim DWGAddIn As TranslatorAddIn 
    DWGAddIn = ThisApplication.ApplicationAddIns.ItemById _
    ("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 
    
    'Set a reference to the active document 
    Dim oDocument As Document 
    oDocument = ThisApplication.ActiveDocument 
    Dim oContext As TranslationContext 
    oContext = ThisApplication.TransientObjects.CreateTranslationContext 
    oContext.Type = IOMechanismEnum.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 DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then 
        ' DWG version.
        ' 23 = ACAD 2000
        ' 25 = ACAD 2004
        ' 27 = ACAD 2007
        ' 29 = ACAD 2010 
        oOptions.Value("DwgVersion") = 25
    Dim strIniFile As String 
    strIniFile = "C:\temp\DWGout.ini" 
    ' Create the name-value that specifies the ini file to use. 
    oOptions.Value("Export_Acad_IniFile") = strIniFile 
    End If 
    
    'get path and file name
    path_and_name = ThisDoc.PathAndFileName(False) ' without extension
    
    'Set the DWG target file name
    oDataMedium.FileName = path_and_name & ".DWG"
    DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
    '------- end of iLogic code ------------------- 

     



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,964
    Registered: ‎03-08-2006

    Re: Save PDF using iLogic and name after revision number?

    02-24-2012 09:13 AM in reply to: Curtis_Waguespack

    Hi DVDM,

     

    Here is a rule that will write out each sheet to a PDF following the naming scheme you mentioned. But I wasn't able to find the hook to use the Sheet Revision property. Maybe someone will have a look and point us to it. In the mean time this should get you started.

     

    I hope this helps.
    Best of luck to you in all of your Inventor pursuits,
    Curtis
    http://inventortrenches.blogspot.com

     

    '------start of iLogic-------
    oPath = ThisDoc.Path
    oFileName = ThisDoc.FileName(False) 'without extension
    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
    
    'Define the drawing 
    Dim oDrawing As DrawingDocument
    oDrawing = ThisDrawing.Document
    'Count the sheets
    Dim intNumSheets As Integer
    intNumSheets = oDrawing.Sheets.Count
    Dim intIndex As Integer
    For intIndex = 1 To intNumSheets
    
    If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange oOptions.Value("Custom_Begin_Sheet") = intIndex oOptions.Value("Custom_End_Sheet") = intIndex End If 'get PDF target folder path oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF" '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 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFileName & "-0" & intIndex & ".pdf" 'Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Next '------end of iLogic-------

     

     

     



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    Valued Contributor
    Posts: 112
    Registered: ‎09-24-2009

    Re: Save PDF using iLogic and name after revision number?

    02-26-2012 05:31 PM in reply to: Curtis_Waguespack

    Hi Curtis,

     

    Thanks for those, very much appreciated!

    I've tested both, and both work pretty well, but would like to do a bit of finetuning, and ask you a few more questions.

     

    The save to dwg rule doesn't seem to save to Acad 2004 format, but to 2010 format (which is the default setting for the exporter), so it ignores the Options.Value setting from your rule. I checked by looking at the file header which is AC1024, which should be AC1018 for Acad 2004 format.

    Your rule packs the drawings into a zip file, but by default this 'pack and go' option is unticked. So the questions is, how are these options controlled? Does the C:\temp\DWGout.ini file play a role in this? I don't actually know what this file currently does, or how to store configuration settings in it if possible.

    The one other niggle is that during the export the filename gets the addition of a _ in the filename (i.e. ABC-123_-01.DWG), but as it's done by the built in exporter and not the rule that invokes it this might not be possible to change?

     

    Your export to pdf works very well, but would like to finetune the naming convention. For example:

    ABC-123.dwg contains:

    ABC-123-01, ABC-123-02, ......, up to ABC-123-99

    This currently saves out to ABC-123-01, ABC-123-02,......, ABC-123-099. You add the "-0" to the filename, but after 10 sheets the "-0" should no longer apply.

    But this is only when we have a fully sequential set of sheets without any gaps.

    Say we have a 3 sheet drawing like this:

    ABC-123-05, ABC-123-10, ABC-123-34

    This currently saves out to ABC-123-01, ABC-123-02, ABC-123-03.

     

    This could be solved two different ways. The way the "Export to dwg" tool does it would work quite well, by using the sheet name. We name our sheets like this: -05, -10, -34, so in the model tree for the drawing you see: -05:1, -10:2, -34:3. If this value could be used to append the filename that would be the most straightforward fix.

     

    The drawing number also matches the part number of the component detailed. The title block picks up the <Part Number> value of the model, so this one drawing file with 3 sheets would be detailing ABC-123-05.iam, ABC-123-10.ipt & ABC-123-34.ipt.

    Since a sheet can contain many base views to different parts and assemblies you wouldn't be able to establish which one to use, unless it would be able to pick it based on the first view placed, similar to how the title block knows to pick to <Part Number> from the first view.

     

    I've only just started learning how to use iLogic last week, so wouldn't be able to write anything this complex with VB in it. Reading through the code I'm able to get an idea what's going on, and can imagine being able to do something like that once I know VB myself. One thing that puzzles me though is the 

    ItemById _
    ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

    code. Where are you supposed to find something like that? 

     

    Appreciate your help!

    Please use plain text.
    Valued Contributor
    Posts: 112
    Registered: ‎09-24-2009

    Re: Save PDF using iLogic and name after revision number?

    02-26-2012 07:51 PM in reply to: DVDM

    I figured out how to get that ini file to work:

    http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/Export-sheet-to-DWG/td-p/3341737

     

    So I'd be able to set up different ini files, that are called upon by different iLogic rules, that'll be pretty handy.

     

    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,964
    Registered: ‎03-08-2006

    Re: Save PDF using iLogic and name after revision number?

    02-27-2012 10:41 AM in reply to: DVDM

    Hi DVDM,

     

    Let's focus on just the PDF part of this for now and come back to the DWG export. If I understand correctly, this rule should output the PDF's per sheet as such:

     

    A drawing has 3 sheets:

    ABC-123-05:1

    ABC-123-10:2

    ABC-123-34:3

    the rule writes out 3 PDF's:

    ABC-123-05.pdf

    ABC-123-10.pdf

    ABC-123-34.pdf

    and places them in a folder named PDF that resides next to the drawing file:

    C:\Temp\ABC-123-05.dwg

    C:\Temp\PDF\ABC-123-05.pdf

    C:\Temp\PDF\ABC-123-10.pdf

    C:\Temp\PDF\ABC-123-34.pdf

     

    Let me know if this is what you're after.

     

    I hope this helps.
    Best of luck to you in all of your Inventor pursuits,
    Curtis
    http://inventortrenches.blogspot.com

     

    '------start of iLogic-------
    oPath = ThisDoc.Path
    oFileName = ThisDoc.FileName(False) 'without extension
    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
    
    'Define the drawing 
    Dim oDrawing As DrawingDocument
    oDrawing = ThisDoc.Document
    
    Dim oSheet As Sheet
    Dim lPos As Long
    Dim rPos As Long
    Dim sLen As Long
    Dim sSheetName As String
    Dim sSheetNumber As String 
    
    'step through each drawing sheet
    For Each oSheet In oDrawing.Sheets 'find the seperator in the sheet name:number lPos = InStr(oSheet.Name, ":") 'find the number of characters in the sheet name sLen = Len(oSheet.Name) 'find the sheet name sSheetName = Left(oSheet.Name, lPos -1) 'find the sheet number sSheetNumber = Right(oSheet.Name, sLen -lPos ) 'set PDF Options If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange oOptions.Value("Custom_Begin_Sheet") = sSheetNumber oOptions.Value("Custom_End_Sheet") = sSheetNumber End If 'get PDF target folder path oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF" '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 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & sSheetName & ".pdf" 'Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Next '------end of iLogic-------

     



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.