- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You don't need 2018 for Event Triggers.
For running the code on save, just go to the iLogic section under the Manage tab and click on Event Triggers, then right-click on After Save Document, Select Rules, and then check the box next to the rule you want.
Depending on your needs, if you need the file in DXF format instead of DWG, all you have to do is change the DWG references in the lines
SyntaxEditor Code Snippet
sOut="FLAT PATTERN DWG?AcadVersion=2000" _
And
SyntaxEditor Code Snippet
sFname=ThisDoc.Path &"\"&invPartNumiProp.Value &".dwg"
to "DXF" and ."dxf" appropriately and it will work as well.
If you're interested in a process that will export all flat patterns in one process, here's the code that's used in an assembly file that has all sheet metal parts placed, it doesn't require the previous code to be placed in each sheet metal part, so this will work with any sheet metal part placed as long as there is a flat pattern that can be generated without errors. This also works with iParts for those who use them.
It's a great time saver that did about 80 parts, normal and iParts combined, in a few minutes instead of a few hours when done manually.
SyntaxEditor Code Snippet
Dim oDoc As Document oDoc=ThisDoc.Document Dim docFile As Document For Each docFile In oDoc.AllReferencedDocuments ThisApplication.Documents.Open(docFile.FullFileName,True) Dim partDoc As PartDocument partDoc=ThisApplication.ActiveDocument If partDoc.SubType="{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Dim oCompDef As SheetMetalComponentDefinition oCompDef=partDoc.ComponentDefinition Dim oDataIO As DataIO oDataIO=oDoc.ComponentDefinition.DataIO If oCompDef.HasFlatPattern=False Then oCompDef.Unfold Else oCompDef.FlatPattern.Edit End If Dim sOut As String sOut="FLAT PATTERN DWG?AcadVersion=2000" _ +"&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL" _ +"&SimplifySplines=True" _ +"&LINEAR TOLERANCE=0.010" _ +"&MergeProfilesIntoPolyline=True" _ +"&RebaseGeometry=False" _ +"&TrimCenterlines=True" Dim invPropSets As PropertySets invPropSets=partDoc.PropertySets Dim invPropSet As PropertySet invPropSet=invPropSets.Item("Design Tracking Properties") Dim invPartNumiProp As Inventor.Property invPartNumiProp=invPropSet.Item("Part Number") Dim sFname As String sFname=ThisDoc.Path &"\"&invPartNumiProp.Value &".dwg" oCompDef.DataIO.WriteDataToFile(sOut,sFname) oCompDef.FlatPattern.ExitEdit If partDoc.ComponentDefinition.IsiPartFactory Or partDoc.ComponentDefinition.IsiPartMember Then partDoc.Save() End If Else End If partDoc.Close Next