Jump to content

Inventor VBA, working with reference keys


Recommended Posts

Posted

Hi guys, trying to do some work with selecting objects in drawings, and retrieving information. so far i've managed to be able to select an object, in this case a leader note, but i need to retrieve information about it's nodes etc. however, i can't seem to access this information using the code i've got, so i've had to retrieve the reference key for the object, and i was hoping to access the information through drawingnotes.leadernotes which i can get if i reference the objects using leadernotes.item(1) etc... but the problem is that the item number will change as the drawing is edited...

 

SO, the question is, having the reference key for an object, how do i then refer to that object, and access it's properties?

 

code i have so far is:

 

Public Sub TestSelection()
   ' Create a new clsSelect object.
   Dim oSelect As New clsLeaderGhost
   
   Dim odoc As DrawingDocument
   Dim oleader As DrawingNote
   Dim oNotes As LeaderNotes
   
   Dim Lrefkey() As Byte
   Dim lrefkeystr As String
   Dim Leaderinfo As New Collection
   
   Set odoc = ThisApplication.ActiveDocument
   Set oNotes = odoc.ActiveSheet.DrawingNotes.LeaderNotes
   ' Call the pick method of the clsSelect object and set
   ' the filter to pick any Drawing Note.
   Set oleader = oSelect.Pick(kDrawingNoteFilter)
   

   ' Check to make sure an object was selected.
   If Not oleader Is Nothing Then
       
       Call oleader.GetReferenceKey(Lrefkey)
       lrefkeystr = odoc.ReferenceKeyManager.KeyToString(Lrefkey)
       
       For n = 1 To oNotes.Item(Lrefkey).Leader.AllNodes.Count
           Leaderinfo.Add (oNotes.Item(1).Leader.AllNodes.Item(n).Position.X)
       Next
       
   End If
End Sub

Posted

Knowing nothing about the Inventor API, have you tried adding a breakpoint in the code and seeing what methods or properties are available to the object you are referring to while it is running?

Posted

Just figured it out while trying to type an explaination for why it wasn't working... i have oLeader declared as a drawingnote, and oNotes declared as leadernotes.... so by declaring oLeader as leadernote (note that oNotes is leadernoteS i.e. plural) i can access all the information i want...

 

thanks for making me look harder :-D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...