Annotation

Annotation

Thetigerpirro
Advocate Advocate
4,257 Views
17 Replies
Message 1 of 18

Annotation

Thetigerpirro
Advocate
Advocate

Hi, I would like to add a code that automatically puts a Annotation in my model but i cant seem to find how.
What I'm doing is measuring the flat pattern and if it goes above my recommended size, i want it to show up as a annotation. Pop-ups wont work well and are way to intrusive for this. I also want the note to get deleted when it goes under my specified value. 

All the measuring and stuff I can do myself but I dont know how to call the API to make/delete Annotations.

 

 

Annotation.png

0 Likes
Accepted solutions (3)
4,258 Views
17 Replies
Replies (17)
Message 2 of 18

WCrihfield
Mentor
Mentor

Under the PartComponentDefinition, you should find ModelAnnotations, then depending on what type of model annotation you want, you can either go the ModelDimensions, ModelGeneralNotes, or ModelLeaderNotes (or others), then you should find options for adding one.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 18

Thetigerpirro
Advocate
Advocate

Thanks. I have gotten a little bit further but I dont have a good grasp on how to work against API.
This is my code so far:

Dim partcompdef As PartComponentDefinition
partcompdef = ThisApplication.ActiveDocument.ComponentDefinition

partcompdef.ModelGeneralNoteDefinition.Add("kaka")

Any pointers? 

0 Likes
Message 4 of 18

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Thetigerpirro 

This code will add the note:

Dim partcompdef As PartComponentDefinition
partcompdef = ThisApplication.ActiveDocument.ComponentDefinition

Dim noteDef As ModelGeneralNoteDefinition = partcompdef.ModelAnnotations.ModelGeneralNotes.CreateDefinition("kaka", True)
Dim onote As ModelGeneralNote = partcompdef.ModelAnnotations.ModelGeneralNotes.Add(noteDef)
oNote.Name = "KAKA NOTE"

And this code will delete it:

Dim partcompdef As PartComponentDefinition
partcompdef = ThisApplication.ActiveDocument.ComponentDefinition

On Error Resume Next
Dim oNote As ModelGeneralNote = partcompdef.ModelAnnotations.ModelGeneralNotes.Item("KAKA NOTE") 'Name of note
oNote.Delete

Hope it helps! 🙂

kaka.PNG

Message 5 of 18

Luisfmts
Enthusiast
Enthusiast

hi @JhoelForshav

First code, in an assembly environment,  for adding the General Note works fine. But the second one the method for deleting fails.

Do you know why? I also tried the Proxy but not sure if the implementation is similar. 

Regards,
Luís

0 Likes
Message 6 of 18

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Luisfmts 

I see that... I guess it's just a bug that you cannot delete ModelGeneralNotes in Assembly Environment.

Something like this as a workaround will have to do 🙂

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim odef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim selSet As SelectSet = oAsm.SelectSet
selSet.Clear
On Error Resume Next
selSet.Select(odef.ModelAnnotations.ModelGeneralNotes.Item("KAKA NOTE")) 'Name of note
ThisApplication.CommandManager.ControlDefinitions("AppDeleteCmd").Execute

 

Message 7 of 18

Luisfmts
Enthusiast
Enthusiast

Hi @JhoelForshav,

It worked perfectly. It is always nice to learn some new workarounds like this 😄

Thank you!

Message 8 of 18

ngdnam88
Advocate
Advocate

Hi @JhoelForshav 
Can you share Code that delete all General Note in 3D Model?

 

Thanks,

0 Likes
Message 9 of 18

WCrihfield
Mentor
Mentor

Hi @ngdnam88.  Here is an iLogic rule you can try for deleting all ModelGeneralNote objects from a Part or Assembly document.  It can be used on either a Part or an Assembly, and can also be used as an external rule if needed.

 

Sub Main
	Dim oDoc As Document = ThisApplication.ActiveDocument
	Dim oMA As ModelAnnotations
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		Dim oADoc As AssemblyDocument = oDoc
		oMA = oADoc.ComponentDefinition.ModelAnnotations
	ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oPDoc As PartDocument = oDoc
		oMA = oPDoc.ComponentDefinition.ModelAnnotations
	Else
		MsgBox("A Part or Assembly must be 'Active' for this rule to work.  Exiting.", vbExclamation, "iLogic")
		Exit Sub
	End If
	
	If oMA.ModelGeneralNotes.Count = 0 Then Exit Sub
	For Each oMGN As ModelGeneralNote In oMA.ModelGeneralNotes
		oMGN.Delete
	Next
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 18

ngdnam88
Advocate
Advocate
Thanks @WCrihfield
It's working perfectly!
0 Likes
Message 11 of 18

ngdnam88
Advocate
Advocate

Hi @WCrihfield

I just tested one more times and got a problem with assembly. Please help me. Thanks,

A005.PNG

0 Likes
Message 12 of 18

ngdnam88
Advocate
Advocate

Hi @WCrihfield 

I just tested one more times and got a problem with assembly. Please help me. Thanks,

A005.PNG

0 Likes
Message 13 of 18

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @ngdnam88 

The code @WCrihfield posted works for inventor 2022. For older versions though (don't know about 2021, but at least 2020 and earlier), there's a bug when it comes to deleting annotations in assemblies. That's why I wrote a workaround for that earlier in this thread. I have modified @WCrihfield's code to use this workaround for assemblies. Hope it helps!

Sub Main
	Dim oDoc As Document = ThisApplication.ActiveDocument
	Dim oMA As ModelAnnotations
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		Dim oADoc As AssemblyDocument = oDoc
		oMA = oADoc.ComponentDefinition.ModelAnnotations
	ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oPDoc As PartDocument = oDoc
		oMA = oPDoc.ComponentDefinition.ModelAnnotations
	Else
		MsgBox("A Part or Assembly must be 'Active' for this rule to work.  Exiting.", vbExclamation, "iLogic")
		Exit Sub
	End If

	If oMA.ModelGeneralNotes.Count = 0 Then Exit Sub
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		Dim oSelSet As SelectSet = oDoc.SelectSet
		Dim oCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
		For Each oMGN As ModelGeneralNote In oMA.ModelGeneralNotes
			oCol.Add(oMGN)
		Next
		oSelSet.SelectMultiple(oCol)
		ThisApplication.CommandManager.ControlDefinitions("AppDeleteCmd").Execute
	Else
		For Each oMGN As ModelGeneralNote In oMA.ModelGeneralNotes
			oMGN.Delete
		Next
	End If
End Sub
Message 14 of 18

ngdnam88
Advocate
Advocate
I'm using Inventor 2018.3. Your code is working perfectly!
Thanks you very much!
0 Likes
Message 15 of 18

ngdnam88
Advocate
Advocate

Dears @JhoelForshav @WCrihfield 
Is possible rename it to new name?

ngnam1988_0-1672988331732.png

Thanks,

0 Likes
Message 16 of 18

WCrihfield
Mentor
Mentor

Hi @ngdnam88.  Yes.  Much like before, you just have to dig down to that ModelGeneralNote object, then change the value of its Name property to something else.  The following code is just a very basic example for doing that in an assembly, which has just one ModelGeneralNote.  It just had its default name before running the code, then when I ran this code, it change its name to "INFO", just like in your image.

Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oMAs As ModelAnnotations = oADoc.ComponentDefinition.ModelAnnotations
Dim oMGN As ModelGeneralNote = oMAs.ModelGeneralNotes.Item(1)
oMGN.Name = "INFO"

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 17 of 18

DeckTechnick
Explorer
Explorer

.

0 Likes
Message 18 of 18

DeckTechnick
Explorer
Explorer

Hi,

I have a similar problem:

I tried to put a note baseded  in user parameter (kind "int_ref=1.234") into a model general note (into kUpperLeftQuadrant), and when i use

"<Parameter Resolved='True' ComponentIdentifier='" & oDoc.FullDocumentName & "' Name='int_ref' Precision='2'>" & Parameter("int_ref") & "</Parameter>"

 it keep me sending the same error:

"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

The error persist in assamblies and parts documents.

Can u tell what is wrong ?

0 Likes