Inventor Customization

Inventor Customization

Reply
Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 1 of 20 (1,847 Views)
Accepted Solution

iLogic Rule to ask YES or No for .DXF export when saving .IDW

1847 Views, 19 Replies
05-27-2013 07:00 AM

dontalways.png

 

Haha, little monday morning humour,

 

So I would like help with a simple rule if anyone has a few moments,

Basically, some of my drawings require a dxf for cnc purposes.
Not all my drawings, so I don't need a dxf for every drawing, just some.

 

It would be much quicker to have a rule that prompts a message box after I press save, stating something like

Do you require a .DXF?

 Yes    or     No.

 

I currently have a rule that saves all my .idw's as pdf, I am not sure if I should have a separate rule or if it can be part of the same rule. The pdf rule is triggered by a save as well.

 

'Save PDF with options
path_and_namePDF = ThisDoc.PathAndFileName(False) ' without extension
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") = 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

'Set the destination file name
oDataMedium.FileName = path_and_namePDF & ".pdf"

On Error Goto handlePDFLock
'Publish document.
Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

Exit Sub

handlePDFLock:
MessageBox.Show("PDF could not be saved, most likely someone else has it open.", _
"No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next

 

 

Thanks for any input!!

 

 

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49

Victory!

I used this reference to complete my rule, works great now:

 

http://inventortrenches.blogspot.ca/2011/03/using-yes-no-message-box-in-your-ilogic.html

 

Below is a rule that I have triggered by a save, once the drawing is saved a message box prompts asking if a .dxf is needed, yes or no. if yes is selected, the drawing will have a copy exported as .dxf with same name and location as .idw.

 

Hope it helps someone!!

 

thanks!

'query user
question = MessageBox.Show("is a .DXF Export Required", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'set condition based on answer
If question = vbYes Then
' Get the DXF translator Add-In.
path_and_nameDXF = ThisDoc.PathAndFileName(False)
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
'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 = 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
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\Users\Farr\Documents\Inventor\DXF_EXPORT_INI\DXF_EXPORT.ini"
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
oDataMedium.FileName = path_and_nameDXF & ".dxf"
Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If 

 

Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 2 of 20 (1,840 Views)

Re: iLogic Rule to ask YES or No for .DXF export when saving .IDW

05-27-2013 07:52 AM in reply to: SeanFarr

I searched this forum and came up with no results for any rules for exporting a dxf. I just did a google search and it found a post from this forum! the same search was done??

 

Oh well, here is the old post:

They have the following iLogic Rule for exporting to dxf, I have a questioin though, the OP states he has the rule set up to save to specific folder, I would like to save the dxf to the same directory as the .idw. Also i see in the rule he is referencing to an .ini file. What is that .ini file for and do I need it for my application?

 

Thanks (rule below)

 

' Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
'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 = 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

' Sets directory for file save
Dim DXFDirectory As String
DXFDirectory = "\\ServerName\Shared\DXF Folder\"
' Sets save name as iProperties value
Dim SaveName As String
SaveName = iProperties.Value("Project", "Part Number")

If Len(Dir(DXFDirectory, vbDirectory)) = 0 Then
	MkDir (DXFDirectory)
End If

' Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "\\HMI-ENGINEERING\Inventor_Data\Miscellaneous\dxf.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
'Set the destination file name
oDataMedium.FileName = ThisDoc.PathAndFileName(False) 
oDataMedium.FileName = DXFDirectory & SaveName & ".dxf"
'Publish document.
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'Launch the dxf file in whatever application Windows is set to open this document type with
i = MessageBox.Show("Preview the DXF file?", "DXF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)

 

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49
Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 3 of 20 (1,829 Views)

Re: iLogic Rule to ask YES or No for .DXF export when saving .IDW

05-27-2013 12:02 PM in reply to: SeanFarr

Update: the code below now produces a .dxf when I save a drawing.

It uses the same name and places it in the same directory,

 

The final step I would like, is once I press save on the drawing, I would like a message box to pop up asking if a .dxf export is required, if yes then run the rule, if no then just save document.

 

I will continue to play around with this tonight and post back if I can find a solution!

 

' Get the DXF translator Add-In.
path_and_nameDXF = ThisDoc.PathAndFileName(False)
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
'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 = 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

If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "\\TESSBSRV\Personal\sfarr\Documents\CAD_Documents\DXF_Export_INI\DXF_Export.ini"
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

oDataMedium.FileName = path_and_nameDXF & ".dxf"

Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

 

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49
Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 4 of 20 (1,826 Views)

Re: iLogic Rule to ask YES or No for .DXF export when saving .IDW

05-27-2013 02:36 PM in reply to: SeanFarr

Victory!

I used this reference to complete my rule, works great now:

 

http://inventortrenches.blogspot.ca/2011/03/using-yes-no-message-box-in-your-ilogic.html

 

Below is a rule that I have triggered by a save, once the drawing is saved a message box prompts asking if a .dxf is needed, yes or no. if yes is selected, the drawing will have a copy exported as .dxf with same name and location as .idw.

 

Hope it helps someone!!

 

thanks!

'query user

question = MessageBox.Show("is a .DXF Export Required", "iLogic Question",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

          'set condition based on answer
            If question = vbYes Then
			
' Get the DXF translator Add-In.
path_and_nameDXF = ThisDoc.PathAndFileName(False)
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
'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 = 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

If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\Users\Farr\Documents\Inventor\DXF_EXPORT_INI\DXF_EXPORT.ini"
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If

oDataMedium.FileName = path_and_nameDXF & ".dxf"

Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If 

 

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49
Mentor
MisterZS
Posts: 165
Registered: ‎08-24-2012
Message 5 of 20 (1,776 Views)

Re: iLogic Rule to ask YES or No for .DXF export when saving .IDW

06-07-2013 08:29 AM in reply to: SeanFarr

Hello,

code working perfect, but my first questionwould be: is it possible to run dxf for each sheet with sheet name. Second question is it possible to make dxf for each sheet but with option which sheet to be included in dxf formation

This second option would be just perfect time saver for me.

Thanks a lot

Valued Mentor
SeanFarr
Posts: 475
Registered: ‎07-25-2012
Message 6 of 20 (1,771 Views)

Re: iLogic Rule to ask YES or No for .DXF export when saving .IDW

06-07-2013 08:40 AM in reply to: MisterZS

I am going to say yes, you can bring up the same type dialogue to export specific sheets to dxf, however I am not a power iLogic user. Since I marked this thread solved, you may want to create a new thread/post and reference this one to it.

 

I typically never use multiple sheets, forget why exactly, but I find it much easier to just adjust the size of sheet if i need more room. Also any logic used becomes more difficult to write for this reason as well.

 

 

Sean Farr
Product Designer at TESInc.ca

Inventor Professional 2014-Update 2 - AutoCAD Electrical 2014
Win7-x64 | ASUS P8Z77-V | i7 3770 -3.4 GHz | 32GB RAM |
240GB SSD | nVidia GTX 670 4GB - 320.49
Mentor
MisterZS
Posts: 165
Registered: ‎08-24-2012
Message 7 of 20 (1,706 Views)

Re: iLogic Rule to ask YES or No for .DXF export when saving .IDW

06-19-2013 01:42 PM in reply to: SeanFarr

Ok thanks for reply. I took from your code most of that but still need to figureout some stuff. :smileyhappy:

Distinguished Contributor
drguitarum2005
Posts: 196
Registered: ‎10-08-2012
Message 8 of 20 (1,517 Views)

Re: iLogic Rule to ask YES or No for .DXF export when saving .IDW

09-04-2013 12:53 PM in reply to: MisterZS

I took the code from this thread and customized it a little (to our paths, etc.) and came up with a few issues:

 

The file name ends up being PartNumberPartNumber.dxf (using the actual part number). If I change the line

 

oDataMedium.FileName = DXFDirectory & SaveName & ".dxf"

 to

oDataMedium.FileName = SaveName & ".dxf"

 it cries at me. Where is it getting the part number twice?

 

 

Also, let's say I have a 2-sheet drawing. It creates:

 

Partnumber.dxf

Partnumber_SHEET_1.dxf

Partnumber_SHEET_2.dxf

 

When I do a manual Save Copy As>DXF, it creates the two "SHEET" files, but not the first one. That's the behavior I'd like to see.

 

Also, this doesn't happen on a single sheet drawing, but if the files already exist, it brings up a dialogue EVERY TIME to overwrite existing files. How can I force it to overwrite with no prompt?

 

Thanks

 

' Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
'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 = 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

' Sets directory for file save
Dim DXFDirectory As String
DXFDirectory = strFolder
' Sets save name as iProperties value
Dim SaveName As String
SaveName = iProperties.Value("Project", "Part Number")

' Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "\\server\Company Engineering Documents\Inventor 2013 Files\Save Templates\DXF Export.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
End If
'Set the destination file name
oDataMedium.FileName = ThisDoc.PathAndFileName(False) 
oDataMedium.FileName = DXFDirectory & SaveName & ".dxf"
'Publish document.
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'Launch the dxf file in whatever application Windows is set to open this document type with
i = MessageBox.Show("Preview the DXF file?", "DXF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)

 

(Never mind the "strFolder" variable. I set it above the code.)

Mentor
MisterZS
Posts: 165
Registered: ‎08-24-2012
Message 9 of 20 (1,513 Views)

Re: iLogic Rule to ask YES or No for .DXF export when saving .IDW

09-04-2013 01:02 PM in reply to: SeanFarr

'This is good rule change for your purpose path and folder

 

oPath = ThisDoc.Path

 

        oFileName = ThisDoc.FileName(False) 'without extension

 

        oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")

 

        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

 

Dim Response As MsgboxResult

 

        For Each oSheet In oDrawing.Sheets

 

            Response = MsgBox("Yes = Save or No = Continue to next Sheet?", MsgBoxStyle.YesNo, "Question")

            If Response = MsgBoxResult.Yes Then

 

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

 

 

 

                'get DXF target folder path

 

                oFolder = "C:\Test Folder"

 

 

 

                'Set the DXF target file name

 

                oDataMedium.FileName = oFolder & "\" & " " & sSheetName & " " & sSheetNumber & ".dxf"

 

 

                MessageBox.Show("DXF SAVED TO: " & oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK)

 

                'Publish document

 

                oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

 

            End If

        Next

 

 

 

Distinguished Contributor
drguitarum2005
Posts: 196
Registered: ‎10-08-2012
Message 10 of 20 (1,509 Views)

Re: iLogic Rule to ask YES or No for .DXF export when saving .IDW

09-04-2013 01:10 PM in reply to: MisterZS

I was able to get the filename working correctly. Now my only issue is that is is NOT automatically overwriting existing files. Everything I've ready said the SaveCopyAs function should overwrite without prompting. Any way to force the overwrite from my code?

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!