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. ๐
Solved! Go to Solution.
Solved by rjay75. Go to 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.
Can't find what you're looking for? Ask the community or share your knowledge.