iLogic printing to DXF

iLogic printing to DXF

JorisSteurs1246
Advocate Advocate
1,640 Views
16 Replies
Message 1 of 17

iLogic printing to DXF

JorisSteurs1246
Advocate
Advocate

I have this code to save out drawings to DXF but it is not behaving consistent.

Sometimes the a new dxf file for each sheet was created but sometimes it would overwrite the previous sheet also.

So I decided to give each sheet a unique name and use this  sheet name as part of the filename of the DXF to make.

So far so good...

But now

The code below is working , it outputs a new file for every sheet with the correct name.

The problem that I can't figure out with this code is, that the files are created without the .dxf extension and the size is 0 Kb .

 

 

SyntaxEditor Code Snippet

'***** DXF'***** use the custom rule copy Iprops from model to drawing to get the Part Number on the drawing.

oFolderDXF = (oPath & "\output\DXF")
oDataMediumDXF = ThisApplication.TransientObjects.CreateDataMedium
oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

If Not System.IO.Directory.Exists(oFolderDXF) Then
    System.IO.Directory.CreateDirectory(oFolderDXF)
End If

' Check whether the translator has 'SaveCopyAs' options
If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\Users\kasutaja\Documents\Inventor\MY support files\AI2012_to_DXF2004_NotAllSheets.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

Dim oCurrentNumber  As Sheet
oCurrentNumber = ThisApplication.ActiveDocument.ActiveSheet
    
' Iterate through the sheets
Dim oSheet As Sheet
For Each oSheet In ThisApplication.ActiveDocument.Sheets
    oSheet.Activate
    If oSheet.ExcludeFromPrinting = False Then
    'run DXF code here
Dim oSheetName As Object
oSheetName = oSheet.Name()
MessageBox.Show("I found variable: " & oSheetName , "Info")
oDataMediumDXF.FileName = ThisDoc.PathAndFileName(False)
oDataMediumDXF.FileName = oFolderDXF &"\"& oPN & "--" & oFileName &  oSheetName & ".dxf"
'oDataMediumDXF.FileName = ThisDoc.PathAndFileName(False)'oDataMediumDXF.FileName = oFolderDXF &"\"& oPN & "--" & oFileName & ".dxf"
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumDXF)
End If
Next
' Return to original active sheet
oCurrentNumber.Activate



sSpace = ""
sDots = "              ----------        "
MessageBox.Show("Drawing is printed as PDF and saved in : " & oFolderPDF _
& vbLf & ""& sDots _
& vbLf & ""& sSpace _
& vbLf & "Drawing is printed as DXF and saved in : "& oFolderDXF _
& vbLf & ""& sDots _
& vbLf & ""& sSpace _
& vbLf & " Click OK to save drawing and close this box. "   , "DONE!")
ThisDoc.Save
Goto Alldone

Endrule :

MessageBox.Show("No PDF or DXF was saved ", "Info")

  
Alldone :

 

0 Likes
Accepted solutions (1)
1,641 Views
16 Replies
Replies (16)
Message 2 of 17

Owner2229
Advisor
Advisor

HI, the problem seems to be in oFilename (the same counts for oPN). You're ussing it as part of the file name, it it's not defined anywhere. And you had oSheetName defined as Object. You were also missing the context creation. See the correction and test it out. The blue is what I changed or added.

 

'***** DXF ***** use the custom rule copy Iprops from model to drawing to get the Part Number on the drawing.
Dim oDocument As Document
oDocument = ThisDoc.Document
Dim oFileName As String
oFileName = ThisDoc.FileName(False)
Dim oFolderDXF As String oFolderDXF = oPath & "\output\DXF" oDataMediumDXF = ThisApplication.TransientObjects.CreateDataMedium oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById _ ("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
' Create the saving folder if it doesn't exist If Not System.IO.Directory.Exists(oFolderDXF) Then System.IO.Directory.CreateDirectory(oFolderDXF) End If
' Create transaction context
Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Check whether the translator has 'SaveCopyAs' options If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then oOptions.Value("DwgVersion") = 25
Dim strIniFile As String strIniFile = "C:\Users\kasutaja\Documents\Inventor\MY support files\AI2012_to_DXF2004_NotAllSheets.ini"
' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile End If Dim oCurrentNumber As Sheet oCurrentNumber = ThisApplication.ActiveDocument.ActiveSheet ' Iterate through the sheets Dim oSheet As Sheet For Each oSheet In ThisApplication.ActiveDocument.Sheets oSheet.Activate If oSheet.ExcludeFromPrinting = False Then ' Run DXF code here Dim oSheetName As String oSheetName = oSheet.Name MessageBox.Show("I found variable: " & oSheetName , "Info") oDataMediumDXF.FileName = oFolderDXF & "\" & oFileName & " - " & oSheetName & ".dxf" oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumDXF) End If Next
' Return to original active sheet oCurrentNumber.Activate sSpace = "" sDots = " ---------- " MessageBox.Show("Drawing is printed as PDF and saved in : " & oFolderPDF _ & vbLf & ""& sDots _ & vbLf & ""& sSpace _ & vbLf & "Drawing is printed as DXF and saved in : "& oFolderDXF _ & vbLf & ""& sDots _ & vbLf & ""& sSpace _ & vbLf & " Click OK to save drawing and close this box. " , "DONE!") ThisDoc.Save Goto Alldone Endrule : MessageBox.Show("No PDF or DXF was saved ", "Info") Alldone :

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 17

JorisSteurs1246
Advocate
Advocate

Hi Mike,

Sorry for being not more careful.

The missing declarations weer just not copied over because I've a block of code in the same rule that saves as PDF and that's where filename and path are declared.

The problem I was focusing on was the "oSheetName" I've declared it in a few different ways because when ever I ad this var to the filename it doesn't save as .dxf anymore but without extension.

When i remove "oSheetName" it will save out as .dxf but every sheet will overwrite the previous.  

So I made a new rule with your code and I still get empty files without extention.

I only get a proper .dxf file if I remove "oSheetName" from the name asigning line.

These 2 lines are in the code below with some comment. You can activate one or the other and check it on your machine.

Keep in mind that the drawing should have more than 2 sheets in order to have a correct test.

 

 

 

SyntaxEditor Code Snippet

Question = MessageBox.Show("If you closed this rule but don't want to run it now, click cancel.","Attention",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button2)
If Question = vbOK Then
MessageBox.Show("Rule will continue", "CADsherpa")
'***** DXF ***** use the custom rule copy Iprops from model to drawing to get the Part Number on the drawing.'***** save folders 
oPath = ThisDoc.WorkspacePath
Dim oDocument As Document
oDocument = ThisDoc.Document
Dim oFileName As String
oFileName = ThisDoc.FileName(False)
Dim oPN As String
oPN = iProperties.Value("Project", "Part Number")

Dim oFolderDXF As String
oFolderDXF = oPath & "\output\DXF"
oDataMediumDXF = ThisApplication.TransientObjects.CreateDataMedium
oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

' Create the saving folder if it doesn't exist
If Not System.IO.Directory.Exists(oFolderDXF) Then
    System.IO.Directory.CreateDirectory(oFolderDXF)
End If

' Create transaction context
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Check whether the translator has 'SaveCopyAs' options
If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
    oOptions.Value("DwgVersion") = 25
    Dim strIniFile As String
    strIniFile = "C:\Users\kasutaja\Documents\Inventor\MY support files\AI2012_to_DXF2004_NotAllSheets.ini"

    ' Create the name-value that specifies the ini file to use.
    oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

Dim oCurrentNumber As Sheet
oCurrentNumber = ThisApplication.ActiveDocument.ActiveSheet
    
' Iterate through the sheets
Dim oSheet As Sheet
For Each oSheet In ThisApplication.ActiveDocument.Sheets
    oSheet.Activate
    If oSheet.ExcludeFromPrinting = False Then
        ' Run DXF code here
        Dim oSheetName As String
        oSheetName = oSheet.Name
        MessageBox.Show("I found variable: " & oSheetName , "Info")
        'oDataMediumDXF.FileName = oFolderDXF & "\" & oFileName & " - " & oSheetName & ".dxf"  '***** this gives files with 0KB and no extention
        oDataMediumDXF.FileName = oFolderDXF &"\"& oPN & "--" & oFileName & ".dxf" '***** this gives a .dxf that is good but every sheet overwrites the previous
        oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumDXF)
    End If
Next

' Return to original active sheet
oCurrentNumber.Activate

sSpace = ""
sDots = "              ----------        "
MessageBox.Show("Drawing is printed as PDF and saved in : " & oFolderPDF _
& vbLf & ""& sDots _
& vbLf & ""& sSpace _
& vbLf & "Drawing is printed as DXF and saved in : "& oFolderDXF _
& vbLf & ""& sDots _
& vbLf & ""& sSpace _
& vbLf & " Click OK to save drawing and close this box. "   , "DONE!")
ThisDoc.Save

Else

Goto  EndRule

End If


EndRule:

 

0 Likes
Message 4 of 17

Owner2229
Advisor
Advisor
Accepted solution

Hi, unfortunately I can't test it, because I don't have your INI file and it doesn't work with mine.

But I believe I know what's causing the isssue. Each sheet has symbol ":" in name. This symbol can't be in any file name in Windows.

So here is the fix:

 

 

Question = MessageBox.Show("If you closed this rule but don't want to run it now, click cancel.","Attention",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button2)
If Question = vbOK Then
MessageBox.Show("Rule will continue", "CADsherpa")
'***** DXF ***** use the custom rule copy Iprops from model to drawing to get the Part Number on the drawing.'***** save folders 
oPath = ThisDoc.WorkspacePath
Dim oDocument As Document
oDocument = ThisDoc.Document
Dim oFileName As String
oFileName = ThisDoc.FileName(False)
Dim oPN As String
oPN = iProperties.Value("Project", "Part Number")

Dim oFolderDXF As String
oFolderDXF = oPath & "\output\DXF"
oDataMediumDXF = ThisApplication.TransientObjects.CreateDataMedium
oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

' Create the saving folder if it doesn't exist
If Not System.IO.Directory.Exists(oFolderDXF) Then
    System.IO.Directory.CreateDirectory(oFolderDXF)
End If

' Create transaction context
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Check whether the translator has 'SaveCopyAs' options
If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
    oOptions.Value("DwgVersion") = 25
    Dim strIniFile As String
    strIniFile = "C:\Users\kasutaja\Documents\Inventor\MY support files\AI2012_to_DXF2004_NotAllSheets.ini"

    ' Create the name-value that specifies the ini file to use.
    oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

Dim oCurrentNumber As Sheet
oCurrentNumber = ThisApplication.ActiveDocument.ActiveSheet
    
' Iterate through the sheets
Dim oSheet As Sheet
For Each oSheet In ThisApplication.ActiveDocument.Sheets
    oSheet.Activate
    If oSheet.ExcludeFromPrinting = False Then
        ' Run DXF code here
        Dim oSheetName As String
        oSheetName = oSheet.Name
oSheetName = Replace(oSheetName, ":", "-")
MessageBox.Show("I found variable: " & oSheetName , "Info") oDataMediumDXF.FileName = oFolderDXF & "\" & oFileName & " - " & oSheetName & ".dxf" '***** this gives files with 0KB and no extention 'oDataMediumDXF.FileName = oFolderDXF &"\"& oPN & "--" & oFileName & ".dxf" '***** this gives a .dxf that is good but every sheet overwrites the previous oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumDXF) End If Next ' Return to original active sheet oCurrentNumber.Activate sSpace = "" sDots = " ---------- " MessageBox.Show("Drawing is printed as PDF and saved in : " & oFolderPDF _ & vbLf & ""& sDots _ & vbLf & ""& sSpace _ & vbLf & "Drawing is printed as DXF and saved in : "& oFolderDXF _ & vbLf & ""& sDots _ & vbLf & ""& sSpace _ & vbLf & " Click OK to save drawing and close this box. " , "DONE!") ThisDoc.Save Else Goto EndRule End If EndRule:

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 5 of 17

JorisSteurs1246
Advocate
Advocate

I'll quickly wanted to post the .ini file here but I get an error as it has no valid extention

 

0 Likes
Message 6 of 17

Owner2229
Advisor
Advisor

You can rename it form *.ini to *.txt. It should work after that.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 7 of 17

JorisSteurs1246
Advocate
Advocate

Hi Mike,

 

Thank you so much , you were 100pct right. 

This 1 line of code added and everything works perfectly.

The sheet name is something really weird because default it is just on every sheet  "Sheet"

Than there is also a counter  that places a number behind teh sheet and that changes depending the fact if a sheet is excluded from printing or not.

Anyhow it works now, 

 

Thanks again

 

Joris

 

 

0 Likes
Message 8 of 17

JorisSteurs1246
Advocate
Advocate

.Ini file attached as .txt file.

Please change extension back to .ini and change the location of the file in the code accordingly

 

0 Likes
Message 9 of 17

Anonymous
Not applicable

Hello and thank you for contirbuting the dxf pdf rule for Inventor.  I am trying to use it but get the following errors:

 

Do you know what could cause these errors? 

 

Capture.PNG

0 Likes
Message 10 of 17

JorisSteurs1246
Advocate
Advocate

You can remove all code untill the point where it says  '************ DXF

Run the code again and see where the error marks the code in blue

 

Let me know if that helps

 

Joris

0 Likes
Message 11 of 17

Anonymous
Not applicable

 Thank you!  I am now down to just the following errors on the lines shown (line 71 is highlighted); I wonder if this is related to pasting?

 

Capture.PNG

0 Likes
Message 12 of 17

Anonymous
Not applicable

That did help and the dxf is working flawlessly; now I need to get a pdf generated fo reach as well.

0 Likes
Message 13 of 17

JorisSteurs1246
Advocate
Advocate

yes the error says what is the problem,

 

you have to check if  your code is contructed like this

 

 

If My_Expression Then

' code here

Else

' code here ( or empty)

End If

 

0 Likes
Message 14 of 17

JorisSteurs1246
Advocate
Advocate

Pdf is more  easy, you'll find it here on the forum also.

0 Likes
Message 15 of 17

TA.Fehr
Advocate
Advocate

I don't mean to hijack, but i've run into a similar issue. I've got a dxf output that follows the example, but it still spits out a corrupt dxf.

I've written it in vb.net as part of an add-in so that's why its slightly different. I am able to run it through vba without issue, but then it defeats the point of an add-in.

 

Private Sub SMDXF(DXFSource As String)
        Dim oPartDoc As Document = _invApp.ActiveDocument
        Dim oCompDef As ComponentDefinition = oPartDoc.ComponentDefinition
        Dim oDef As ControlDefinition
        If oCompDef.HasFlatPattern = False Then
            'go to flat pattern or create it if it doesn't exist
            oCompDef.Unfold()
            oDef = _invApp.CommandManager.ControlDefinitions.Item("PartSwitchRepresentationCmd")
            oDef.Execute()
            'Return to folded model
            oDef = _invApp.CommandManager.ControlDefinitions.Item("PartConvertToSheetMetalCmd")
            oDef.Execute()
            'Get active document
        End If
       
        Dim oDXFAddin As TranslatorAddIn = Nothing
        For i As Long = 1 To _invApp.ApplicationAddIns.Count
            If _invApp.ApplicationAddIns.Item(i).ClassIdString = "{C24E3AC4-122E-11D5-8E91-0010B541CD80}" Then
                oDXFAddin = _invApp.ApplicationAddIns.Item(i)
                Exit For
            End If
        Next
        If oDXFAddin Is Nothing Then
            MsgBox("The DXF Add-in could not be found")
            Exit Sub
        End If
        If Not oDXFAddin.Activated Then oDXFAddin.Activate()
        Dim oContext As TranslationContext = _invApp.TransientObjects.CreateTranslationContext
        oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
        Dim oNameValueMap As NameValueMap = _invApp.TransientObjects.CreateNameValueMap
        If oDXFAddin.HasSaveCopyAsOptions(oPartDoc, oContext, oNameValueMap) Then
            oNameValueMap.Value("DwgVersion") = 25
            Dim strIniFile As String = "P:\Inventor System Files\Inventor Add Ins and Programs\IO Profile.ini"
            oNameValueMap.Value("Export_Acad_IniFile") = strIniFile
        End If

        Dim oOutputFile As DataMedium = _invApp.TransientObjects.CreateDataMedium
        oOutputFile.FileName = DXFSource

        Call oDXFAddin.SaveCopyAs(oPartDoc, oContext, oNameValueMap, oOutputFile)

    End Sub

 

 

The only way I've been able to make it work is to use:

        Dim oDataIO As DataIO
        oDataIO = oCompDef.DataIO
        Build the string that defines the format of the DXF file
        Dim sOut As String
        sOut = "FLAT PATTERN DXF?AcadVersion=2010&OuterProfileLayer=CUT&InteriorProfilesLayer=CUT"
        oDataIO.WriteDataToFile(sOut, DXFSource)

But this doesn't give me the flexibility of the .ini file.

Any suggestions?

0 Likes
Message 16 of 17

JorisSteurs1246
Advocate
Advocate

Because it runs in VBA but not as an Add -In,  the nature of your problem might be diffent from what is discussed here.

Problebly you'll be more succesfull when posting this as a new post.

 

Joris

0 Likes
Message 17 of 17

Anonymous
Not applicable

Just to help anyone else and close the book on this: this rule is generating dxf and pdf as we want them, a multipage pdf and individual dxf files for each page in the drawing file.  Thank you to the community for the help in putting this together!  Been working for us for a few weeks now.

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 44791 StartFragment: 314 EndFragment: 44759 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

'*****Sheet Qty
Dim oDrawing As DrawingDocument
oDrawing = ThisApplication.ActiveDocument
Dim osheet As Sheet
i = 0
'tally the sheets that are set to be excluded
For Each osheet In oDrawing.Sheets
If osheet.ExcludeFromCount = True Then
i = i + 1
Else
End If
Next

'subtract the excluded sheet from the number of sheets in the sheet collection
oMySheetCount = oDrawing.Sheets.Count - i

'***** DXF use the custom rule copy Iprops from model to drawing to get the Part Number on the drawing.'***** save folders 
Dim oDocument As Document
oDocument = ThisDoc.Document
Dim oFileName As String
oFileName = ThisDoc.FileName(False)
Dim oPN As String
oPN = iProperties.Value("Project", "Part Number")

Dim oFolderDXF As String
oFolderDXF = "Y:\Manufacturing Release"
oDataMediumDXF = ThisApplication.TransientObjects.CreateDataMedium
oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

' Create the saving folder if it doesn't exist
If Not System.IO.Directory.Exists(oFolderDXF) Then
    System.IO.Directory.CreateDirectory(oFolderDXF)
End If

' Create transaction context
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

' Check whether the translator has 'SaveCopyAs' options
If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
    oOptions.Value("DwgVersion") = 25
    Dim strIniFile As String
    strIniFile = "C:\Workspace\Inventor to AutoCad 2004 dxf Model data only.ini"

    ' Create the name-value that specifies the ini file to use.
    oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

Dim oCurrentNumber As Sheet
oCurrentNumber = ThisApplication.ActiveDocument.ActiveSheet
    
' Iterate through the sheets
For Each oSheet In ThisApplication.ActiveDocument.Sheets
    oSheet.Activate
    If oSheet.ExcludeFromPrinting = False Then
        ' Run DXF code here
        Dim oSheetName As String
        oSheetName = oSheet.Name
        If oMySheetCount >1
            oSheetName = Replace(oSheetName, ":", "_")
            'MessageBox.Show("Located: " & oSheetName , "Info")
            oDataMediumDXF.FileName = oFolderDXF & "\" & oFileName & "_" & oSheetName & ".dxf"  '***** this gives files with 0KB and no extention
        Else
               oDataMediumDXF.FileName = oFolderDXF & "\" & oFileName & ".dxf"  '***** this gives files with 0KB and no extention
        End If
        'oDataMediumDXF.FileName = oFolderDXF &"\"& oPN & "--" & oFileName & ".dxf" '***** this gives a .dxf that is good but every sheet overwrites the previous
        oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMediumDXF)
    End If
Next

' Return to original active sheet
oCurrentNumber.Activate

sSpace = ""
sDots = "              ----------        "

'***** PDF 

oPath = "Y:\Manufacturing Release"
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

If oPDFAddIn.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

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

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

' alternative oFileName value
oFileName = ThisDoc.PathAndFileName(False).Replace(ThisDoc.WorkspacePath(), "J:")
' your code.....' oFolder
oFolder = oFileName.Replace(ThisDoc.FileName(False),"")
' your code....' oDataMedium.FileName
oDataMedium.FileName = oFileName & ".pdf"

MessageBox.Show("Drawing saved as multi-sheet .pdf and individual .dxf files: "& oFolderDXF)

Endrule: