Macro - control the text size of a 2D sketch by a coefficient

Hello

The objective: to define a text size proportional to a label using a coefficient that will resize the label and the text it contains in the sketch of a part.

I provide you with the code written by an AI, below:

*' Définir la hauteur de base du texte*
*Dim hauteurBase As Double = 5 ' Hauteur initiale en mm*
*Dim hauteurFinale As Double*
* *
*' Calculer la nouvelle hauteur*
*hauteurFinale = hauteurBase * CoeffMultiplicateur*
* *
*' Appliquer au texte dans l'esquisse nommée "Esquisse1"*
*Dim oDoc As PartDocument = ThisApplication.ActiveDocument*
*Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition*
*Dim oSketch As Sketch = oCompDef.Sketches.Item("Esquisse1")*
* *
*' Parcourir les objets texte de l'esquisse*
*For Each oTextBox As TextBox In oSketch.TextBoxes*
*    oTextBox.Height = hauteurFinale*
*Next*
* *
*' Mettre à jour le modèle*
*InventorVb.DocumentUpdate()*

The problem as soon as I launch the macro, inventor crashes (Inventor 2022 5.2)

I'm a complete ignoramus, would someone correct the code for me, or offer me a code adapted for what I want to get?

Ready in advance

I don't specialize in macros in Inventor, so it's hard to see the problem.

But to debug a macro in general you have to go through the editor and run it step by step (debug mode and F8) in order to see the line that is causing the problem:

Look at this link in English of course, but understandable to debug a macro depending on the type of error:

For your information, AI is great for non-specific macros (VBA exel ok) but specific vba SW, inventor or other, this is something else because too many functions, and few examples for AI which therefore has an annoying tendency to invent non-existent features in the CAD software API and therefore bug the whole thing. And without knowledge in VBA complicated to detect where the AI fails.

1 Like