API bug: Setting the expression of a parameter in a drawing sketch fails since IV2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
It seems that Inventor 2023 has a bug while setting the expression of a parameter in a drawing sketch.
We've recently migrated from IV2021 to IV2023 and I can confirm that the situation below works in IV2021, but doesn't work in IV2023 (2023.2).
To recreate the issue:
1. Start a new .idw.
2. Create a Sketch on the .idw.
3. Draw a rectangle and add 2 dimensions to constrain the size. The parameters connected to the dimensions will become d0 and d1.
4. Finish the sketch.
5. Run the code below from VBA, which will change the expression from the second dimension constraint to reference the dimension (d0) of the first constraint.
6. This will prompt an error at line 10: "Invalid procedure call or argument".
7. Now undo the Sketch Edit.
8. Change line 10 to oSketch.DimensionConstraints.Item(2).Parameter.Expression = "100 mm + 100 mm".
9. Run the code again, this will work, so the error is in referring to d0 in this case.
10. When you manually set the dimension in sketch to "d0 + 100 mm", it will not give an error.
11. This problem also occurs via iLogic.
12. This problem only occurs on drawings, not on parts/assemblies.
Sub ErrorSettingExpression()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oSketch As Sketch
Set oSketch = oDoc.ActiveSheet.Sketches.Item("Sketch1")
oSketch.Edit
oSketch.DimensionConstraints.Item(2).Parameter.Expression = "d0 + 100 mm"
oSketch.Solve
oSketch.ExitEdit
End Sub