Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
SOLVED
Reply
Message 1 of 2
alyssaweaver
434 Views, 1 Reply

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

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. 😄

 

 

Best Wishes,
Ali

|---------------------------------------------------------------------------------------------------------------------|
"It's a screwdriver, not a water pistol! What are you gonna do? Construct a cabinet at them?!"
1 REPLY 1
Message 2 of 2
rjay75
in reply to: alyssaweaver

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.

Post to forums  

Autodesk Design & Make Report