Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Naming a save file from iproperties

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
458 Views, 3 Replies

Naming a save file from iproperties

'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.

 

 

Labels (2)
3 REPLIES 3
Message 2 of 4
bradeneuropeArthur
in reply to: Anonymous

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:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !

Message 3 of 4

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:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
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: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 !

Message 4 of 4
Anonymous
in reply to: Anonymous

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

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report