Adding QuantityNote to HoleThreadNote in VBA

Adding QuantityNote to HoleThreadNote in VBA

bshbsh
Collaborator Collaborator
540 Views
3 Replies
Message 1 of 4

Adding QuantityNote to HoleThreadNote in VBA

bshbsh
Collaborator
Collaborator

Hi all,

I'm having difficulties adding QuantityNotes to HoleThreadnotes (based on interactive user selection) with a macro.

As far as I understand (probably wrong...) I have to add it to the FormattedHoleThreadNote string.

The problem is, the string is completely wrong. For example on the attached images, it's a 20mm hole with a H7 tolerance set in the model. When the Holenote is created using the UI, it is correct. But when I read the FormattedHoleThreadNote and try to slap on the Quantitynote, it somehow contains that the tolerance type is a symmetric type, which it is not... And this f*#cks up the holetnote. I can set the hole note afterwards to use part tolerances (which is how the note was created by the UI in the first place) and that fixes it - but I don't know how to change this with VBA. Or where that false "FormattedHoleThreadNote" string comes from...

Currently I'm manipulating the Formatted... string to remove all those false substrings, but that does not always work and it shouldn't be needed in the first place.

Any help please? Thanks.

Clipboard01.jpgClipboard02.jpgClipboard03.jpg

0 Likes
541 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @bshbsh.  It appears that you are on the right track, by accessing the HoleThreadNote.FormattedHoleThreadNote, because that is where much of that type of stuff is handled by code.  After seeing a great many of the 'behind the scenes' codes inside many different FormattedText scenarios, you really start to appreciate the user interface tools we have available for editing these things.  What I usually recommend is that you reverse engineer the note...what I mean is, try creating the note using the user interface tools just the way you want it, then inspect its FormattedText by code to see its contents.  Then copy/paste that back into your rule/macro for creating it by code.  In order to get something you can copy/paste, I recommend using an InputBox, instead of a MsgBox or MessageBox.Show, and setting the value as the 'default response' portion, that way it will be in the interactive textbox area of the dialog when it pops-up.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

bshbsh
Collaborator
Collaborator

I'm not creating the notes, they are created using the UI. All the macro does (using it for years now but it annoys me that it f*cks up the note sometimes) is allow the user to select the hole notes to which they want to add a quantity note (because it is not there by default on purpose) and adds it.

This should not need any "reverse engineering" or anything, should be as simple as:

HoleThreadNote.FormattedText = HoleThreadNote.FormattedText & "<Br/><StyleOverride FontSize='0.25'>(<QuantityNote/>)</StyleOverride>"

But it's hard to make it work for all the hundreds of different hole tpye combinations, if the FormattedText is already wrong. I'm forging it by trying to remove the "tolerancetype" and similar things, that used to work 90% the time. Oh it is also "interesting" that the string sometimes contains the "precision" values using a "." as a decimal marker, sometimes using a "," (comma) (which is my default locale), apparently randomly (this is the case all over the numeric values in Inventor...) So even the above simple code may fail if inventor is using the comma, because it won't interpret the "0.25"...

Or why the holethreadnote ist not "Retrieved" and has no "ModelValue" even if it clearly gets it's value from a model feature...?

Or why the tap drill diameter for internal pipe threads is wrong in the threads.xls since decades...

So I'm not aprreciating the behind the scenes work, that fails, sorry. 😛

Message 4 of 4

bshbsh
Collaborator
Collaborator

Bump!

 

I have a new problem. After upgfrading to 2023, the macro works (with the above problem of course) on some hole notes, but on many of them, when I replace the FormattedText with all those xml stlye "<" and ">" brackets, they get replaced by escaped texts "&lt;" and such, and instead of the expected threadnote, this whole formattednote text appears. Any idea why this happens now all of a sudden? And why only on some notes?

 

Edit:

so just doing this, getting the Note into a string and writing it straigt back without any modification:

 

S = BInfo.FormattedHoleThreadNote
BInfo.FormattedHoleThreadNote = S

 

turns the content of the Not to this:

bshbsh_0-1687844356610.png

and the Note will be displayed as a text, showing basically the string S.

bshbsh_0-1687845794211.png

 


0 Likes