Hi, I tried to use your code with the same intencion but I dont be able to make it work :c
I need the same, Export platpaterns DXF files with a custom Parameters in the name, but for some reason, te code just make the folder but nothing more, Im pretty new with ilogic so probably is something small in the code, but I need help for sure.
This is the code Im using (As an external rule):
'Sub Main()
'Check that the active document is an assembly file
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
Dim oADoc As AssemblyDocument
oADoc = ThisApplication.ActiveDocument
'Get user input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the asembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly components?" _
& vbLf & "This could take a while.", "iLogic - Batch Output DXFs ", MessageBoxButtons.YesNo)
If RUsure <> vbYes Then Exit Sub
'where to save all the DXF's to
Dim oFolder As String = "C:\Users\SROSS\Documents\Directorio Exportacion Temporal DXF Ilogic\TEST\"
'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
Dim oRefDoc As Document
Dim oPath, oName, oDxfName As String
For Each oRefDoc In oADoc.AllReferencedDocuments
If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
If oPDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal" Then
Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
oName = IO.Path.GetFileNameWithoutExtension(oPDoc.FullFileName)
'here is your 'Custom' iProperties set
Dim oCProps As Inventor.PropertySet = oPDoc.PropertySets.Item("Inventor User Defined Properties")
'assemble your DXF file name here
Dim oCProp1 As String = oCProps.Item("#ITEM").Value
Dim oCProp2 As String = oCProps.Item("Thickness").Value
Dim oCProp3 As String = oCProps.Item("#CANT").Value
oDxfName = oFolder & oName & oCProp1 & "_" & oCProp2 & "_" & oCProp3 & "units" & ".dxf"
Dim oFPattern As FlatPattern
If oSMDef.HasFlatPattern = False Then
Try
'create flat pattern
oSMDef.Unfold
oFPattern = oSMDef.FlatPattern
Catch
'don't exit rule, just skip to the next loop document
MsgBox("Failed to 'Unfold' " & oPDoc.FullFileName & vbCrLf & _
"Skipping it and continuing to the next document.", , "")
Continue For
End Try
Else 'if flat pattern exists
oFPattern = oSMDef.FlatPattern
End If
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"
oFPattern.DataIO.WriteDataToFile(sOut, oFolder & "\" & oDxfName)
End If
oPDoc.Close(True)
End If
Next