How to make a folder selection persistent per each assembly file?

How to make a folder selection persistent per each assembly file?

Anonymous
Not applicable
381 Views
2 Replies
Message 1 of 3

How to make a folder selection persistent per each assembly file?

Anonymous
Not applicable

Greetings.

 

I'm making a simple form with the API to export components from an assembly to STEP. The idea looks like this:

 

pagutierreza_0-1629997570190.png

So far I've only focused on getting the layout. I managed to get the select folder code to work, but it resets every time inventor is closed. What I want to achieve is make the folder selection at first, and let it be persistent across multiple sessions. We're usually exporting and increasing versions on a regular basis for individual parts and assemblies of the projects we work on, so having to navigate the target folder each time defeats the purpose of automation.

 

I would like this persistence to be unique per each assembly we're working with. Is there a way to store the two folder selections in the assembly file the form is run on?

 

Thank you in advance.

 

 

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

JelteDeJong
Mentor
Mentor
Accepted solution

You could use the document attributes to save your data. something like this might work for you.

Public Class ThisRule

    Private _attSetName As String = "PersistentSelectionTool"
    Private _attName As String = "folder"
    Public Sub Main()

        SetPersistentSelection("C:\temp\.....")

        Dim selectedFolder = GetPersistentSelection()

        MsgBox(selectedFolder)

    End Sub
    Public Sub SetPersistentSelection(folder As String)

        Dim doc As Document = ThisDoc.Document
        Dim attSet As AttributeSet
        If (doc.AttributeSets.NameIsUsed(_attSetName)) Then
            attSet = doc.AttributeSets.Item(_attSetName)
        Else
            attSet = doc.AttributeSets.Add(_attSetName)
        End If


        If (attSet.NameIsUsed(_attName)) Then
            Dim att As Attribute = attSet.Item(_attName)
            att.Value = folder
        Else
            attSet.Add(_attName, ValueTypeEnum.kStringType, folder)
        End If

    End Sub

    Public Function GetPersistentSelection() As String
        Dim doc As Document = ThisDoc.Document
        Dim att As Attribute = doc.AttributeManager.FindAttributes(_attSetName, _attName).
                                                Cast(Of Attribute).First()
        Return att.Value
    End Function
end class

You can find more information about attributes on this blog. Also if you are going to work with attributes then you might want to have a look at this addin.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

Anonymous
Not applicable

Thank you! This is exactly what I need. The blog post also gave me an idea of another thing I'm working on. Thank you so much.

0 Likes