Define material-iProperty in VBA userform

Define material-iProperty in VBA userform

uw
Advocate Advocate
945 Views
8 Replies
Message 1 of 9

Define material-iProperty in VBA userform

uw
Advocate
Advocate

Hello!

 

I have designed a VBA-code which starts a userform with textboxes to fill in iProperties for the active project.

No problem so far.

But for defining the material-iProperty it would be perfect to have a combobox to select the material from the active material-database.

(To have an option for selecting the material-database would be great)

 

Thank you for any help you can offer!

 

Regards,

 Reinhard

0 Likes
946 Views
8 Replies
Replies (8)
Message 2 of 9

marcin_otręba
Advisor
Advisor

Adding all mat librarys:

 For i = 1 To g_inventorApplication.AssetLibraries.Count
            mat_lib(i)=g_inventorApplication.AssetLibraries.Item(i).DisplayName
  Next

 

Adding materials from mat lib:

 

Dim assetLib As AssetLibrary
 assetLib = g_inventorApplication.AssetLibraries.Item("materialy")
For i = 1 To assetLib.MaterialAssets.Count
                      mats_inv(i) = assetLib.MaterialAssets.Item(i).DisplayName.ToString
            Next

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 9

uw
Advocate
Advocate

Hello.

 

Please be lenient with me, buit I'm far away from being an VBA-expert...

 

I tried following code (called by a combobox of a userform):

_______________________________________________

Private Sub ComboBox1_Change()

    Dim i As Integer
    Dim mat_lib(1 To g_inventorApplication.AssetLibraries.Count) As Variant

        For i = 1 To g_inventorApplication.AssetLibraries.Count
            mat_lib(i) = g_inventorApplication.AssetLibraries.Item(i).DisplayName
        Next
    UserForm1.ComboBox1.List = mat_lib()

End Sub

_______________________________________________

There is no error or warning, but the list is empty:

Combobox.png

Even though there are material-libaries in my project:

Libaries.png

Thank you for any help you can offer!

 

Regards,

 Reinhard

0 Likes
Message 4 of 9

marcin_otręba
Advisor
Advisor

try:

Private Sub ComboBox1_Change()

    Dim i As Integer
    Dim mat_lib(g_inventorApplication.AssetLibraries.Count) As string

        For i = 1 To g_inventorApplication.AssetLibraries.Count
            mat_lib(i) = g_inventorApplication.AssetLibraries.Item(i).DisplayName
        Next
    UserForm1.ComboBox1.List = mat_lib()

End Sub

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 9

uw
Advocate
Advocate

Hello!

 

Thank you for your answer and your patience, but I'm affraid the solution is not working..

(Maybe I use your solution in a wrong way...)

 

In Inventor2019 I created a new ipt-file and with Alt+F11 I startet the VBA-environment.

I created a new UserForm with a ComboBox:

ComboBox01.png

With a doubleclick on the ComboBox I started the code-environment and entered following code:

ComboBox02.png

With F5 I tried to test the code, and the combobox was still empty:

ComboBox03.png

Thank you for any help you can offer!

 

Regards,

 Reinhard

0 Likes
Message 6 of 9

marcin_otręba
Advisor
Advisor

Replace g_inventorApplication with thisapplication.

Net post if aby error occur Please place screen with error message 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 9

uw
Advocate
Advocate

Hello.

 

Combobox04.png

No error messages but also no changes in the ComboBox - it is still empty Smiley Sad

 

Regards

 Reinhard

0 Likes
Message 8 of 9

marcin_otręba
Advisor
Advisor

hi,

 

Sorry i was writing from my mobile and focused on code, did't realise that you put code in wrong sub:

should bin in for initialize sub

 

try this instead:

 

Private Sub UserForm_Initialize()
    Dim i As Integer
    Dim mat_lib() As String
        For i = 1 To ThisApplication.AssetLibraries.Count
         ReDim Preserve mat_lib(i)
            mat_lib(i - 1) = ThisApplication.AssetLibraries.Item(i).DisplayName
         
        Next
    UserForm1.ComboBox1.List = mat_lib()


End Sub

 



End Sub

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 9 of 9

uw
Advocate
Advocate

Thank you very, very much!!!

 

It works:

ComboBox5.png

But when I try to fill a ComboBox with the materials of a certain libary (e.g. "Inventor-Materialbibliothek")

with following code:

________________________________

Private Sub UserForm_Initialize()

Dim i As Integer
Dim assetLib As AssetLibrary

assetLib = g_inventorApplication.AssetLibraries.Item("Inventor-Materialbibliothek")

For i = 1 To assetLib.MaterialAssets.Count
mats_inv(i) = assetLib.MaterialAssets.Item(i).DisplayName.ToString
Next

End Sub

________________________________

I get following error-message:

 

ComboBox6.png

Unfortunately (for you Smiley Wink) the message is in german.

It means something like "improper use of a property"

 

I hope you can help me one more time...

 

Thank you and have a nice evening!

 

Regards

 Reinhard

0 Likes