Limiting Visible.Documents to open IDW files

Limiting Visible.Documents to open IDW files

cadman777
Advisor Advisor
993 Views
10 Replies
Message 1 of 11

Limiting Visible.Documents to open IDW files

cadman777
Advisor
Advisor

Here I am back again, stuck on lack of information.

Maybe someone can direct me to the rabbithole that shows me what calls I can make to limit "Visible.Documents" to only open IDW files and not try to any open IAM or IPT files.

Here's the scenario:

I have a pile of IDW files open along with an assembly and some parts.

I'm running a rule that will only process IDW files, so when it tries to open an IAM or IPT file, it opens a DB with an error.

I want to prevent that error from poping up so the rule can continue processing files that are only IDWs.

I tried 'error handling' but to no avail.

So now I'm trying an 'If/Then/End If' statment.

But I can't figure out how to reach into 'VISIBLE.DOCUMENTS' to tell it to skip non-IDW files, or to only process IDW files.

Anyone in here able to direct me to some reading on what applies to 'Visible.Documents'?
Here's the code in question (don't recall where I picked it up, but it works very well):

 

 

' This rule runs the below rule on all open parts
Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns = ThisApplication.ApplicationAddIns
Dim iLogicAuto
For Each addIn In addIns
    If InStr(addIn.DisplayName, "iLogic") > 0 Then
        iLogicAuto = addIn.Automation
        Exit For
    End If
Next
For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
    oDoc.Activate()
	   	iLogicAuto.RunExternalRule(oDoc, "rule_filename")
Next

'This is what I tried but failed:
'For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
'	If oDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name").Value = "Sheet Metal"  Then
'    	oDoc.Activate() 'This is the added code that doesn't work
'		iLogicAuto.RunExternalRule(oDoc, "rule_filename")
'	End If
'Next

 

 

 

 

 

Thanx...

 

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Accepted solutions (2)
994 Views
10 Replies
Replies (10)
Message 2 of 11

WCrihfield
Mentor
Mentor
Accepted solution

Just add a document type filter in there like this:

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Continue For
	oDoc.Activate()
	iLogicAuto.RunExternalRule(oDoc, "rule_filename")
Next

That way, if the document is not a DrawingDocument, it will immediately skip to the next oDoc in the collection.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 11

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @cadman777 

 

In addition to the previous reply, you can use something like the example below to process only drawing files. 

 

Just as a general side note, I can tell you're struggling to understand how others are able to find their way around and you are not... and I think it might help to understand that the newer versions of Inventor have improved iLogic authoring tools that helps us navigate the API as we type.

 

Unfortunately, since you're still on a much older version still ( I think ), you must dig through the API help and find these things on your own which can be difficult ( many of us did it that way for years also). 

 

I know this isn't much help, but maybe it will provide some understanding of why it seems easier for others.

 

Curtis_W_0-1639160548410.png

 

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

 

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox(oDoc.FullFileName,,"iLogic")
	End If
Next

 

EESignature

0 Likes
Message 4 of 11

cadman777
Advisor
Advisor

@WCrihfield & @Curtis_Waguespack,

Excellent!

Now please tell me how you knew to use that line of code and not the line I used?

Don't they all look for a file type?

 

@Curtis_Waguespack,

Precisely!

I'm permanently offline, so I have to access the Help system from a separate computer that's online.

Also, I'm working on an old version of Inventor, which means I have to massage every snippet I get from here to make it work. One example is use of the VB Dictionary function. It won't work in 2010, so I have to use an Array and then use a round about method to sort it. But that still has problems b/c I'm 'green'. But the help in here goes a LONG way towards keeping my head above water.

 

Gentlemen, your expertise is appreciated!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 5 of 11

WCrihfield
Mentor
Mentor

Just throwing another 'bone' out there, in case file extension is important, since a file extension is used in the title of the post.  In stead of, or in addition to checking DocumentType, you could also check the file's extension without 'too much' trouble.  Here is one way to do that.

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	'check file extension for ".idw" (or .dwg)
	'I use Try...Catch, because if an open document has not been saved yet, it won't have a 'FullFileName'.
	Try
		If System.IO.Path.GetExtension(oDoc.FullFileName) <> ".idw" Then Continue For
	Catch
	End Try
	oDoc.Activate()
	iLogicAuto.RunExternalRule(oDoc, "rule_filename")
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 11

cadman777
Advisor
Advisor

Thanx for the 'added value'!

 

The only thing about all this is, I didn't save any of the IDW files, so they technically don't have a file extension.

I don't know if you recall, but I asked in another post how to make and process IDW's without opening them.

But since that appeared to be tied strictly to the API and Apprentice, I figrued it was well above my pay-grade, so I opted to go this route instead.

 

So far I'm gaining on it thanx to your help and that of the other kind experts in here!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 7 of 11

cadman777
Advisor
Advisor

Hey Curtis,

I have one question about your code.

Considering this line:

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments

How would I know to use the Method "DocumentTypeEnum" in the below code if I never knew it before?

If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then

In other words, when I see "VisibleDocuments", where would I look to find the Methods and Properties that would clue me in that I needed to choose "DocumentType" and then "DocumentTypeEnum" to accomplish my objective? Where is the MAP that shows me all the Methods and Properties I can use with "VisibleDocuments" to do FILTERING?  This is where I get stuck every time when trying to construct a rule. Another example is this: How am I supposed to know to use "VisibleDocuments" instead of something else (like "OpenDocuments")? Are there other ways to do this? I don't know. Where can I find the ways to do this in TOPICAL format?

 

Here is an example of what I tried with this inquiry. I opened Inventor's VBA environment, pressed F2 and typed into the Search box "visibledocuments" and got this: 

cadman777_0-1639320589549.png

Then I clicked on "DocumentsEnumerator" in the bottom description and got this:

cadman777_1-1639320624710.png

Then I clicked on Type, and then on "ObjectTypeEnum" in the bottom description and got this:

cadman777_2-1639320669750.png

I searched the entire list(!) and didn't find ANYTHING related to a Drawing DOCUMENT. You can see that "kDrawingDocumentObject" is nowhere to be found in that list.

 

So I ask you: How am I supposed to track down the Methods and Properties for this when they don't appear in the MAP that Autodesk has provided in it's VBA environment? Let me say it this way: AS A LINEAR THINKER, how am I supposed to approach this work from LINEAR LEARNING?

 

So I start w/the tools Inventor provides (the VBA environment) and also my objective. I know I want to filter out all kinds of documents but Drawing documents. So where do I begin to find the right code to do that? Where is the TOPICAL INDEX that I can consult to find ALL BASIC FILTERING METHODS? Let me give you a hypothetical example:

 

Suppose you start out knowing nothing but your objective that you want to achieve. You do not have a forum where you can go to consult with experts in the field. You do not know any experts or can't get any help from others. Then where do you start looking for the code words that match the topic you want to code and the syntax you need to do that? This is where I get stuck every time. I don't know where to START writing my code, and I don't know how to look up what I need to know, b/c there's so many different code words that seem to say what I want to do. And the help doesn't go into the details on what those code words each are intended to accomplish nor examples on how to use them. I think part of my problem is I don't do well at THINKING BACKWARDS. It seems that you have to think backwards to construct code. It seems like the same as filing a law suit. You have to think backwards, which is the opposite of linear thinking.

 

Until I get an answer to this inquiry, which I've asked many times in here, I'll NEVER be able to do this myself, and will be forever dependent on everybody else's code and help, which I will eventually abandon doing. Occasional help is fine, but total dependence is not.

 

Thanx for the help!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 8 of 11

A.Acheson
Mentor
Mentor

I think you may have looked in the wrong location. Required was the DocumentTypeEnum class.

AAcheson_0-1639338432401.png

 

And from the API help search documents, properties -DocumentType, click to documentTypeEnum

AAcheson_1-1639338672779.png

 

AAcheson_2-1639338794424.png

Or alternately in API Help API Navigate through fly out tabs  >Reference Manual>Enums>DocumentTypeEnumsEnums.

This document type method doesn;t have a physical smaple in the help docuemnt so it isn't that clear on how to use it. But for these workflow gaps looking to the  forum to produce a sample helps a lot then you can backtrack and find the path used. 

 

Here is a link to API Object Model. However I am not sure why it is not listed under documents.

https://knowledge.autodesk.com/search-result/caas/simplecontent/content/autodesk-C2-AE-inventor-C2-A...

 

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

cadman777
Advisor
Advisor

Hi Alan,

Thanx for the guidance. It helps a little, but not enough.

I see what you did, but that would not have occurred to me.

When you go backwards you have to know how far back to go.

So why did you start with 'Documents' instead of 'Drawings'?

I want to filter Drawings, not general Documents.

See what I mean?

Doesn't make sense.

 

Anyway, let me explain how I go about it and see if you can identify where I'm making my mistake/s.

Let's start from the very beginning using the ObjectModel (OM).

1. I want to filter out every kind of document but Drawings (idw).

2. So I look at the yellow part of the OM (Drawings) and don't see anything that can help me.

3. So then I go up one level and look till I find what looks relevant, the white part of the OM (Documents):

     Document>DocumentDescriptorsEnumerator>DocumentDescriptor.

4. That's the end of the line so I then open the VBA editor and look up DocumentDescriptor.

5. That brings me to a list where I find DrawingDocument (Class).

6. The Members of that Class are many, so I scroll through them and find Type.

7. The bottom line description says Property Type as ObjectTypeEnum, so I click on that

8. That brings me to another list of Members, so I scroll through them and do NOT find anything related to DrawingType.

9. At that point I'm stuck.

10. Result: What you just told me above makes no sense at all when I follow the rabbithole in the VBA editor.

11. How am I supposed to make the connection to the Method you know you should use and the misleading ObjectBrowser system that is embedded in Inventor VBA that I am navigating? I just want to know how to make the jump from the OM to the ObjectBrowser to writing code that works.

The above is how linear thinkers follow scripts.

Please advise...

 

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 10 of 11

A.Acheson
Mentor
Mentor

In this case for me it was just something I have picked up while search posts. I suppose enough time working with the help documents and having some training in terminology of programming would help also.

Another path is DrawingDocument>DocumentType>DocumentTypeEnum

AAcheson_0-1639345644526.png

or from the API help Drawing Document

AAcheson_1-1639345955098.png

As regards knowing to check the document collection (group of document) called documents. I think this is  

something that has to be picked up.  The object model diagram doesn't have everything  included so the help file is needed. I have just found that the index works well for seeing the hierarchy. 

AAcheson_3-1639348044862.png

 

 

 

 

 

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

cadman777
Advisor
Advisor

OK Alan, this sounds like a good starting point:

"The object model diagram doesn't have everything included so the help file is needed. I have just found that the index works well for seeing the hierarchy."

I'll try this soon as I have some free time, and let you know how it works for me.

I beginning to see that a lot of what I've learned so far came from observation/musing about others code and trial-and-error hacking together others code. Not my favorite way to learn.

Thanx again for the direction!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes