Naming a save file from iproperties

Naming a save file from iproperties

Anonymous
Not applicable
589 Views
3 Replies
Message 1 of 4

Naming a save file from iproperties

Anonymous
Not applicable
'Define the active document as an assembly file
Dim oDoc As Document = ThisApplication.ActiveDocument

'Check that the active document is an assembly file
If oDoc.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 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

Dim oAsmName As String = Left(oDoc.DisplayName, Len(oDoc.DisplayName) - 4)
Dim oPath As String = ThisDoc.Path

'Get the DXF target folder path
Dim oFolder As String = oPath & "\" & oAsmName & " DXF Files"

'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

'- - - - - - - - - - - - -Component  - - - - - - - - - - - -

Dim oBOM As BOM = oDoc.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
'You'll have to play with this to get the BOM you want. Try 1, 2, 3 or "Structured"
Dim oBOMView As BOMView = oBOM.BOMViews.Item(2)
For Each oRow As BOMRow In oBOMView.BOMRows
    Dim oCD As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
    Dim iDoc As Document = oCD.Document
    'SheetMetal parts only
    If iDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
    Dim iName As String = iDoc.FullFileName

    'check that model is saved
    If iName = vbNullString Then Continue For
    iDoc = ThisApplication.Documents.Open(iName)
    oCD = iDoc.ComponentDefinition
    
    Dim oItem As String = oRow.ItemNumber  'here I would like to change the rule
    Try
        If Not oCD.HasFlatPattern Then
            oCD.Unfold()
        Else
            oCD.FlatPattern.Edit()
        End If
        Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PROFILE"
        'Dim oDXFName As String = oPath & "\" & oAsmName & i & "_FlatPatterns.dxf"
        oCD.DataIO.WriteDataToFile(sOut, oFolder & "\" & oAsmName & "-" & oItem & ".dxf")
        oCD.FlatPattern.ExitEdit()
        MsgBox(oFolder & "\" & oAsmName & "-" & oItem & ".dxf")
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    iDoc.Close(True)
Next

 Hi,

 

I found program, which export Flatpattern to DXF from assembly : https://forums.autodesk.com/t5/inventor-customization/export-flatpattern-to-dxf-from-assembly-filena...

 

I can't  change the name of the saved file. I'd like it had a name like Item Number from iproperties.

 

 

0 Likes
Accepted solutions (1)
590 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor

in each part you have an I-property that you need in your file.

How is the I-property called exact?

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 4

bradeneuropeArthur
Mentor
Mentor

Otherwise use this:

'Define the active document as an assembly file
Dim oDoc As Document = ThisApplication.ActiveDocument

'Check that the active document is an assembly file
If oDoc.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 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

Dim oAsmName As String = Left(oDoc.DisplayName, Len(oDoc.DisplayName) - 4)
Dim oPath As String = ThisDoc.Path

'Get the DXF target folder path
Dim oFolder As String = oPath & "\" & oAsmName & " DXF Files"

'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

'- - - - - - - - - - - - -Component  - - - - - - - - - - - -

Dim oBOM As BOM = oDoc.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
'You'll have to play with this to get the BOM you want. Try 1, 2, 3 or "Structured"
Dim oBOMView As BOMView = oBOM.BOMViews.Item(2)
For Each oRow As BOMRow In oBOMView.BOMRows
    Dim oCD As ComponentDefinition = oRow.ComponentDefinitions.Item(1)
    Dim iDoc As Document = oCD.Document
    'SheetMetal parts only
    If iDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
    Dim iName As String = iDoc.FullFileName

    'check that model is saved
    If iName = vbNullString Then Continue For
    iDoc = ThisApplication.Documents.Open(iName)
    oCD = iDoc.ComponentDefinition
    
    Dim oItem As String = iDoc.PropertySets.Item(4).Item("Item Number").Value'oRow.ItemNumber  'here I would like to change the rule
    Try
        If Not oCD.HasFlatPattern Then
            oCD.Unfold()
        Else
            oCD.FlatPattern.Edit()
        End If
        Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2004&OuterProfileLayer=IV_OUTER_PROFILE"
        'Dim oDXFName As String = oPath & "\" & oAsmName & i & "_FlatPatterns.dxf"
        oCD.DataIO.WriteDataToFile(sOut, oFolder & "\" & oAsmName & "-" & oItem & ".dxf")
        oCD.FlatPattern.ExitEdit()
        MsgBox(oFolder & "\" & oAsmName & "-" & oItem & ".dxf")
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
    iDoc.Close(True)
Next

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 4

Anonymous
Not applicable
Accepted solution

I checked your code and there was an error. I changed to:

 

        ' Get the design tracking property set.
    Dim invDesignInfo As PropertySet  = iDoc.PropertySets.Item("Design Tracking Properties")
    ' Get the part number property.
    
    Dim oItem As String = invDesignInfo.Item("Part Number").Value

it's work

 

0 Likes