Hi guys! Help solve the issue. I have a ready - made solution . I need it to be recorded when exporting to a DXF file ( " Name - thickness - Material ) as in the picture (the material is preferably abbreviated) . And it would be better to sort by folders as in Figure 2. I met an approximate solution on the forum somewhere, but not quite correct. Can someone help solve this problem? Or it will give a link to a ready-made working solution.
my text
'define the active document as an assembly file Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4) oRevNum = iProperties.Value("Project", "Revision Number") 'make sure that the active document is an assembly file If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("Please run this rule from the build file.", "iLogic") Exit Sub End If 'Getting User input RUsure = MessageBox.Show ( _ "This will create a DXF file for all the components of the assembly made of sheet metal." _ & vbLf & "This rule assumes that the part file will be saved." _ & vbLf & "Only sheet metal parts for which the specification structure is set to the normal value will be exported" _ & vbLf & " " _ & vbLf & "Are you sure you want to create a DXF for all the components of a sheet metal assembly?" _ & vbLf & " " _ & vbLf & "This may take some time.", "iLogic - Batch Output DXFs ",MessageBoxButtons.YesNo) If RUsure = vbNo Then Return Else End If '- - - - - - - - - - - - -Component - - - - - - - - - - - - 'look at the files referenced by the assembly Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments Dim oRefDoc As Document 'process the drawing files for the referenced models 'at the same time, it is expected that the model has been saved For Each oRefDoc In oRefDocs 'check if the document is a sheet metal part If oRefDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For 'check if the normal structure of the specification is set If oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt" 'make sure that the model is saved If(System.IO.File.Exists(iptPathName)) Then Dim oDrawDoc As PartDocument oDrawDoc = ThisApplication.Documents.Open(iptPathName, True) oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName)- 3) On Error Resume Next oStyle=oRefDoc.ComponentDefinition.ActiveSheetMetalStyle.Name oPath = ThisDoc.Path oDataMedium = ThisApplication.TransientObjects.CreateDataMedium oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'get the path to the target folder DXF oFolder = oPath & "\" & oAsmName & "-DXP" & "\" & oStyle If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If Dim activepart As PartDocument = ThisApplication.ActiveDocument Dim Sheetmetal As SheetMetalComponentDefinition = activepart.ComponentDefinition Dim ThicknessSM As Parameter = Sheetmetal.Thickness Dim Thickness As String=ThicknessSM.Value *10 & "mm" oDataMedium.FileName = oFolder & "\" & oFileName & " " & "-" & Thickness & "-" & ".dxf" Dim oCompDef As SheetMetalComponentDefinition oCompDef = oDrawDoc.ComponentDefinition If oCompDef.HasFlatPattern = False Then oCompDef.Unfold Else oCompDef.FlatPattern.Edit End If Dim sOut As String 'sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PR?OFILE" 'sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerColor=255;0;0&BendUpLayerColor=255;0;0&BendDownLayerLineType=37641&BendUpLayerLineType=37639IV_BEND;IV_BEND_DOWN;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES" sOut = "FLAT PATTERN DXF?AcadVersion=2018&MergeOuterContour=True&MergeProfilesIntoPolyline=True&RebaseGeometry=True&Feature" _ + "&FeatureProfilesLayer=IV_FEATURE_PROFILES&FeatureProfilesLayerColor=0;255;255&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerColor=0;255;255" _ + "&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL" oCompDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName) oCompDef.FlatPattern.ExitEdit oDrawDoc.Close End If Next MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic") 'open the folder where the new ffiles are saved Shell("explorer.exe " & oFolder,vbNormalFocus)
Solved! Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Hi @negutorthik . Please try this code:
'define the active document as an assembly file
Dim oInvApp As Inventor.Application = ThisApplication
'make sure that the active document is an assembly file
If oInvApp.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the build file.", "iLogic")
Exit Sub
End If
Dim oAsmDoc As AssemblyDocument = oInvApp.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
oRevNum = iProperties.Value("Project", "Revision Number")
oPath = ThisDoc.Path
'Getting User input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all the components of the assembly made of sheet metal." _
& vbLf & "This rule assumes that the part file will be saved." _
& vbLf & "Only sheet metal parts for which the specification structure is set to the normal value will be exported" _
& vbLf & " " _
& vbLf & "Are you sure you want to create a DXF for all the components of a sheet metal assembly?" _
& vbLf & " " _
& vbLf & "This may take some time.", "iLogic - Batch Output DXFs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
'- - - - - - - - - - - - -Component - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
'process the drawing files for the referenced models
'at the same time, it is expected that the model has been saved
For Each oRefDoc As Document In oRefDocs
'check if the document is a sheet metal part
If oRefDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
'check if the normal structure of the specification is set
If oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For
'make sure that the model is saved
If Not System.IO.File.Exists(oRefDoc.FullFileName) Then Continue For
Dim oPDoc As PartDocument = oInvApp.Documents.Open(oRefDoc.FullFileName, True)
Dim oSheetDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
Dim ThicknessSM As Inventor.Parameter = oSheetDef.Thickness
Dim Thickness As String=ThicknessSM.Value *10 & "mm"
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName)- 3)
On Error Resume Next
oStyle = oSheetDef.ActiveSheetMetalStyle.Name
Dim oTO As TransientObjects = oInvApp.TransientObjects
oDataMedium = oTO.CreateDataMedium
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
'get the path to the target folder DXF
oFolder = oPath & "\" & oAsmName & "-DXP" & "\" & oStyle & "\" & oPDoc.ActiveMaterial.Name & " - " & Thickness
If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder)
oDataMedium.FileName = oFolder & "\" & oFileName & ".dxf"
' oDataMedium.FileName = oFolder & "\" & oFileName & " " & "-" & Thickness & "- " & activepart.ActiveMaterial.Name & ".dxf"
If oSheetDef.HasFlatPattern = False Then
oSheetDef.Unfold
Else
oSheetDef.FlatPattern.Edit
End If
Dim sOut As String
'sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PR?OFILE"
'sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerColor=255;0;0&BendUpLayerColor=255;0;0&BendDownLayerLineType=37641&BendUpLayerLineType=37639IV_BEND;IV_BEND_DOWN;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES"
sOut = "FLAT PATTERN DXF?AcadVersion=2018&MergeOuterContour=True&MergeProfilesIntoPolyline=True&RebaseGeometry=True&Feature" _
+ "&FeatureProfilesLayer=IV_FEATURE_PROFILES&FeatureProfilesLayerColor=0;255;255&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerColor=0;255;255" _
+ "&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
oSheetDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
oSheetDef.FlatPattern.ExitEdit
oPDoc.Close()
Next
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new ffiles are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
I made a mistake, fix in line 53: oPDoc.ActiveMaterial.Name to oPDoc.ActiveMaterial.DisplayName
Theoretically, the name of the material may contain characters that are not valid for creating a folder. It needs to be controlled.
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
What I need! Works well👍
It would be ideal to save to one folder as in Figure 1. Do not create a folder Figure 2
That is, you want the following structure: Folder (Thickness) \ File (Name and Material)?
'define the active document as an assembly file
Dim oInvApp As Inventor.Application = ThisApplication
'make sure that the active document is an assembly file
If oInvApp.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the build file.", "iLogic")
Exit Sub
End If
Dim oAsmDoc As AssemblyDocument = oInvApp.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
oRevNum = iProperties.Value("Project", "Revision Number")
oPath = ThisDoc.Path
'Getting User input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all the components of the assembly made of sheet metal." _
& vbLf & "This rule assumes that the part file will be saved." _
& vbLf & "Only sheet metal parts for which the specification structure is set to the normal value will be exported" _
& vbLf & " " _
& vbLf & "Are you sure you want to create a DXF for all the components of a sheet metal assembly?" _
& vbLf & " " _
& vbLf & "This may take some time.", "iLogic - Batch Output DXFs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
'- - - - - - - - - - - - -Component - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
'process the drawing files for the referenced models
'at the same time, it is expected that the model has been saved
For Each oRefDoc As Document In oRefDocs
'check if the document is a sheet metal part
If oRefDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
'check if the normal structure of the specification is set
If oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For
'make sure that the model is saved
If Not System.IO.File.Exists(oRefDoc.FullFileName) Then Continue For
Dim oPDoc As PartDocument = oInvApp.Documents.Open(oRefDoc.FullFileName, True)
Dim oSheetDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
Dim ThicknessSM As Inventor.Parameter = oSheetDef.Thickness
Dim Thickness As String=ThicknessSM.Value * 10
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName)- 3)
On Error Resume Next
oStyle = oSheetDef.ActiveSheetMetalStyle.Name
Dim oTO As TransientObjects = oInvApp.TransientObjects
oDataMedium = oTO.CreateDataMedium
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
'get the path to the target folder DXF
oFolder = oPath & "\" & oAsmName & "-DXP" & "\" & oStyle & "\" & Thickness
If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder)
oDataMedium.FileName = oFolder & "\" & oFileName & " - " & oPDoc.ActiveMaterial.DisplayName & ".dxf"
If oSheetDef.HasFlatPattern = False Then
oSheetDef.Unfold
Else
oSheetDef.FlatPattern.Edit
End If
Dim sOut As String
'sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PR?OFILE"
'sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerColor=255;0;0&BendUpLayerColor=255;0;0&BendDownLayerLineType=37641&BendUpLayerLineType=37639IV_BEND;IV_BEND_DOWN;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES"
sOut = "FLAT PATTERN DXF?AcadVersion=2018&MergeOuterContour=True&MergeProfilesIntoPolyline=True&RebaseGeometry=True&Feature" _
+ "&FeatureProfilesLayer=IV_FEATURE_PROFILES&FeatureProfilesLayerColor=0;255;255&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerColor=0;255;255" _
+ "&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
oSheetDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
oSheetDef.FlatPattern.ExitEdit
oPDoc.Close()
Next
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new ffiles are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)
If I'm wrong, describe how exactly you want to form folders?
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
No. Everything is as in the first version. Only without the folder, the thickness of the material is my fault. I specified the drawing incorrectly. This is necessary, as shown in Figure 2. Forgive me
I hope this is exactly what you need, because right now I'm just trying to guess what structure you need.
'define the active document as an assembly file
Dim oInvApp As Inventor.Application = ThisApplication
'make sure that the active document is an assembly file
If oInvApp.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the build file.", "iLogic")
Exit Sub
End If
Dim oAsmDoc As AssemblyDocument = oInvApp.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)
oRevNum = iProperties.Value("Project", "Revision Number")
oPath = ThisDoc.Path
'Getting User input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all the components of the assembly made of sheet metal." _
& vbLf & "This rule assumes that the part file will be saved." _
& vbLf & "Only sheet metal parts for which the specification structure is set to the normal value will be exported" _
& vbLf & " " _
& vbLf & "Are you sure you want to create a DXF for all the components of a sheet metal assembly?" _
& vbLf & " " _
& vbLf & "This may take some time.", "iLogic - Batch Output DXFs ",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
Return
Else
End If
'- - - - - - - - - - - - -Component - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
'process the drawing files for the referenced models
'at the same time, it is expected that the model has been saved
For Each oRefDoc As Document In oRefDocs
'check if the document is a sheet metal part
If oRefDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
'check if the normal structure of the specification is set
If oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For
'make sure that the model is saved
If Not System.IO.File.Exists(oRefDoc.FullFileName) Then Continue For
Dim oPDoc As PartDocument = oInvApp.Documents.Open(oRefDoc.FullFileName, True)
Dim oSheetDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
Dim ThicknessSM As Inventor.Parameter = oSheetDef.Thickness
Dim Thickness As String = ThicknessSM.Value * 10 & "mm"
oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName)- 3)
On Error Resume Next
oStyle = oSheetDef.ActiveSheetMetalStyle.Name
Dim oTO As TransientObjects = oInvApp.TransientObjects
oDataMedium = oTO.CreateDataMedium
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
'get the path to the target folder DXF
oFolder = oPath & "\" & oAsmName & "-DXP" & "\" & oStyle
If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder)
' oDataMedium.FileName = oFolder & "\" & oFileName & " - " & oPDoc.ActiveMaterial.DisplayName & ".dxf"
oDataMedium.FileName = oFolder & "\" & oFileName & " " & " - " & oPDoc.ActiveMaterial.DisplayName & " - " & Thickness & ".dxf"
If oSheetDef.HasFlatPattern = False Then
oSheetDef.Unfold
Else
oSheetDef.FlatPattern.Edit
End If
Dim sOut As String
'sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PR?OFILE"
'sOut = "FLAT PATTERN DXF?AcadVersion=2004&RebaseGeometry=True&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerColor=255;0;0&BendUpLayerColor=255;0;0&BendDownLayerLineType=37641&BendUpLayerLineType=37639IV_BEND;IV_BEND_DOWN;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILES;IV_FEATURE_PROFILES_DOWN;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_ROLL_TANGENT;IV_ROLL&InvisibleLayers=IV_TANGENT;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_UNCONSUMED_SKETCHES"
sOut = "FLAT PATTERN DXF?AcadVersion=2018&MergeOuterContour=True&MergeProfilesIntoPolyline=True&RebaseGeometry=True&Feature" _
+ "&FeatureProfilesLayer=IV_FEATURE_PROFILES&FeatureProfilesLayerColor=0;255;255&FeatureProfilesDownLayer=IV_FEATURE_PROFILES_DOWN&FeatureProfilesDownLayerColor=0;255;255" _
+ "&InvisibleLayers=IV_TANGENT;IV_BEND;IV_BEND_DOWN;IV_TOOL_CENTER;IV_TOOL_CENTER_DOWN;IV_ARC_CENTERS;IV_ALTREP_FRONT;IV_ALTREP_BACK;IV_UNCONSUMED_SKETCHES;IV_ROLL_TANGENT;IV_ROLL"
oSheetDef.DataIO.WriteDataToFile( sOut, oDataMedium.FileName)
oSheetDef.FlatPattern.ExitEdit
oPDoc.Close()
Next
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new ffiles are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Thank you for your time. Thank you for the resolved issue. The first option is the most correct. I will use it. Thank you very much again
Can't find what you're looking for? Ask the community or share your knowledge.