iLogic for exporting .dxf as polylines - Share, anyone?

iLogic for exporting .dxf as polylines - Share, anyone?

EagleBee93
Advocate Advocate
275 Views
6 Replies
Message 1 of 7

iLogic for exporting .dxf as polylines - Share, anyone?

EagleBee93
Advocate
Advocate

I've been working with ChatGPT for the past hour trying (for the first time ever!) to write an iLogic script that does the following: 

 

Save Copy As > .DXF (from a .DWG file)

Let's me select each sheet that i want to export (each sheet has multiple base views of different CNC parts)

Exports each sheet as one .dxf file (does this for all sheets selected)

Converts all  linework to polylines

Prompts me for location of where i want to save the file

 

I can't get it just right, and the one time it did work it took literally 30 seconds to export each sheet, even sheets with just one base view. does anyone have a similar script theyd be willing to share?

0 Likes
276 Views
6 Replies
Replies (6)
Message 2 of 7

Andrii_Humeniuk
Advisor
Advisor

Hi @EagleBee93 . You need to set the MergeProfilesIntoPolyline = True setting in the DXF file export properties. Code example:

Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2018&MergeProfilesIntoPolyline=True"

To have a better chance of helping you, I need you to share your code sample.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 7

EagleBee93
Advocate
Advocate

Imports System.Windows.Forms

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheets As Sheets = oDoc.Sheets
Dim selectedSheets As New List(Of String)

' Create a form to select sheets
Dim form As New Form()
form.Text = "Select Sheets to Export"
form.Width = 500
form.Height = 600
form.FormBorderStyle = FormBorderStyle.FixedDialog
form.StartPosition = FormStartPosition.CenterScreen

' Create a panel for scrolling
Dim panel As New Panel()
panel.AutoScroll = True
panel.Dock = DockStyle.Top
panel.Height = 450
form.Controls.Add(panel)

Dim checkBoxes As New List(Of CheckBox)
Dim yPosition As Integer = 10

' Add checkboxes for each sheet
For Each oSheet As Sheet In oSheets
Dim checkBox As New CheckBox()
checkBox.Text = oSheet.Name
checkBox.AutoSize = True
checkBox.Top = yPosition
checkBox.Left = 10
checkBoxes.Add(checkBox)
panel.Controls.Add(checkBox)
yPosition += 25
Next

' Export button
Dim confirmButton As New Button()
confirmButton.Text = "Export Selected"
confirmButton.Top = yPosition + 20
confirmButton.Left = 10
confirmButton.Width = 150
form.Controls.Add(confirmButton)

' Event handler for button click
AddHandler confirmButton.Click, Sub(sender As Object, e As EventArgs)
For Each checkBox As CheckBox In checkBoxes
If checkBox.Checked Then
selectedSheets.Add(checkBox.Text)
End If
Next
form.Close()
End Sub

' Show the form
form.ShowDialog()

' Check if any sheets were selected
If selectedSheets.Count = 0 Then
MessageBox.Show("No sheets selected for export.", "Export Canceled")
Exit Sub
End If

' Ask user for save location
Dim oFileDialog As New SaveFileDialog()
oFileDialog.Filter = "DXF Files (*.dxf)|*.dxf"
oFileDialog.Title = "Select DXF Save Location"

If oFileDialog.ShowDialog() = DialogResult.OK Then
Dim savePath As String = System.IO.Path.GetDirectoryName(oFileDialog.FileName)

' Export each selected sheet
For Each sheetName In selectedSheets
Try
Dim oSheet As Sheet = oSheets.Item(sheetName)
Dim safeSheetName As String = System.Text.RegularExpressions.Regex.Replace(oSheet.Name, "[^\w\.-]", "_")
Dim fullFileName As String = System.IO.Path.Combine(savePath, safeSheetName & ".dxf")

' Export the sheet
oSheet.SaveAs(fullFileName, SaveCopyAsOptionsEnum.kDXFFormat)
MessageBox.Show("DXF Exported: " & fullFileName, "Export Complete")
Catch ex As Exception
MessageBox.Show("Error exporting DXF for sheet " & sheetName & ": " & ex.Message, "Export Failed")
End Try
Next
Else
MessageBox.Show("DXF export canceled.", "Export Canceled")
End If

 

 

 

I had a better working version but I went through probably 25 different versions trying to get ChatGPT to fix all the mistakes, so this is the best one I could find. It still has an error code for that "savecopyasoptionsenum" but I don't understand much of this coding jargon. So, I'm lost haha.

0 Likes
Message 4 of 7

GosponZ
Collaborator
Collaborator

This would be great rule if is possible to fix. I uncomment line 80 and run rule. No error but file is not saved. Experts can you dig into little bit. Thanks

 

Message 5 of 7

GosponZ
Collaborator
Collaborator

ANYBODY TO TRY?

Message 6 of 7

hollypapp65
Advocate
Advocate

Can't fix that ball of spaghetti code.

This is dxf export VB code:

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=SaveAsDXFTranslator_Sample 

 

The trick is to set option values.

Easiest way is do export manually.  Get the options correct and save the ini file.

Reuse that file in code.

 

Or get the correct options here:

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-25D24E28-7517-4903-8AEE-123F8C71A89E&v=In...

Message 7 of 7

EagleBee93
Advocate
Advocate

Most of what you just said is foreign language to me. I don't know anything about coding terms. 

 

Would you mind breaking down what you just said in laymans terms? Step by step instructions would be even better 🙂

 

I'm not a very advanced inventor user, I just do the basics for the most part.

 

Also, I checked and I don't have a DXF translator add in

0 Likes