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

Did you find the error?

@sbadenis

To the that no!
Originally it was for one of my colleagues who wanted to set txt on a label according to the size of it
He told me to use an AI, and as you explained to me it's.
The little kid gave up, but if anyone has the answer I'm taker, for my culture.
The problem is to retrieve the txt parameter, and I read on Autodesk support (2020) that this is not possible. And that it's a minor evolution so it's not possible to get it back in the version of my Inventor.
I stay tuned

For me AI is very good for coding or other, you just have to understand and know corrected or redirected in case of error.
As with an RDM calculation, we must absolutely not blindly trust AI without a minimum of knowledge, impossible to know the true from the false in what it brings us.

AI has brought me a lot of solutions in macro in particular, but rarely functional on the 1st try and very often with a lot of debugging and coorective.

1 Like

I kind of agree with that, but I've already made macro sldws that work with AI while I don't beat anything in coding. A lot of debugg and a lot of corrections but it's possible for a noob.

For the RDM I agree with you, AI is a support that I use to validate calculations, it also brings some interesting information on some sometimes obscure features of solver settings.

2 Likes