Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument 'If document is not assembly, alert user and exit rule If oDoc.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule must be run from an Assembly.", "iLogic") Exit Sub End If 'get user input RUsure = MessageBox.Show ( _ "This will create a DXF file for all sheet metal components." _ & vbLf & " " _ & vbLf & "Are you sure you want to create a DXF for all of the sheet metal components in this assembly?" _ & vbLf & "This could take a while.", "iLogic - SaveAllDXF ",MessageBoxButtons.YesNo) If RUsure = vbNo Then Return Else End If '- - - - - - - - - - - - -Establish DXF Save Path - - - - - - - - - - - - Dim oTName As String = InputBox("Where do you want to save to?", "File Path:", "H:\CNC\DXF Files for Punch and Laser\DXF_Delete") oPath = oTName & "\" 'Must include final backslash If Not System.IO.Directory.Exists(oPath) Then System.IO.Directory.CreateDirectory(oPath) End If '- - - - - - - - - - - - -Components - - - - - - - - - - - - Dim oRefDocs As DocumentsEnumerator Dim oRefDoc As Document oRefDocs = oDoc.AllReferencedDocuments 'Iterate through referenced docs For Each oRefDoc In oRefDocs Dim oCurFile As Document 'current file Try oCurFile = ThisApplication.Documents.Open(oRefDoc.FullFileName, False) 'False == open invisible, True == open visible. invisible is much faster. Catch GoTo NextIteration End Try If oCurFile.DocumentSubType.DocumentSubTypeID <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then 'document is not sheet metal. oCurFile.Close(True) 'True == skip save Else oCurFileName = oCurFile.FullFileName 'get the postion of the last backslash in the path FNamePos = InStrRev(oCurFileName, "\", -1) 'get the file name with the file extension FName = Right(oCurFileName, Len(oCurFileName) - FNamePos) 'get the file name (without extension) FName = Left(FName, Len(FName) - 4) 'set dxf filename DxfName = oPath & FName & ".dxf" '- - - - - - - - - - - - - Checks if Good side exists - - - - - - - - - - - - ' Dim namedEntities = ThisDoc.NamedEntities Dim namedEntities = iLogicVb.Automation.GetNamedEntities(ThisDoc.Document) Dim oGoodSide As Object = NamedEntities.TryGetEntity("Good Side") '- - - - - - - - - - - - - Checks if flat pattern exists - - - - - - - - - - - - Dim oSMCD As SheetMetalComponentDefinition = oCurFile.ComponentDefinition If Not oSMCD.HasFlatPattern Then 'If it doesn't have a flat pattern, create one (unfold the model) If oGoodSide = Nothing Then oSMCD.Unfold() oSMCD.FlatPattern.ExitEdit() ElseIf oGoodSide = "Good Side" Then oSMCD.Unfold2("Good Side") oSMCD.FlatPattern.ExitEdit() End If End If 'set dxf options Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2004" _ + "&OuterProfileLayer=IV_INTERIOR_PROFILES" _ + "&InvisibleLayers=IV_TANGENT;IV_FEATURE_PROFILES_DOWN;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL" _ + "&SimplifySplines=True" _ + "&BendLayerColor=255;255;0" Try oSMCD.DataIO.WriteDataToFile(sOut, DxfName) 'save the dxf Catch End Try oCurFile.Close(True) End If NextIteration: Next '- - - - - - - Display Results - - - - - - - - - - - - - MessageBox.Show("New Files Created in: " & vbLf & oPath & vbLf & vbLf & "Please verify that all DXFs are correct.", "iLogic") 'open the folder where the new files are saved Shell("explorer.exe " & oPath,vbNormalFocus)