Export all "FLAT PATTERN" drawing sheets to DXF, with _REV(revision)

Export all "FLAT PATTERN" drawing sheets to DXF, with _REV(revision)

NOEL_GETTINGBYCZTUC
Advocate Advocate
568 Views
4 Replies
Message 1 of 5

Export all "FLAT PATTERN" drawing sheets to DXF, with _REV(revision)

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Hi again,

 

I'm sorry but I'm not much of a coder and at this point don't have the knowledge to do much more in iLogic than relatively simple commands.

 

What I've been trying to do is automate the export of DXF files from the sheet named "FLAT PATTERN" from all the part drawings related to an assembly. I'd also like the file name of the DXF to be in the format "part_number"_REV"revision".DXF

 

The object types that I've wanting to export are "Visible View Edge" and "3D Sketch Geometry" objects, these are defaulting to Layer 0. I often use 3D Sketch Geometry in Dotted line type to indicate NC marking lines on the DXFs. Since layer 0 is set to continuous, I am overriding some of the line types of the 3D Sketch Geometry objects to ensure that I get a WYSIWYG output. I have a custom export configuration created called "ExportDXF2019.ini" which is currently giving me the expected line outputs when I manually export the "FLAT PATTERN" sheet.

 

On a related matter, I also want the export PDFs of the printable sheets of each drawing, again with the _REV"revision" suffix. I don't want this to be combined with the DXF export since I won't always want to do both together. This I think should be a little easier and I can likely find a script on the forum that will do it.

 

I've tried using Drawing Porter but there's not enough export options and the output is too messy (extra output files will need deleting, all output files will need renaming, etc). If it were possible to write sheet selection rules and file naming rules into the export configuration for Drawing Porter to then use that'd be great but I don't think such options exist. Likewise with Task Scheduler, the options that I'd like do not exist; there seems to be even less control over the process than with Drawing Porter.

 

 

Any help the iLogic pros can provide would be greatly appreciated.

0 Likes
Accepted solutions (1)
569 Views
4 Replies
Replies (4)
Message 2 of 5

NOEL_GETTINGBYCZTUC
Advocate
Advocate

Importantly, I do not want to have to open the drawings manually before running the rule, I need it to to be run from a top level assembly (with multiple subassembly levels).

 

Or, if that is too difficult, or if a script that works for an individual drawing is much easier, then I could use the iLogic Rule Batch Tool to run and delete it from all drawings in a project folder.

0 Likes
Message 3 of 5

NOEL_GETTINGBYCZTUC
Advocate
Advocate
Accepted solution

Since nobody was responding, this is what I came up with after an hour or so on ChatGPT.
There were originally a couple of message boxes for failure and confirmation included but they were pausing the progress when using the iLogic Rule Batch Tool so I got rid of them.

 

ChatGPT is probably not the best way to create these scripts, it gets stuck in a loop sometimes applying fixes to errors but I got there in the end.

 

Imports System.IO

' iLogic script to export the FLAT PATTERN sheet as DXF
' The exported DXF filename includes the drawing file name and its REVISION NUMBER iProperty Sub Main Dim doc As DrawingDocument = ThisDoc.Document Dim flatPatternSheet As Sheet = Nothing ' Find the "FLAT PATTERN" sheet For Each sheet As Sheet In doc.Sheets If sheet.Name = "FLAT PATTERN" Then flatPatternSheet = sheet Exit For End If Next If flatPatternSheet Is Nothing Then Exit Sub End If ' Activate the "FLAT PATTERN" sheet flatPatternSheet.Activate() Dim parentPartRevision As String = doc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value ' Get the drawing file name without extension Dim drawingFileName As String = System.IO.Path.GetFileNameWithoutExtension(doc.FullFileName) ' Specify the export directory Dim exportDirectory As String = "V:\Market\Team 8\DXFs Temp\" ' Change this to your desired directory ' Construct the export filename with DXF extension Dim exportFilename As String = System.IO.Path.Combine(exportDirectory, drawingFileName & "_Rev" & parentPartRevision & ".dxf") ' Save a copy of the FLAT PATTERN sheet as DXF doc.SaveAs(exportFilename, True) End Sub

 

0 Likes
Message 4 of 5

nilesh_natheCGQ9D
Community Visitor
Community Visitor

nilesh_natheCGQ9D_0-1739854376049.png

When I run this rule it shows me above error? Any idea on this.

0 Likes
Message 5 of 5

mateusz_baczewski
Advocate
Advocate

Hi,

This happens because you are trying to run this rule in a part, but from what I see, the rule should be run in a drawing. It should look like this:

' iLogic script to export the FLAT PATTERN sheet as DXF
' The exported DXF filename includes the drawing file name and its REVISION NUMBER iProperty


Sub Main
    Dim oDoc As Document = ThisDoc.Document
	Dim doc As DrawingDocument
	If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject
		doc = oDoc
	Else
	 	MsgBox("Run rule in drawing document.", MsgBoxStyle.OkOnly, "Warning!")
		Exit Sub
	End If
	
    Dim flatPatternSheet As Sheet = Nothing
    
    ' Find the "FLAT PATTERN" sheet
    For Each sheet As Sheet In doc.Sheets
        If Sheet.Name = "FLAT PATTERN" Then
            flatPatternSheet = Sheet
            Exit For
        End If
    Next
    
    If flatPatternSheet Is Nothing Then
        Exit Sub
    End If
    
    ' Activate the "FLAT PATTERN" sheet
    flatPatternSheet.Activate()
    
    Dim parentPartRevision As String = doc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
    
    ' Get the drawing file name without extension
    Dim drawingFileName As String = System.IO.Path.GetFileNameWithoutExtension(doc.FullFileName)
    
    ' Specify the export directory
    Dim exportDirectory As String = "V:\Market\Team 8\DXFs Temp\" ' Change this to your desired directory
    
    ' Construct the export filename with DXF extension
    Dim exportFilename As String = System.IO.Path.Combine(exportDirectory, drawingFileName & "_Rev" & parentPartRevision & ".dxf")
    
    ' Save a copy of the FLAT PATTERN sheet as DXF
    doc.SaveAs(exportFilename, True)
    
  End Sub

 

If you found it helpful, a "Like" would be much appreciated!
If this post solved your problem, please mark it as "Solution.".

0 Likes