Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
pball
in reply to: Anonymous

This is definitely possible and not that difficult. Here is some code I put together from something similar I had. It will prompt for the two quantities and multipy them, if the flat pattern doesn't exist yet it will create it, and then it will save the dxf in the same folder as the part with "-(totalquantity) added to the file name. Let me know how it works for you.

 

 

Public Sub Export_DXF()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveEditDocument
    If (oDoc.FullDocumentName <> oDoc.FullDocumentName) Then
        MsgBox "Can't export while editing a part in an assembly"
        Exit Sub
    ElseIf (oDoc.ComponentDefinition.Type <> kSheetMetalComponentDefinitionObject) Then
        MsgBox "Not a sheet metal part Sorry."
        Exit Sub
    End If
    
    Dim BomQty As Integer
    BomQty = InputBox(Prompt:="Enter Bom Quantity", Title:="Bom Quantity")
    
    Dim AsmQty As Integer
    AsmQty = InputBox(Prompt:="Enter Assembly Quantity", Title:="Assembly Quantity")
    
    Dim TotQty As Integer
    TotQty = BomQty * AsmQty
    
    'If flat pattern doesn't exist, create it and return to folded view
    If (oDoc.ComponentDefinition.FlatPattern Is Nothing) Then
        Dim oDef As ControlDefinition
        oDoc.ComponentDefinition.Unfold
        Set oDef = ThisApplication.CommandManager.ControlDefinitions.Item("PartSwitchRepresentationCmd")
        oDef.Execute
    End If

    ' Get the DataIO object.
    Dim oDataIO As DataIO
    Set oDataIO = oDoc.ComponentDefinition.DataIO

    ' Build the string that defines the format of the DXF file.
    Dim sOut As String
    sOut = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=Outer&InvisibleLayers=IV_Tangent;IV_Bend;IV_Bend_Down;IV_Bend_Up;IV_Arc_Centers"

    ' Create the DXF file.
    oDataIO.WriteDataToFile sOut, full_path(oDoc.FullFileName) & filename_noext(oDoc.FullFileName) & "-" & TotQty & ".dxf"
End Sub

Function filename_noext(spth As String)
    'Returns filename without extension from full path
    If (spth <> "") And (InStr(spth, ".")) And (InStrRev(spth, "\") < InStrRev(spth, ".")) Then
        filename_noext = Mid(spth, InStrRev(spth, "\") + 1, InStrRev(spth, ".") - InStrRev(spth, "\") - 1)
    ElseIf (spth <> "") And Not (InStr(spth, ".")) Then
        filename_noext = Mid(spth, InStrRev(spth, "\", Len(spth)) + 1, Len(spth))
    Else:
        filename_noext = ""
    End If
End Function

Function full_path(spth As String)
    'Returns full path minus filename, trailing slash is included
    If spth <> "" Then
        full_path = Left(spth, Len(spth) - (Len(spth) - InStrRev(spth, "\")))
    Else:
        full_path = ""
    End If
End Function

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style