Make macro sort sheet metal DXF by thickness and material

Make macro sort sheet metal DXF by thickness and material

Anonymous
Not applicable
761 Views
2 Replies
Message 1 of 3

Make macro sort sheet metal DXF by thickness and material

Anonymous
Not applicable

On a different post someone was looking for help making a macro that exported dxf's sort the files by material and thickness. They said they got it working and posted some revisions but I can;t seem to make it work.  If anyone could help with this that would be great.

 

https://forums.autodesk.com/t5/inventor-customization/adding-sheetmetal-rule-to-foldername/td-p/7751...

 

The original code:

'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")

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
'Get user Input
RUsure = MessageBox.Show ( _
"This will create a DXF file for all of the assembly components that are sheet metal." _
& vbLf & "This rule expects that the part file is saved." _
& vbLf & "Only sheet metal parts with their BOM-structure set to normal will be exported" _
& vbLf & " " _
& vbLf & "Are you sure you want to create DXF for all of the assembly sheet metal components?" _
& vbLf & " " _
& vbLf & "This could take a while.", "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
'work the drawing files for the referenced models
'this expects 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 BOM-structure is set to normal
If oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For
iptPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "ipt"
'check 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

oPath = ThisDoc.Path
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

'get DXF target folder path
oFolder = oPath & "\" & oAsmName & "-Rev_" & oRevNum & "-PF" & "\" & oAsmName & "-Rev_" & oRevNum & "-DXF" 
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
oDataMedium.FileName = oFolder & "\" & oFileName & "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=2004&OuterProfileLayer=0&OuterProfileLayerColor=0;0;0&InteriorProfilesLayer=0&InteriorProfilesLayerColor=0;0;0&BendDownLayerColor=255;0;0&BendUpLayerColor=0;128;255&BendDownLayerLineType=37633&BendUpLayerLineType=37641;IV_BEND;IV_BEND_DOWN;IV_OUTER_PROFILE;IV_INTERIOR_PROFILES;IV_FEATURE_PROFILESLayer=engrave;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;IV_FEATURE_PROFILES_DOWN"
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)

 The revisions:

oStyle=oRefDoc.ComponentDefinition.ActiveSheetMetalStyle.Name
oFolder = oPath & "\" & oAsmName & "-Rev_" & oRevNum & "-PF" & "\" & oAsmName & "-Rev_" & oRevNum & "-DXF" & "\" & oStyle
 

 I have an Ilogic rule that exports DXF's as well so if your more comfortable with coding those and you could make it sort like the macro is supposed to that would also work.

 

0 Likes
762 Views
2 Replies
Replies (2)
Message 2 of 3

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please explain file name of DXF with example?

oFolder = oPath & "\" & oAsmName & "-Rev_" & oRevNum & "-PF" & "\" & oAsmName & "-Rev_" & oRevNum & "-DXF" & "\" & oStyle

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 3

Anonymous
Not applicable

I'm brand new to coding and found this on a different forum that I linked above.  I was having issues with the code poping up saying I needed a job# with either version of the code so I don't know what the file name would look like.  If you look at the original forum the creater of the code offered to help me adjust it for my needs.  If you want to also give it a shot the link is in the top post.

0 Likes