API get quantity of holes in threadnote

API get quantity of holes in threadnote

TA.Fehr
Advocate Advocate
1,946 Views
4 Replies
Message 1 of 5

API get quantity of holes in threadnote

TA.Fehr
Advocate
Advocate

I'm looking to pull data from my drawing but I can't seem to find where the quantity value for the hole notes are stored.

 

I've made a reference to the dimension a HoleThreadNote, but the only quantity related items are HoleThreadNote.QuantityDefinition and HoleThreadNote.FormattedQuantityNote. Neither of these actually reference the number of holes.

 

I've looked through the WatchItems in the VBA window and can't seem to find which variables store the quantity either.

 

Any help is appreciated.

0 Likes
Accepted solutions (1)
1,947 Views
4 Replies
Replies (4)
Message 2 of 5

clutsa
Collaborator
Collaborator
Accepted solution

I'm really stretching here. You can find the evaluated quantity in noteRef.Text.Text but that's the whole note. I did get this to work but it's super hackish...

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim sh As Sheet = doc.Sheets.Item(1)
Dim oNote = sh.DrawingNotes.HoleThreadNotes.Item(1)
oNote.FormattedHoleThreadNote = "<QuantityNote/>"
MessageBox.Show(oNote.Text.Text, "Title")
undoDef = app.CommandManager.ControlDefinitions.Item("AppUndoCmd")
undoDef.Execute

I tried capturing the FormattedHoleThreadNote in a variable and changing it back to what I captured but that didn't work for some reason so I just run an undo to change the note back to what it was (super hackish)

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 3 of 5

TA.Fehr
Advocate
Advocate

Nice thinking outside the box.

Although I'm averse to any hack coding, I used your idea and created a new variable as a HoleThreadNote and copied the values over. Then when I renamed the "FormattedHoleThreadNote" to "<QuantityNote/>" the change does not affect the original component.

Nice simple and tidy, thanks for the direction

I've modified your code to better explain in case anyone in the future finds this thread

 

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim sh As Sheet = doc.Sheets.Item(1)
Dim oNote = sh.DrawingNotes.HoleThreadNotes.Item(1)
Dim oNote2 as HoleThreadNote = oNote
oNote2.FormattedHoleThreadNote = "<QuantityNote/>"
MessageBox.Show(Replace(oNote2.Text.Text, "X", ""), "Title")
Message 4 of 5

TA.Fehr
Advocate
Advocate

Spoke too soon.

 

 

I didn't notice that when I replaced the one holenote with another, the drawing still updated to the new holenote which means I effectively did nothing.

So my next though would be to save the formatted text in a string, perform the switch and then replace the formatted text with what I had saved. But for some reason it wouldn't reformat, it would convert it to only text.

 

So after about 30 minutes of head-scratching, I found that when I exported the formatted text from the holethreadnote, it exported it incorrectly (this would be Inventor's error as I compared what I was inputting to what Inventor exported and they were identical).

 

Inventor exports this:

 

<QuantityNote/><StyleOverride Font='AIGDT' FontSize='0.2032'>n</StyleOverride><StyleOverride Font='Tahoma' FontSize='0.2032'><HoleProperty HolePropertyID='kHoleDiameterHoleProperty' SetTolerances='False'></HoleProperty> </StyleOverride><StyleOverride Font='AIGDT' FontSize='0.2032'>x</StyleOverride><StyleOverride Font='Tahoma' FontSize='0.2032'> <HoleProperty HolePropertyID='kHoleDepthHoleProperty'False'></HoleProperty></StyleOverride>

 

 

The difference is that on the second hole property, the string reads:

HolePropertyID='kHoleDepthHoleProperty'False'>

But the correct syntax is

HolePropertyID='kHoleDepthHoleProperty' SetTolerances='False'>

So I had to create a makeshift replace command which in all reality winds up being a bit more of a hack job than the undo command because it assumes this is the only error. 

 

 Dim SavedNote As String = oDim.FormattedHoleThreadNote
 oNote.FormattedHoleThreadNote = "<QuantityNote/>"
 Dim QTY As Integer = Replace(oNote.Text.Text, "X", "")
 SavedNote = Replace(SavedNote, "Property'False", "Property' SetTolerances='False")
 oNote.FormattedHoleThreadNote = SavedNote

So long story short, @clutsa, your method, although slightly sacrilegious, is still a better method than what I came up with. I stand by my statement that this could be resolved by Inventor not exporting incorrect formatted notes in the first place.

Message 5 of 5

maxim.teleguz
Advocate
Advocate

your last code was broken, i fixed it and posted it here so that other people can see what you did:

Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim sh As Sheet = doc.Sheets.Item(1)
 Dim oNote = sh.DrawingNotes.HoleThreadNotes.Item(1)
 Dim SavedNote As String = oNote.FormattedHoleThreadNote
 oNote.FormattedHoleThreadNote = "<QuantityNote/>"
 Dim QTY As Integer = Replace(oNote.Text.Text, "X", "")
 SavedNote = Replace(SavedNote, "Property'False", "Property' SetTolerances='False")
 oNote.FormattedHoleThreadNote = SavedNote
InputBox(SavedNote)
0 Likes