Numeric paramteres precision display

Numeric paramteres precision display

bshbsh
Collaborator Collaborator
472 Views
5 Replies
Message 1 of 6

Numeric paramteres precision display

bshbsh
Collaborator
Collaborator

Hi,

when I type in a numerical parameter through the GUI, let's say for example a hole depth of 20mm, it will display as "20mm" and when queried through VBA it will be "2" (centimeters).

However, when I change the value through VBA, it will be shown on the GUI as "20.000000 mm" and when read by VBA it will be 2.00000 cm as well.

I have this problem with changing every kind of numerical parameters through VBA, and I have no idea how to do this correctly.

Could anyone help me please? Thanks in advance.

0 Likes
473 Views
5 Replies
Replies (5)
Message 2 of 6

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Can you make a screenshot of the parameterbox in inventor.

Maybe I have the solution!

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 6

bshbsh
Collaborator
Collaborator

Here's an example what I mean.

This is what the value of the thickness and the hole diameter looks like when typed in via these dialog boxes:

Clipboard01.jpgClipboard02.jpgClipboard03.jpg

And after running this macro (a simplified example of how I want to change these parameters)

Public Sub ChangeParameters()
    Dim ThicknessBefore, ThicknessAfter, HoleDiaBefore, HoleDiaAfter As String
    ThicknessBefore = ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Expression
    HoleDiaBefore = ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Expression
    ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Value = 0.5
    ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Value = 1.5
    ThicknessAfter = ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Expression
    HoleDiaAfter = ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Expression
    MsgBox (ThicknessBefore & vbNewLine & ThicknessAfter & vbNewLine & HoleDiaBefore & vbNewLine & HoleDiaAfter)
End Sub

The parameter Expressions change (obviously), but the display unnecessary tailing decimal zeroes. Also the parameters DecimalPrecision is set to 3, so it should only display at most 3 zeroes.


Clipboard04.jpgClipboard05.jpgClipboard06.jpgClipboard07.jpg

0 Likes
Message 4 of 6

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Try this:

 

Public Sub ChangeParameters()
    Dim ThicknessBefore, ThicknessAfter, HoleDiaBefore, HoleDiaAfter As String
    ThicknessBefore = ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Expression
    HoleDiaBefore = ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Expression
    ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Expression = "0.7 mm"
    ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Expression = "1.6 mm"
    ThicknessAfter = ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Expression
    HoleDiaAfter = ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Expression
    MsgBox (ThicknessBefore & vbNewLine & ThicknessAfter & vbNewLine & HoleDiaBefore & vbNewLine & HoleDiaAfter)
End Sub

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

bshbsh
Collaborator
Collaborator

Thanks, that of course works, but do I really have to construct the expressions myself to do that? Isn't there an evaluator function somewhere that returns the expression in the proper format from the value?

0 Likes
Message 6 of 6

bradeneuropeArthur
Mentor
Mentor

change to this:

 

Public Sub ChangeParameters()
    Dim ThicknessBefore, ThicknessAfter, HoleDiaBefore, HoleDiaAfter As String
    ThicknessBefore = ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Expression
    HoleDiaBefore = ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Expression
    
    ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Expression = "0.7" & ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Units
    ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Expression = "1.6" & ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Units
    
    'ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Units
    ThicknessAfter = ThisApplication.ActiveEditDocument.ComponentDefinition.Thickness.Expression
    HoleDiaAfter = ThisApplication.ActiveEditDocument.ComponentDefinition.Features.HoleFeatures.Item(1).HoleDiameter.Expression
    MsgBox (ThicknessBefore & vbNewLine & ThicknessAfter & vbNewLine & HoleDiaBefore & vbNewLine & HoleDiaAfter)
End Sub

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