Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Save PDF using iLogic and name after revision number?

47 REPLIES 47
SOLVED
Reply
Message 1 of 48
GustavStigsohn
14548 Views, 47 Replies

Save PDF using iLogic and name after revision number?

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

 

47 REPLIES 47
Message 2 of 48
danvang
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

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang
Message 3 of 48

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/

 

 

Message 4 of 48

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

Message 5 of 48
DVDM
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!

Message 6 of 48
Curtis_Waguespack
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 ------------------- 

 

Message 7 of 48

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

 

 

 

Message 8 of 48
DVDM
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!

Message 9 of 48
DVDM
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.

 

Message 10 of 48
Curtis_Waguespack
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-------

 

Message 11 of 48
DVDM
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 🙂

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.

 

Message 12 of 48
Curtis_Waguespack
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

 

 

Message 13 of 48
DVDM
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.

Message 14 of 48

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

Message 15 of 48

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

 

Message 16 of 48

Thank you Curtis, 

 

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

Message 17 of 48
128848
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

Message 18 of 48
danvang
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)

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang
Message 19 of 48

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?

 

 

 

Message 20 of 48
danvang
in reply to: james.nahani

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

** If my reply resolves this issue, please choose "Accept as Solution" **
Dan Vang

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report