Flat Pattern DXF Export Options

Flat Pattern DXF Export Options

clintwilkinson
Contributor Contributor
6,809 Views
12 Replies
Message 1 of 13

Flat Pattern DXF Export Options

clintwilkinson
Contributor
Contributor

Hi all

I have over time compiled & tweaked the following code.

This code Exports Flat Pattern to DXF, gives  the DXF file a name & stores it in a specific generated directory where the IPT file lives. The code is also part of a bigger picture & is linked to another piece of code that allows me to generate flat patterns for multiple IPT files I have open.

My problem is configuring the code to work to the Export options below.

clintwilkinson_0-1630130476708.png

This seems to tidy up any EMBOSSED text that in some cases in the course of our operation needs to be Laser Etched.

The code gives me this.

clintwilkinson_1-1630130798182.png

When I need this as created in the normal Inventor export function using a configured *.ini file

clintwilkinson_3-1630131632889.png

You will notice that the Letter "C" is not made up of long facets & is a lot tidier.

The code seems to work a treat and is easily tweaked from time to time when another idea is found for its use.

But I can't seem to replicate the DXF Export Options at the "sOut" section of within the code.

Any help or advice would be appreciated. Here is the code.

'Code to Export Fat Pattern to DXF by Clint Wilkinson
'Set your filepath here:
SETFilePath = ThisDoc.Path
SETFileName = iProperties.Value("Custom", "ProfileFileName")

'get DXF target folder path
SETFileFolder = SETFilePath & "\" & "Dxf"

'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(SETFileFolder) Then
    System.IO.Directory.CreateDirectory(SETFileFolder)
End If

Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MessageBox.Show ("Please open a part document", "iLogic")
End If

'Check for flat pattern >> create one if needed
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oDoc.ComponentDefinition
If oCompDef.HasFlatPattern = False Then
oCompDef.Unfold

Else
oCompDef.FlatPattern.Edit
End If

'DXF Settings
Dim sOut As String
Dim sPATH As String
sOut = "FLAT PATTERN DXF?AcadVersion=2007" _
	+ "&OuterProfileLayer=0&InteriorProfilesLayer=0" _
	+ "&FeatureProfilesDownLayerColor=0;128;255" _
	+ "&FeatureProfilesUpLayerColor=255;0;0" _
	+ "&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_BEND;IV_BEND_DOWN" _
	+ "SimplifySplines=True" _
	+ "&SplineTolerance=0.01" _
	+ "&MergeProfilesIntoPolyline=True" _
	+ "&BendLayerColor=255;255;0"

Dim sFname As String
sFname = SETFileFolder & "\" & SETFileName & ".dxf"

If System.IO.File.Exists(sFname) Then
		resp = MsgBox("Overwrite?" & vbLf & "Yes = Overwrite old file" & vbLf & "No = Create New Appended File", vbYesNo, "Dxf Rule")
        If resp = vbYes
            System.IO.File.Delete( sFname )
            MessageBox.Show("Earlier Dxf deleted! ", "Inventor")
        Else 
            sFname = SETFileFolder & "\" & SETFileName + " [New]" & ".dxf"
'            PrintSheet(sheetPath As String, sheetName As String) 
'            'Exit here to prevent it from being saved again
'            Exit Function
        End If
	End If

'Export the DXF and fold the model back up
oCompDef.DataIO.WriteDataToFile( sOut, sFname)
Dim oSMDef As SheetMetalComponentDefinition
oSMDef = oDoc.ComponentDefinition
oSMDef.FlatPattern.ExitEdit

'ThisApplication.StatusBarText = "Clint Wilkinson:  DXF saved to: " & sFname
MessageBox.Show("DXF saved to: " & sFname, "Bazinga!!!! Success!")

 

0 Likes
Accepted solutions (1)
6,810 Views
12 Replies
Replies (12)
Message 2 of 13

bradeneuropeArthur
Mentor
Mentor
sOut = "FLAT PATTERN DXF?AcadVersion=2007" _
	 "&OuterProfileLayer=0&InteriorProfilesLayer=0" _
	 "&FeatureProfilesDownLayerColor=0;128;255" _
	 "&FeatureProfilesUpLayerColor=255;0;0" _
	 "&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_BEND;IV_BEND_DOWN" _
	 "SimplifySplines=True" _
	 "&SplineTolerance=0.01" _
	 "&MergeProfilesIntoPolyline=True" _
	 "&BendLayerColor=255;255;0"

Try this. 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 13

clintwilkinson
Contributor
Contributor
Accepted solution

BradeneuropeArthur

Thanks for your help.

But unfortunately I couldn't get your suggestion to work.

However; Just by simply adding an extra decimal place was all it took.

I was under the impression that the code would use the Units specified in the part Document Settings.

In my case (mm). But it seems (cm) is what the "&SplineTolerence" was working to.

sOut = "FLAT PATTERN DXF?AcadVersion=2007" _
	+ "&OuterProfileLayer=0&InteriorProfilesLayer=0" _
	+ "&FeatureProfilesDownLayerColor=0;128;255" _
	+ "&FeatureProfilesUpLayerColor=255;0;0" _
	+ "&InvisibleLayers=IV_TANGENT;IV_ARC_CENTERS;IV_BEND;IV_BEND_DOWN" _
	+ "SimplifySplines=True" _
	+ "&SplineTolerance=0.001" _
	+ "&MergeProfilesIntoPolyline=True" _
	+ "&BendLayerColor=255;255;0"

 Thanks again

Message 4 of 13

w_landkoer
Participant
Participant

Hello Clint,

 

Thank you for your code. 

Could you also share the other code where you can make more dxf at once from multiple Parts?

 

Kind regards.

 

Wesley

0 Likes
Message 5 of 13

w_landkoer
Participant
Participant

Hello Clint,

 

Thank you for your code. 

Could you also share the other code where you can make more dxf at once from multiple Parts?

 

Kind regards.

 

Wesley

0 Likes
Message 6 of 13

WCrihfield
Mentor
Mentor

Hi @w_landkoer.  I am not sure if he is still active on the forums, but if you can explain in as much detail as possible how you would like an iLogic rule to work, some of the others here in this forum may be able to help you with it.  Exporting sheet metal flat patterns to DXF files has been a very popular and active topic here in this forum, so you may be able to use the search functionality of this forum to find several other example codes that you can review.  Some codes may get started from an assembly, then it iterates down through all documents being referenced within the assembly, and if they are sheet metal, it will attempt to export their flat patterns to DXF.  There are a great many variations in these types of codes though, because it seems like everyone wants slightly different settings / options set, wants the files named differently, wants the files put in different places, and so on.  Some code variations may just look at all documents that are currently open, then iterate though those, and process them.  It all depends on what suits your needs/wants the best.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 13

clintwilkinson
Contributor
Contributor

Hi @w_landkoer. & @WCrihfield 

That is correct. I have not been active on the forum for a while.

I use a separate  iLogic routine to export Multiple DXF files on multiple parts.

The 'caveat' is that only the *.ipt files that will be required for export can be open in Inventor & these are to be "Sheet Metal" files only. [The code you have already will Fall Over & give an error message if any file is not a Sheet Metal component].

All this iLogic routine does is run the code you already have downloaded on each open *.ipt file.

Also since I put this code together I have changed to name of the code a few times & can't remember the name of the code you downloaded. So you will notice at the end of the new code below you will notice the syntax iLogicAuto.RunExternalRule(oDoc, "FlatPatternDxf"). The area saying "FlatPatternDxf" must be named exactly the name you saved the previously downloaded code. [I named my code "FlatPatternDxf.iLogicVb"]

Here it is:

'Run External iLogic rule on all opened documents to EXPORT ALL DXF FLATPATTERNS
Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns = ThisApplication.ApplicationAddIns
Dim iLogicAuto
For Each addIn In addIns
If InStr(addIn.DisplayName, "iLogic") > 0 Then
iLogicAuto = addIn.Automation
Exit For
End If
Next

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
oDoc.Activate()
iLogicAuto.RunExternalRule(oDoc, "FlatPatternDxf")
Next

Message 8 of 13

clintwilkinson
Contributor
Contributor

Hi @w_landkoer. & @WCrihfield 

That is correct. I have not been active on the forum for a while.

I use a separate  iLogic routine to export Multiple DXF files on multiple parts.

The 'caveat' is that only the *.ipt files that will be required for export can be open in Inventor & these are to be "Sheet Metal" files only. [The code you have already will Fall Over & give an error message if any file is not a Sheet Metal component].

All this iLogic routine does is run the code you already have downloaded on each open *.ipt file.

Also since I put this code together I have changed to name of the code a few times & can't remember the name of the code you downloaded. So you will notice at the end of the new code below you will notice the syntax iLogicAuto.RunExternalRule(oDoc, "FlatPatternDxf"). The area saying "FlatPatternDxf" must be named exactly the name you saved the previously downloaded code. [I named my code "FlatPatternDxf.iLogicVb"]

Here it is:

'Run External iLogic rule on all opened documents to EXPORT ALL DXF FLATPATTERNS
Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns = ThisApplication.ApplicationAddIns
Dim iLogicAuto
For Each addIn In addIns
If InStr(addIn.DisplayName, "iLogic") > 0 Then
iLogicAuto = addIn.Automation
Exit For
End If
Next

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
oDoc.Activate()
iLogicAuto.RunExternalRule(oDoc, "FlatPatternDxf")
Next

Message 9 of 13

WCrihfield
Mentor
Mentor

Hi @w_landkoer & @clintwilkinson.

After I saw your code example for running your external rule on all open sheet metal parts, and hearing the caveats about it, I decided to create a simpler, and more error proof version of it for you.

Dim oADoc As Document = ThisApplication.ActiveDocument
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If (Not TypeOf oDoc Is PartDocument) Then Continue For 'skip to next document
	Dim oPDoc As PartDocument = oDoc
	If (Not TypeOf oPDoc.ComponentDefinition Is SheetMetalComponentDefinition) Then Continue For
	oDoc.Activate
	oAuto.RunExternalRule(oDoc, "FlatPatternDxf")
Next
oADoc.Activate

 I also created an alternate version of your 'FlatPatternDxf' external rule that may work slightly better for you (see attached text file).

 

One of the main differences of this external rule below to your original code posted in this topic, is switching out the use of 'ThisApplication.ActiveDocument' code phrase for the 'ThisDoc.Document' code phrase.  By making that one simple change, you would no longer need to 'activate' each document before running your external rule on it.  Another difference is additional, informational feedback when something goes wrong.  Another difference is how the export process works.  You do not need to be in 'edit mode' of the FlatPattern to do the export.  You can just do the export directly from the FlatPattern object itself instead.  The export options are copied from your accepted solution post above, so if those have changed locally, you can swap that String out, as needed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 13

w_landkoer
Participant
Participant

Works perfect for me. Thanks, you guys, @clintwilkinson and @WCrihfield 

 

My next step is to make a template with some views of the Folded Product in an Inventor dwg, already with the most important Dimensions in there. So I have made one basis sheet and from there I want every (slightly different) other part to be placed in the same way in a new sheet. Any ideas?

0 Likes
Message 11 of 13

WCrihfield
Mentor
Mentor

Hi @w_landkoer.  Drawing automation is not an area I fucus on that much, because it requires a lot of strict design similarity, consistency, conformity, preparations, patience, and extremely detailed familiarity with the objects being annotated.  I simply deal with too much variety, and work with a whole team of other engineers.

 

Creating a new drawing from a template is simple.  Placing a view requires being familiar with the templates being used, their sheet sizes, their orientations, how the borders, title blocks, rev tables, parts Lists, any standard notes / symbols, and more are all positioned & oriented on the sheets.  Then being able to determine available space for views within the border area of the sheet, while avoiding the title block (and other obstructions) within that area.  Being able to compare model sizes (in X, Y, & Z), with that available space in the sheet, for not only scaling the view(s), but also determining the proper orientations of the views before (or after) placing them.  Then once you have a view (or multiple) placed, knowing how to specify exactly which pieces of the 2D geometry within each view to attach each point of each dimension or other type of annotation to.  Then knowing about all your company's drawing standards, and things that make your drawings unique from all other company's drawings.  Then all the 'styles' that are/can be involved (every type of annotation has one or multiple Styles).  Controlling that level of detail by code, accurately, and without errors, is not usually something that 'someone else' can write the code for.  It generally requires a long process of learning how to do every little step along the way by code yourself, so that you can write the code yourself as you learn.  Because you are likely the only one who knows all the little details about the product/design that need to be known for the process.  One of the common tasks involved in drawing automation is assigning meaningful names to all the faces, edges, and vertex objects in the part environment, that you will want to attach a dimension or annotation to in the drawing.  Then knowing how to specify those specific geometry entities within the drawing view for attaching dimensions/annotations to.  No one else would know what names to assign to what things in all your model files.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 13

clintwilkinson
Contributor
Contributor

Hi @WCrihfield & @w_landkoer

One of the companies I worked for in the past had this exact idea & ended up abandoning it for the reasons outlined by @WCrihfield. We found it more efficient & less stressful just by using the "Copy/Design" feature in Autodesk Vault.

Once the initial part & drawing file were created it was a very simple process & procedure using "Copy/Design" & then just adjusting the required dimensions on the part & letting the drawing update. Obviously there was the odd Metadata (ie. iProperties) that needed to be sorted out but it was a quick & easy process that everyone at different skill levels could deal with confidently.

If "Vault is not an option for you & you are "Stand Alone" then the same thing con be achieved through "Design Assistant". I know it is "Old School" but it does the same thing only locally.

I hope this helps.

0 Likes
Message 13 of 13

clintwilkinson
Contributor
Contributor

Hi @WCrihfield

Thankyou for that. It has always bugged me having to take the "Caveats" into consideration. The bits of code I have done are entirely to make light work of that laborious logistical part of the project reserved at the end after everything has been approved for manufacture.

Many Thanks.

Clint Wilkinson

0 Likes