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

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

Anonymous
Not applicable
9,012 Views
22 Replies
Message 1 of 23

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

Anonymous
Not applicable

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

 

 

Accepted solutions (1)
9,013 Views
22 Replies
Replies (22)
Message 2 of 23

Anonymous
Not applicable

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)

 

0 Likes
Message 3 of 23

Anonymous
Not applicable

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)

 

0 Likes
Message 4 of 23

Anonymous
Not applicable
Accepted solution

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 

 

Message 5 of 23

GosponZ
Collaborator
Collaborator

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

0 Likes
Message 6 of 23

Anonymous
Not applicable

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.

 

 

0 Likes
Message 7 of 23

GosponZ
Collaborator
Collaborator

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

0 Likes
Message 8 of 23

Anonymous
Not applicable

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

0 Likes
Message 9 of 23

GosponZ
Collaborator
Collaborator

'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

 

 

 

0 Likes
Message 10 of 23

Anonymous
Not applicable

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?

0 Likes
Message 11 of 23

Anonymous
Not applicable

My problem with overwriting doesn't exist when there is only a single sheet. The problem is when there are 2 or more sheets. Inventor automatically (somehow, somewhere) appends the "_SHEET_X" to the end of each sheet when creating the DXFs. That's fine for new files but it apparently can't overwrite those without my input. Is there a way to either force that overwrite OR delete the files (could be x number of sheets) right before the .SaveCopyAs() function?

0 Likes
Message 12 of 23

GosponZ
Collaborator
Collaborator

With this rule i gave you i do not have no problem.

0 Likes
Message 13 of 23

Anonymous
Not applicable
Still the same issue. If the DXF already exists, it brings up the "save copy as" dialogue and warns me about saving over it...
0 Likes
Message 14 of 23

Anonymous
Not applicable

Here's what I ended up with and it works perfectly:

 

'query user

question = MessageBox.Show("is a .DXF Export Required?" & vbNewLine & "WARNING: This operation will overwrite existing DXF files!", "Export to DXF",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

          'set condition based on answer
            If question = vbYes Then


'Bunch of IF statements here to set strFolder to the path I want the particular DXF saved in, based off the name of the drawing file


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

If ThisDoc.Document.Sheets.Count > 1 Then
	For sheet_count = 1 To ThisDoc.Document.Sheets.Count
		If Len(Dir(DXFDirectory & SaveName & "_SHEET_" & sheet_count & ".dxf")) <> 0 Then
			Kill(DXFDirectory & SaveName & "_SHEET_" & sheet_count & ".dxf")
		Else If Len(Dir(DXFDirectory & SaveName & ".dxf")) <> 0 Then
			Kill(DXFDirectory & SaveName & ".dxf")
		End If
	Next sheet_count
End If

'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? " & SaveName & " " & ThisDoc.Document.Sheets.Count, "DXF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)
End If

 

0 Likes
Message 15 of 23

Anonymous
Not applicable

Hi,

 

When you run a rule I have some error messages.

 

Rule Compile Errors in Eksport DXF, in eksport DXF.idw

Error on Line 3 : Element "Questi" is not a member of the element

„System.Windows.Forms.MessageBoxIcon”.

Error on Line 3 : Expected comma character ")" and follow the correct expression

Error on Line 19 : Expected end of statement.

Error on Line 23 : Expected end of statement.

 

How to solve these problems

 

Best regards,

KSwietochowski

0 Likes
Message 16 of 23

Anonymous
Not applicable
Can you post your code?
0 Likes
Message 17 of 23

GosponZ
Collaborator
Collaborator

I did yesterday. Go to first page.

0 Likes
Message 18 of 23

Anonymous
Not applicable

Not you, KSwietochowski who was having the issue

0 Likes
Message 19 of 23

Anonymous
Not applicable

Hi,

 

The code has been completely copied from your post above.

 

 

'query user

question = MessageBox.Show("is a .DXF Export Required?" & vbNewLine & "WARNING: This operation will overwrite existing DXF files!", "Export to DXF",MessageBoxButtons.YesNo,MessageBoxIcon.Question)

          'set condition based on answer
            If question = vbYes Then


'Bunch of IF statements here to set strFolder to the path I want the particular DXF saved in, based off the name of the drawing file


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

If ThisDoc.Document.Sheets.Count > 1 Then
For sheet_count = 1 To ThisDoc.Document.Sheets.Count
If Len(Dir(DXFDirectory & SaveName & "_SHEET_" & sheet_count & ".dxf")) <> 0 Then
Kill(DXFDirectory & SaveName & "_SHEET_" & sheet_count & ".dxf")
Else If Len(Dir(DXFDirectory & SaveName & ".dxf")) <> 0 Then
Kill(DXFDirectory & SaveName & ".dxf")
End If
Next sheet_count
End If

'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? " & SaveName & " " & ThisDoc.Document.Sheets.Count, "DXF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)
End If

 

 

 

Best regards,

KSwietochowski

0 Likes
Message 20 of 23

Anonymous
Not applicable

Those errors are being flagged up because some unicode characters have been added when you use windows copy and paste command.Smiley Frustrated

If you copy the code from the forum into notepad, and then copy it from notepad into your new rule, you will find that these errors should not be flagged up. Hope this helps Smiley Wink

0 Likes