Inventor, Part, Assembly...Defining Where I Am using VBA

Inventor, Part, Assembly...Defining Where I Am using VBA

Anonymous
Not applicable
503 Views
1 Reply
Message 1 of 2

Inventor, Part, Assembly...Defining Where I Am using VBA

Anonymous
Not applicable

How do you define that you're in an assembly and want to select a component based on its name? Any sample snippets of code would be appreciated.

 

Here's my "pseudo-code":

 

Sub SelectMyPart ()

Dim ThisApplication As something
Dim ThisDocument As something
Dim ThisAssemblyDocument As something
Dim ThisPart (MY PART NAME) As something
Select (MY PART NAME)

blahblahblah actions

End Sub

 

 

Other secondary questions of interest:

1. My compiler doesn't like

For Each oOcc In ThisApplication.ActiveDocument.ComponentDefinition.Occurrences

 My theory is because it's an assembly document and doesn't know that. Do you agree?

 

 

2. Have you ever replaced a component using the VBA editor? If so, would you be so kind as to share how you did it? I have all the dirty work done of identifying the complicated parts of what is getting replace. I just can't get the replace itself to work 😞

 

3. Do you have issues with oOcc / oOccurrence? My compiler REALLY dislikes this.

 

Thanks for all your help! I'm not posting the full code for now, since my main question is about identifying that it's an  Inventor Part from a designated assembly. I will post it if requested, but I don't want to scare away potential answers because of a long post. 😄

 

 

0 Likes
Accepted solutions (1)
504 Views
1 Reply
Reply (1)
Message 2 of 2

rjay75
Collaborator
Collaborator
Accepted solution

ThisApplication is predefined to point to the Inventor application.

ThisDocument is only available from certain modules in VBA.

 

If you want specifiy your own ThisDocument object you can do this in your sub.

 

Sub WhatAmI()
  Dim ThisDocument As Document
  ThisDocument = ThisApplication.ActiveDocument

  If ThisDocument.DocumentType = kAssemblyDocumentObject Then
    MsgBox "I'm an assembly document."
  ElseIf ThisDocument.DocumentType = kPartDocumentObject Then
    MsgBox "I'm a part document."
  ElseIf ThisDocument.DocumentType = kDrawingDocumentObject Then
    MsgBox "I'm a part document."
  End If
End Sub

 You compare the DocumentType property of a document to see what it is.

0 Likes