ThisDoc.Document vs ThisApplication.ActiveDocument

ThisDoc.Document vs ThisApplication.ActiveDocument

utm007
Participant Participant
4,584 Views
7 Replies
Message 1 of 8

ThisDoc.Document vs ThisApplication.ActiveDocument

utm007
Participant
Participant

Hi to all,

I've tried the following code to see the differences, but Set Doc=ThisDoc.Document give run time error 404 no object, while the second one is correct.

What's wrong in my usage of ThisDoc?

Sub example()

Dim oDoc As Document, Doc As Document

Set oDoc = ThisApplication.ActiveDocument
Set Doc = ThisDoc.Document

MsgBox oDoc.DocumentType + "ThisApplication example"
MsgBox Doc.DocumentType  + "ThisDoc example"

End Sub

 

0 Likes
Accepted solutions (1)
4,585 Views
7 Replies
Replies (7)
Message 2 of 8

A.Acheson
Mentor
Mentor

ThisDoc.Document is an ilogic function only with link to API help here.

 

ThisDoc refers to the document in which the rule is written. For more information API help is here

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 8

Curtis_Waguespack
Consultant
Consultant

Hi @utm007 

 

Imagine you have a part file in an assembly and that part file has a rule in it that sets the description iProperty. And that part rule gets triggered when a parameter named Length is updated.

 

Now imagine also that the assembly has a rule that sets the Length in that part.

 

If your part rule uses ThisDoc.Document then when the rule triggers, then the rule is looking at the part document. 

 

But if the part rule is using ThisApplication.ActiveDocument then it will be looking at the assembly, because that is in fact the active document.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 4 of 8

WCrihfield
Mentor
Mentor
Accepted solution

What a coincidence.  I actually wrote a contribution post about this exact topic a year or so ago.  Maybe reading through that will help out some too.

ThisApplication.ActiveDocument vs ThisDoc.Document (Document References Explained In More Detail) 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8

WCrihfield
Mentor
Mentor

Also, just to add to what @A.Acheson said earlier, it's a little hard to tell if you are trying to write that code for an iLogic rule or for a VBA macro, but I would guess that is is for a VBA macro, due to your use of the keyword 'Set' before the two lines of code.  That 'Set' term is not really used in iLogic.  And as he mentioned, that term 'ThisDoc' is only defined within the iLogic add-in, so it will not be recognized within a VBA macro.  That may be why that one is not working as expected in that situation.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 8

utm007
Participant
Participant

Thanks Curtis,

I've written this example because I'd like to acces the ipt  selected within an assembly.

I'm writting it in VBA.

 

With iLogic and ThisDoc.Document it works, as you've correctly written before.

With VBA and ThisApplicatio.ActiveDocument I can acces only the assembly and not the ipt in the assembly.

 

Now, how can I write something like ThisDoc.Document in VBA that runs like ThisDoc.Document in iLogic ? And before do it. Is it possible?

 

I'm trying to read something about the links you've given me.

 

Thanks.

0 Likes
Message 7 of 8

utm007
Participant
Participant

Yes, in VBA.

Thanks

0 Likes
Message 8 of 8

utm007
Participant
Participant

Oh, great!!!!

I've read the doc, and the solution should be:

[...]

The term 'ThisApplication.ActiveEditDocument' seems to have been created for the specific scenario of when you are working within an assembly document, so that the assembly is the 'active' document, but you have entered into the Edit Mode for one its components, so that all the other components are greyed out, and you want to refer to that component document which you are actively in-place editing. Although it was created with that specific scenario in mind, it can also be used in other situations too, and will then return the active document, and is not document type specific

[...]

 

I'm trying and let you know!!!

 

Thanks

0 Likes