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: 

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

22 REPLIES 22
SOLVED
Reply
Message 1 of 23
Anonymous
8521 Views, 22 Replies

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

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

 

 

22 REPLIES 22
Message 21 of 23
Anonymous
in reply to: Anonymous

your posts are always very helpful and thank you for sharing.
I have a question, I would like to convert to DXF only sheet 2, but with the rule over always creates all sheets, how can I do?
Where am I wrong?

 my rule

 

oPath = "C:\Users\luca\Documents\DIS DA SPEDIRE\esportati in automatico\"

oFileName = ThisDoc.FileName(False) 'without extension

 

If iProperties.Value(modelName,"Project", "Revision Number") = "" Then

iProperties.Value("Project", "Revision Number")= "--"

End If

 

If Not iProperties.Value(modelName,"Project", "Revision Number") = "" Then

iProperties.Value("Project", "Revision Number")= iProperties.Value(modelName,"Project", "Revision Number")

End If

 

 

If iProperties.Value(modelName,"Status", "Status") = "" Then

iProperties.Value("Status", "Status")= "--"

End If

 

If Not iProperties.Value(modelName,"Status", "Status") = "" Then

iProperties.Value("Status", "Status")= iProperties.Value(modelName,"Status", "Status")

End If

 

oRevision = iProperties.Value("Project", "Revision Number")

oStatus = iProperties.Value("Status", "Status")

 

 

txt5=iProperties.Value("Summary", "Keywords")

 

' 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

'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

       

         sSheetName= "SAGOMA"

 

        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)

                    End If

        Next

 

' Check whether the translator has 'SaveCopyAs' options

If dxfAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

Dim strIniFile As String

strIniFile = "M:\Ufficio Tecnico\INVENTOR STANDARD\Design Data 2013\DWG-DXF\DWG OK2 exportdwg .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

 

oFolder ="C:\Users\luca.leocata\Documents\DIS DA SPEDIRE\esportati in automatico\"

oDataMedium.FileName = oFolder & oFileName & "  " & oStatus &  "  Rev. " & oRevision & "  " & " " & txt5 & ".dxf"

'Publish document.

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

 

output idw to dxf.JPG

 

thank's 

 

 

Message 22 of 23
GosponZ
in reply to: Anonymous

Ok here is code that I'm using daily, yes is to create dxf from sheet and no is not. Place path where you want this dxf's to go.

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 numbe

           sSheetNumber = Right(oSheet.Name, sLen - lPos)

End If

ActiveSheet = ThisDrawing.Sheet(oSheet.Name)

           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 numbe

           sSheetNumber = Right(oSheet.Name, sLen - lPos)

 

 

 

     'get DXF target folder path

 

               oFolder = "N:\YOUR PATH HERE DXF FILES"

 

 

 

               '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

 

 

 

 

Message 23 of 23
aronmatheus
in reply to: GosponZ

I Found this ruler:

But I would change because the external line of the sheet it don't go out when I print.

 

' 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
' Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "G:\Inventor 2016\iLogic\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) & ".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?", "Title",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)

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

Post to forums  

Autodesk Design & Make Report