Code to See if a Drawing Note is Detached?

Code to See if a Drawing Note is Detached?

el_jefe_de_steak
Collaborator Collaborator
583 Views
3 Replies
Message 1 of 4

Code to See if a Drawing Note is Detached?

el_jefe_de_steak
Collaborator
Collaborator

Hi, I'm working on some code that "cleans up" a drawing, automatically removing any broken annotations and drawing dimensions.

 

The process is very simple for dimensions and balloons:

For Each oDim As GeneralDimension In thisSheet.DrawingDimensions.GeneralDimensions
   If oDim.Attached = False Then
      oDim.Delete()
   End If
Next

 

 

However, I cannot seem to find a property that works like the .Attached property for LeaderNotes and HoleThreadNotes. There is obviously something that does this somewhere in Inventor, because leader notes turn pink, and Hole and Thread notes grey out when they become "detached".

 

Does anyone know how to do this?

0 Likes
Accepted solutions (2)
584 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

For the leader notes, you have to check the nodes on the leader. For the HoleThreadNote I think there is attached property. At least this rule works for me.

Dim doc As DrawingDocument = ThisDoc.Document

Dim sheet As Sheet = doc.ActiveSheet
For Each note As LeaderNote In sheet.DrawingNotes.LeaderNotes
    ' Dim t = note.Leader.AllNodes.Count
    If (note.Leader.HasRootNode = False) Then
        ' This happens if the leader has been deleted.
    Else
        Dim attachedNodeList = note.Leader.AllNodes.
            Cast(Of LeaderNode).Where(Function(n) n.AttachedEntity IsNot Nothing).ToList()
        If (attachedNodeList.Count = 0) Then
            note.Delete()
        End If
    End If
Next

For Each note As HoleThreadNote In sheet.DrawingNotes.HoleThreadNotes
    If (note.Attached = False) Then
        note.Delete()
    End If
Next

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 4

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

I think it would be easier to set

 

 

 

Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
oDrawDoc.DrawingSettings.PreserveOrphanedAnnotations = False

 

 

 

EDIT: If the HoleThreadNote on a threaded hole is attached to the hole (not to the thread symbol) and the hole is deleted, the HoleThreadNote is not not getting pink. Instead it's getting light gray. If this is selected manual, the API returns the ActiveSheet as selected object and in this case there's no attached property and  it's not possible to delete.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 4 of 4

el_jefe_de_steak
Collaborator
Collaborator

Thanks, to both @Ralf_Krieg and @JelteDeJong. I found that both of your solutions worked to some extent.

 

@Ralf_Krieg this works amazingly, and I have implemented it into my project. One thing to note is that it does not delete broken dimensions, only annotation objects.

 

@JelteDeJong you were absolutely correct about the HoleThreadNote having an "Attached" property. I simply overlooked this in the API reference. However, I could not get your code to work for the LeaderNote. I get this error:

  • System.MissingMemberException: 'Public member 'Cast' on type 'LeaderNodesEnumerator' not found.'

For context, I am using this in VB.net with a program compiled in Visual Studio. I have not tried it in iLogic, but I assume that I would get the same result.

0 Likes