You should be able to open a file invisibly by changing this :
ThisApplication.Documents.Open(docFile.FullFileName, True)
To This :
ThisApplication.Documents.Open(docFile.FullFileName, False)
Because of this reason (taken from the API documentation) :
OpenVisible - Optional input Boolean that specifies whether to open the document as visible.
-- You actually seem to have a comment inside of your code that states the above
😉 you wouldn't know anything about that now would you
🙂 🙂 ?
----
Moving on to your other questions, you can do what you're talking about, but I wonder if just creating an external rule wouldn't be a more simple solution.
The sample below is of a rule that is placed inside of your main assembly. The external rule that you will create will be listed below that.
Assembly Rule :::
''' We need to tell this rule that we'll be referencing
''' something from a file outside of this rule.
''' In this instance, that file is an External Rule named
''' ExternalRuleTest2.iLogicVb
AddVbFile "ExternalRuleTest2.iLogicVb"
''' Before we start creating Objects, let's make sure that the user
''' has an Assembly Document open and active!
If Not ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then
Return
End If
''' Now that we know we're inside of an Assembly Document
''' we can outright declare an AssemblyDocument Object,
''' and set said object to the Active Document.
Dim aDoc As AssemblyDocument
aDoc = ThisApplication.ActiveDocument
''' Now let's make an empty Document Object named iDoc
Dim iDoc As Document
''' This should be familiar teritory for you.
''' We just want to loop through all of the referenced
''' documents found inside of our currently active assembly
For Each iDoc In aDoc.AllReferencedDocuments
''' Let's check to see what sort of SubType our document is.
''' SubTypes are pre-defined, and so we know that the SheetMetal
''' subtype will return a GUID of -----
''' "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
''' Using this knowledge, we can check beforehand what sort
''' of SubType our document is. Based on that, we can do some
''' conditional work.
If iDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
''' If the SubType is SheetMetal then we can call out this
''' Public Function (called - ShowDocType) from our
''' External Rule (which we pointed to at the beginning of
''' this rule.
ShowDocType(iDoc)
End If
Next
I've added comment code here so that when you copy / paste this into Inventor, it should come out all pretty like.
Basically this is just iterating through the Referenced Documents, and sending off the documents that are for certain Sheet Metal parts off to the external rule for some additional work.
The External Rule is as follows :::
''' let's make this all rather public.
Public Module ExternalRuleTest2
''' We're going to need a means of processing our incoming
''' Inventor Document, so here I've made a public Function.
''' In this case, our Function is named 'ShowDocType'
''' which you should remember from the Rule used inside of
''' of the Assembly.
''' This Function requires 1 parameter, in this case, an
''' Inventor Document. 'oDoc' is the name given to that
''' object.
''' Though near the end, you see that it returns a String
''' I have not included anything to give a value
''' to that String, as I have no need to send information back
''' to the main Assembly rule (for this example at least).
Public Function ShowDocType(oDoc As Inventor.Document) As String
''' inside of here, we're just going to do some real simple
''' queries of this document. Nothing is being written as of yet
''' but we certainly could if we wanted to.
MsgBox(oDoc.DocumentType.ToString() & " --- " & oDoc.SubType)
''' Try writing out some changes to the document here!
''' Remember to check and see if the file is writable beforehand!
End Function
End Module
Remember that when working with External rules that will be accessed for their delicious Public Functions, you should go to the Options located in the External Rule, and check the 'Straight VB Only' button.
Instead of having to worry about placing a rule inside of a file if it isn't there, you can just keep your one external rule up to date, and have it do the work. Also because you can filter out what gets passed to the external rule, you can make sure that only the select type of files that you want to be processed, get processed.
If you have any questions further about applying this method to your workflow, feel free to ask!!!
The more water the higher the boat!
If my solution worked or helped you out, please don't forget to hit the kudos button 🙂iLogicCode Injector:
goo.gl/uTT1IB