ThisApplication.ActiveDocument.ComponentDefinition fail

ThisApplication.ActiveDocument.ComponentDefinition fail

Darkforce_the_ilogic_guy
Advisor Advisor
1,738 Views
5 Replies
Message 1 of 6

ThisApplication.ActiveDocument.ComponentDefinition fail

Darkforce_the_ilogic_guy
Advisor
Advisor

why does this sometimes fail , and sometimes not

 

Dim oAsmCompDef As AssemblyComponentDefinition
 
 'illogic code
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

 

both files are made form the same templet

 

and add some files to it form vault.

 

one of them fail and one of them do not how can it be and is there a way to not make it fail ?

 

 

 

 

0 Likes
1,739 Views
5 Replies
Replies (5)
Message 2 of 6

Sergio.D.Suárez
Mentor
Mentor

If you are going to work in ilogic, replace the string "ThisApplication.ActiveDocument" with the

 

"ThisDoc.Document"

 

It usually gives problems when it comes to active documents. (In VBA this is not so easy, since the ThisDoc.Document statement does not exist)
For example if you have an assembly file with a component that has an internal rule and this defines the document as "ThisApplication.ActiveDocument"
From the assembly you edit component and execute the rule, it will give an error because your active document is not that of the component. Your active document is the one of assembly.

 

In contrast if in the rule of ilogic would have placed   "ThisDoc.Document "  there would be no problems.
I hope I have been clear and that this helps your problem.

Best Regards!!

 

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 6

bradeneuropeArthur
Mentor
Mentor

@Sergio.D.Suárez 

 

Public Sub main()

Dim a As Document
Set a = ThisDocument.InventorDocument

MsgBox a.FullDocumentName
End Sub

Public Sub main()

Dim a As Document
Set a = ThisDocument

MsgBox a.FullDocumentName
End Sub

both work!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 6

Sergio.D.Suárez
Mentor
Mentor

I already told you the other time that you were a genius   Smiley LOL, I in VBA activating and deactivating again and again !!!! Thank you very much @bradeneuropeArthur  !!!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 5 of 6

bradeneuropeArthur
Mentor
Mentor

@Sergio.D.Suárez 

 

With pleasure...

Your thanks are appreciated very much.

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 6 of 6

philip1009
Advisor
Advisor

ThisDoc.Document is the recommended callout for the document object, but it's all dependant on the context.  ThisDoc.Document refers to the document that the rule is called from, if you have Assembly1 and Assembly2 open, have Assembly2 as the active document and running the rule from Assembly1, ThisDoc.Document refers to Assembly1.

 

In the same situation if you're running the rule from Assembly1 but have Assembly2 active, ThisApplication.ActiveDocument will refer to Assembly2.

 

The last one to consider is ThisApplication.ActiveEditDocument, this is used for editing a sub-assembly in an active assembly, ActiveDocument will refer to the top-layer assembly, ActiveEditDocument refers to the current sub-assembly/part document that's being edited.

 

Also, you don't have to be specific with Component Definitions, Dimming as ComponentDefinition will work for all variations in the context of the document object it's called from.

0 Likes