Hi @wylieDWRUN . I modified your iLogic code a bit and now it works very well. I hope this is exactly what you wanted.
Dim oDoc As AssemblyDocument = 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
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 IO.Directory.Exists(oPath) Then IO.Directory.CreateDirectory(oPath)
'- - - - - - - - - - - - -Components - - - - - - - - - - - -
'Iterate through referenced docs
For Each oRefDoc As Document In oDoc.AllReferencedDocuments
If oRefDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
'set dxf filename
DxfName = oPath & IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName) & ".dxf"
'- - - - - - - - - - - - - Checks if Good side exists - - - - - - - - - - - -
' Dim namedEntities = ThisDoc.NamedEntities
Dim namedEntities = iLogicVb.Automation.GetNamedEntities(oRefDoc)
Dim oGoodSide As Object = namedEntities.TryGetEntity("Good Side")
'- - - - - - - - - - - - - Checks if flat pattern exists - - - - - - - - - - - -
Dim oSMCD As SheetMetalComponentDefinition = oRefDoc.ComponentDefinition
If Not oSMCD.HasFlatPattern Then 'If it doesn't have a flat pattern, create one (unfold the model)
If oGoodSide Is Nothing Then
oSMCD.Unfold()
oSMCD.FlatPattern.ExitEdit()
Else
oSMCD.Unfold2(oGoodSide)
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
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)