Inventor General Discussion

Inventor General Discussion

Reply
Valued Contributor
DVDM
Posts: 112
Registered: ‎09-24-2009
Message 11 of 38 (1,335 Views)

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

02-27-2012 06:11 PM in reply to: Curtis_Waguespack

Hi Curtis,

 

Fantastic, thanks for that!

It didn't work straight up, but all the clues were there for me to edit the code to get it to work the way it should, and give me the satisfaction of having achieved something myself, however small it may have been :smileyhappy:

Basically, what I have is this:

ABC-123.dwg

Containing sheets:

-05:1

-10:2

-34:3

And want as a result:

ABC-123-05.pdf

ABC-123-10.pdf

ABC-123-34.pdf

 

First I changed the code for the PDF target file as per below:

'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & sSheetName & ".pdf"

 

Now all the filenames were written correctly, but for some reason, all files were a print of the first sheet.

It took me some digging around to figure that one out. In the code I added a message box to return what the value for sSheetNumber was, and the correct values appeared. Yet I changed the code to just print sheet 3, it printed sheet 3, so why not when sSheetNumber had value 3? I realized it was because sSheetNumber was declared as String. I changed it to Integer, and it worked perfect this time around.

 

So the end result was this:

 

 '------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 Integer

'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 & "\" & oFileName & sSheetName & ".pdf"

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

Next
'------end of iLogic-------

Really appreciate your time in this, and trying to pick your code apart was a great learning curve.

I am still interested in how it would be possible to manipulate the filename for the dwg export.

 

*Expert Elite*
Curtis_Waguespack
Posts: 3,002
Registered: ‎03-08-2006
Message 12 of 38 (1,321 Views)

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

02-28-2012 01:33 PM in reply to: DVDM

Hi DVDM,

 

Congrats to you for catching my mistake and making this work for your needs, and sorry for the confusion concerning the string/integer variable. You're spot on, I checked what I was outputting and had the same result that you reported. I just hadn't opned the PDFs to look closely and notice ( I was just watching the file names in the output folder).

 

So, now on to the DWG rule. Do you want this to work just as your last PDF rule works, then?

 

You I have:

ABC-123.dwg

Containing sheets:

-05:1

-10:2

-34:3

And want as a result:

ABC-123-05.dwg (ACAD 2004 format)

ABC-123-10.dwg (ACAD 2004 format)

ABC-123-34.dwg (ACAD 2004 format)

 

I hope this helps.
Best of luck to you in all of your 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.





Valued Contributor
DVDM
Posts: 112
Registered: ‎09-24-2009
Message 13 of 38 (1,317 Views)

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

02-28-2012 03:26 PM in reply to: Curtis_Waguespack

Hi Curtis,

 

That's the goal, to have it output two file types with identical filenames, so I can have one rule that runs the two external rules for PDF and DWG

What I have currently is close, so as output I'll get:

ABC-123_-05.dwg

ABC-123_-10.dwg

ABC-123_-34.dwg

ABC-123-05.pdf

ABC-123-10.pdf

ABC-123-34.pdf

 

But from what I can tell the '_' is just an automatic addition by the DWG export function, and probably needs more in depth knowledge to change this.

If it's possible at all, because if the Sheet revision is a hidden or non-accessible property, who knows what else is.

Contributor
james.rammos
Posts: 23
Registered: ‎02-27-2012
Message 14 of 38 (1,304 Views)

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

03-01-2012 04:01 AM in reply to: Curtis_Waguespack

Can somebody change the ilogic to save the PDF in the same folder as the DWG/IDW?

*Expert Elite*
Curtis_Waguespack
Posts: 3,002
Registered: ‎03-08-2006
Message 15 of 38 (1,295 Views)

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

03-01-2012 07:22 AM in reply to: james.rammos

Hi james.rammos, 

 

Here are a couple of rules that will do this.

 

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

 

 

You can use this rule to save each sheet individually into the same folder that the DWG/IDW resides in:

 

 

 '------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 iSheetNumber As Integer

'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

'Set the PDF target file name
oDataMedium.FileName = oPath & "\" & oFileName & "_" & sSheetName & sSheetNumber & ".pdf"

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

Next
'------end of iLogic-------

 

 

And you can use this rule to save each sheet as a single PDF into the same folder that the DWG/IDW resides in:

 

 '------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

'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.kPrintAllSheets
End If

'Set the PDF target file name
oDataMedium.FileName = oPath & "\" & oFileName &  ".pdf"

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

'------end of iLogic-------

 



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





Contributor
james.rammos
Posts: 23
Registered: ‎02-27-2012
Message 16 of 38 (1,289 Views)

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

03-01-2012 11:21 AM in reply to: Curtis_Waguespack

Thank you Curtis, 

 

I will try it as soon as i get back to the office.

Active Contributor
128848
Posts: 31
Registered: ‎01-16-2013
Message 17 of 38 (872 Views)

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

03-03-2013 02:40 AM in reply to: Curtis_Waguespack

Old thread, but I hope I will get a sponse since I`ve been doing the same.

 

I took your code Curtis and added the revision number into the filename.

 

But I'm wondering, is it possible to decide where in the filename the rev number shall appear?

 

Example: 12345-100 Rev 02 - Module 1 - Details

 

The .idw would in that case be named 12345-100 - Module 1 - Details

 

'------- 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 
oRevNum = iProperties.Value("Project", "Revision Number")
oFileName = ThisDoc.FileName(False) 'without extension

' 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") = 29
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 

oFolder = ThisDoc.Path

'Set the DWG target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" Rev " & oRevNum & ".dwg"
DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
'------- end of iLogic code ------------------- 

lection: 314

Distinguished Contributor
danvang
Posts: 110
Registered: ‎02-28-2008
Message 18 of 38 (807 Views)

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

03-08-2013 08:09 AM in reply to: 128848

Not sure if you got an answer to this or not but you will have insert the rev into the file name string. You will need the location in the string. You can get the location by finding it based on a character or you can specified the exact location. Both example are show below. Then use the insert method to place in the "Rev" and the oRevNum. Have this before you save the file. hope that helps.

 

'find the location based on the first space in the string
'Dim intIndex As Integer = oFileName.IndexOf(" ")

 

'use a specified location
Dim intIndex As Integer = 9

oFileName = oFileName.Insert(intIndex, " Rev " & oRevNum)

Contributor
james.rammos
Posts: 23
Registered: ‎02-27-2012
Message 19 of 38 (789 Views)

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

03-15-2013 02:42 AM in reply to: GustavStigsohn

Hi,

 

I tryed to put in the rule for DWG export and i keep getting error message. (see picture below)

 

Anybody knows how to fix this?

 

 

 

Distinguished Contributor
danvang
Posts: 110
Registered: ‎02-28-2008
Message 20 of 38 (772 Views)

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

03-15-2013 08:56 AM in reply to: james.rammos

post up the code you have. The code from Curtis should work.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.