ModelStats vs. existing VBA Codes

ModelStats vs. existing VBA Codes

bindlmi
Advocate Advocate
539 Views
5 Replies
Message 1 of 6

ModelStats vs. existing VBA Codes

bindlmi
Advocate
Advocate

Hi,
we will be updating Inventor 2021 to 2023 and I have noticed that existing VBA macros no longer work.
After many small tests I could find that the macros do not work if a second model state exists.
Is such a problem known? Can anyone confirm this?

 

As an example I have prepared a small macro:

 

Public Sub Test()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oOcc As ComponentOccurrence
Set oOcc = oDoc.ComponentDefinition.Occurrences.Item(1)

Dim oParameters As Parameters
Set oParameters = oOcc.Definition.Parameters

oParameters.Item("Breite").value = 20

End Sub


You need an assembly for it. In this assembly comes a part. And this part needs 2 model states and a parameter called "Breite". Run the macro in the assembly.

bindlmi_0-1658482092115.png  bindlmi_1-1658482142690.png

The error then appears when setting the parameter value.

bindlmi_2-1658482239825.png

If you remove the second model state, the macro works.

 

Regards

Michael

 

 

 

0 Likes
Accepted solutions (2)
540 Views
5 Replies
Replies (5)
Message 2 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

This is a known problem. There is quite some information gathered here on the forum. A good starting point would probably be the sticky thread "Important for developers working with Level Of Details".

Later this year I will be having the same issues therefore I have also some links on my blog. These are my personal notes/links but maybe they are useful for you as well. Have a look at: http://www.hjalte.nl/52-links

 

One last offtopic point. Check my blog post: "Is VBA in Inventor obsolete?"

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 6

bradeneuropeArthur
Mentor
Mentor
Aren't you using Inventor 2022 at the moment, because you will also have issues in the near future?
The change of the LOD's into modelstates is to my opinion unsatisfactory!

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 4 of 6

JelteDeJong
Mentor
Mentor

At home, I'm on 2021 but I stay away from model states if possible. But in my job, we are planning to move to 2024 next year. Before that time I need to update all my addons and configurator. And I agree with you im not happy at all with the model states. But we need to deal with it...

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

0 Likes
Message 5 of 6

bradeneuropeArthur
Mentor
Mentor
Maybe Inventor 2025 will again deal with it different. We are on 2022 and it is a not workable with older designs that were based on possiblities with LOD's.

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 6 of 6

bindlmi
Advocate
Advocate
Accepted solution

Hi,

thanks for the helpful answers. The links helped me to fix the problem.
In short: You have to explicitly select the document if there are multiple model states.
Fixed macro:

Public Sub Test()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oOcc As ComponentOccurrence
Set oOcc = oDoc.ComponentDefinition.Occurrences.Item(1)

Dim oPartDoc As PartDocument
Set oPartDoc = oOcc.Definition.Document

'Check, if the Occurrence-Document is ModelStateMember ( = has ModelStates)
If oPartDoc.ComponentDefinition.IsModelStateMember = True Then
    Set oPartDoc = oPartDoc.ComponentDefinition.FactoryDocument
Else
    Set oPartDoc = oPartDoc
End If

'Make sure to edit all Members
oPartDoc.ComponentDefinition.ModelStates.MemberEditScope = kEditAllMembers

Dim oParameters As Parameters
Set oParameters = oPartDoc.ComponentDefinition.Parameters

oParameters.Item("Breite").value = 20

End Sub
0 Likes