How to get referenced object of ModelLeaderNote?

How to get referenced object of ModelLeaderNote?

Rene_Gerlach
Advocate Advocate
1,057 Views
10 Replies
Message 1 of 11

How to get referenced object of ModelLeaderNote?

Rene_Gerlach
Advocate
Advocate

Hi @Anonymous,

 

i try to find out if an occurrence has an ModelLeaderNote.

The occurrence self did not has such a property or function to get this information.

So i tried to iterate through the ComponentDefinition.ModelAnnotations.ModelLeaderNotes.

But unlike the LeaderNote in the drawings which has an AttachedEntity function, the ModelLeaderNote did not have such a function.

 

Is there any other way to find this information?

 

Cheers

René

0 Likes
Accepted solutions (1)
1,058 Views
10 Replies
Replies (10)
Message 2 of 11

HermJan.Otterman
Advisor
Advisor

Hello Rene,

 

what is it that you are trying to do?

 

I did the following:

 

drew a modelleadernote and selected it.

than went to VBA and set a watch on the application

then go to the activedocument , selectset.

 

there you will find the selected modelLeaderNote

 

then search....., here the object structure:

 

Modelleadernote	type: modelleadernote
Definition		type: modelleadernotedefinition
Intent			type: geometryintent
Geometry		type: edge
Parent			type: surfacebody
Parent			type: partcomponent definition

 

I hope you understand this and can do something with it.....

else let me know

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@Rene_Gerlach,

 

Referenced object can be retrieved through definition of ModelLeaderNote(ModelLeaderNoteDefinition). From this definition, either Intent or AnnotaionPlane would give referenced object details as shown below.

 

ModelLeaderNote.jpg

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 11

Rene_Gerlach
Advocate
Advocate

Hello @HermJan.Otterman, @chandra.shekar.g,

 

thanks for your suggestions.

Indeed I tried this already. 

 

@HermJan.Otterman: The  PartComponentDefinition is not the occurence self. I did not found a way to get the Occurrence.

@chandra.shekar.g: I did not find any property/function in the AnnotationPlane which will get the Occurrence?

 

Cheers

Rene

0 Likes
Message 5 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@Rene_Gerlach,

 

Try the below VBA code to get referenced document from ModelLeaderNote. Will this helpful? or Looking for specific occurrence?

 

Sub Main()

    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As AssemblyComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim oNotes As ModelLeaderNote
    For Each oNotes In oDef.ModelAnnotations.ModelLeaderNotes
        Dim oReferDoc As Document
        Set oReferDoc = oNotes.Definition.Intent.Geometry.Parent.ComponentDefinition.Document
    Next
    
End Sub

Thanks and regards,

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 6 of 11

Rene_Gerlach
Advocate
Advocate

Hi @chandra.shekar.g

 

I'm searching for the specific occurrence.

The idea is, select an occurrence, set some information in Attributes and if existing, update this information also in the attached ModelLeaderNote.

So I need to find out has this occurrence an ModelLeaderNote or has any ModelLeaderNote attached to this occurrence.

 

Cheers

 

Rene

0 Likes
Message 7 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@Rene_Gerlach,

 

Try the following VBA code to get specific occurrence of ModelLeaderNote.

 

Sub Main()

    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oDef As AssemblyComponentDefinition
    Set oDef = oDoc.ComponentDefinition
    
    Dim oNotes As ModelLeaderNote
    For Each oNotes In oDef.ModelAnnotations.ModelLeaderNotes
        Dim oBody As SurfaceBody
        Set oBody = oNotes.Definition.Intent.Geometry.Parent
        
        Dim occ As ComponentOccurrence
        For Each occ In oDef.Occurrences.AllLeafOccurrences
            Dim occBody As SurfaceBody
            For Each occBody In occ.Definition.SurfaceBodies
                If oBody Is occBody Then
                    Debug.Print occ.Name
                    GoTo NextIteration
                End If
            Next
        Next
NextIteration:
    Next
    
End Sub

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 8 of 11

Rene_Gerlach
Advocate
Advocate

@chandra.shekar.g,

 

thanks for this solution. It seems to work in my sample.

 

For the real world, I think, this is not a good solution.

There are many loops in a big assembly with 1000 or more occurrences, this will take a lot of time.

 

Cheers

Rene

0 Likes
Message 9 of 11

chandra.shekar.g
Autodesk Support
Autodesk Support

@Rene_Gerlach

 

Currently, there is no direct Inventor API to get referenced occurrence like AttachedEntity of LeaderNote in Drawing document. You can this wish list at idea station using below link.

 

https://forums.autodesk.com/t5/inventor-ideas/idb-p/v1232/tab/most-recent

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 10 of 11

Rene_Gerlach
Advocate
Advocate
0 Likes
Message 11 of 11

cdellea
Enthusiast
Enthusiast

Hi, I know it is very late to answer your question, but I had to do this today, so I found a solution (which works in my case, but I dont know if it is generic enough). So, the function I did works to find the connected EdgeProxy of a ModelLeaderNote in an assembly document :

 

 

public static EdgeProxy FindNoteConnectedEdgeProxy(AssemblyDocument assembly, ModelLeaderNote note)
{
	EdgeProxy edgeProxy = null;
	Edge connectedEdge = note.Definition.Intent.Geometry as Edge;
	SelectionFilterEnum[] selectionFilter = new SelectionFilterEnum[1];
	selectionFilter[0] = SelectionFilterEnum.kPartEdgeFilter;
	ObjectsEnumerator objFound = assembly.ComponentDefinition.FindUsingPoint(note.Definition.Leader.AllNodes[note.Definition.Leader.AllNodes.Count].Position, ref selectionFilter, 0.001, true);
	foreach (object obj in objFound)
	{
		if (obj is EdgeProxy)
		{
			EdgeProxy proxy = (EdgeProxy)obj;
			if (connectedEdge != null)
			{
				if (proxy.NativeObject.Equals(connectedEdge))
				{
					edgeProxy = proxy;
					break;
				}
			}
			else
			{
				edgeProxy = proxy;
				break;
			}
		}
	}
	return edgeProxy;
}

 

 

I have no time to check what kind of object may be connected to a ModelLeaderNote, but I think this example can easily be modify to handles more connected object types. And of course, if you need an occurrence (ComponentOccurrence), this is easily found with the any proxy object through the "ContainingOccurrence" property.

0 Likes