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: 

Skip invisible documents in reference docs

5 REPLIES 5
Reply
Message 1 of 6
dschulteHR4D5
234 Views, 5 Replies

Skip invisible documents in reference docs

Hello, i have a code i have been using from an assembly, when ran it finds all reference documents within the assembly, finds the IDW of each and prints it, and then finds the IDW of the top level assembly. 

 

I am wondering if there is a simple way to set the visibility to some of the parts so that way when running the code, it will skip printing any invisible components. I have other rules that use this same work flow-set visibility to off, so the rule skips it, but those rules are using component occurences, whereas this one uses reference documents. 

 

Is it possible to change this to run only visible? oAsmDoc.AllReferencedDocuments instead of all?

 

Here is the code

 

 

' This is print all associated idws of an assembly to PDF. This code assumes that the idw for each component is located
' in a DRAWINGS folder in the root workspace folder of the project. Must be run from an assembly, will print top level 
' subassembly And Each Component within the subassembly.
 
'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic"): Exit Sub: End If
 
'Common to all drawings
Dim oWSPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
Dim oDrawingsFolder As String = oWSPath & "\DRAWINGS"
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDrgPrintMgr As DrawingPrintManager
 
'get user input
RUsure = MessageBox.Show ( _
"This will create a print for all of the assembly components that have" _
& vbLf & "associated drawings files. This rule expects that the drawings are stored in a separate DRAWINGS folder within the root workspace folder of the project." _
& vbLf & "" _
& vbLf & "Make sure the file extensions are set to Visible in Windows Explorer." _
& vbLf & "" _
& vbLf & "This could take a while.  Are you sure you want to do this?" _
& vbLf & "" _
& vbLf & "", "iLogic  - Batch Output PDFs ",MessageBoxButtons.YesNo)
 
If RUsure = vbNo Then:Return:Else:End If
 
'- - - - - - - - - - - - -PRINT setup - - - - - - - - - - - -
Dim oPrintMgr As PrintManager = ThisApplication.ActiveDocument.PrintManager
If MsgBox("Using Printer " & oPrintMgr.Printer & ", Letter Size, 1:1 Scale, Landscape Mode." _
& vbLf & " " _
& vbLf & " Do you want to continue?" _
, vbYesNo + vbQuestion, "System Printer Settings ") = vbNo Then: Exit Sub: End If
 
' ----Determine if the prints should be in color or B/W ------
oColorAsBlack="False"
RUsure = MessageBox.Show ( "Do you want to print in COLOR?"& vbLf & "", "Color or B/W Prints",MessageBoxButtons.YesNo)
If RUsure = vbNo Then
oColorAsBlack="True" : Else: End If
 
Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
Dim numFiles As Integer = 0
 
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
For Each oRefDoc As Document In oRefDocs
If oRefDocs.Visible = False Then Continue For
Dim oRefFileName As String = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName)
Dim oRefDrawingFile As String  = oDrawingsFolder & "\" & oRefFileName & ".idw"
If (System.IO.File.Exists(oRefDrawingFile)) Then
    numFiles = numFiles + 1
Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Open(oRefDrawingFile, True)
oDrawDoc.Activate
oDrawDoc.Save
    oDrgPrintMgr = oDrawDoc.PrintManager
    oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack
    oPrintMgr = ThisApplication.ActiveDocument.PrintManager
    oPrintMgr.PrintRange = kPrintAllSheets 'Prints all sheets in the idw.
    oPrintMgr.NumberOfCopies = 1 ' Set to print one copies.
oPrintMgr.PaperSize = kPaperSizeCustom
oPrintMgr.PaperHeight = 27.94 '11.0 in
oPrintMgr.PaperWidth = 21.59 '8.5 in
    oPrintMgr.Scalemode = 13825 'Full Scale print @1:1
    oPrintMgr.SubmitPrint ' Submit the print.
    oDrawDoc.Close (True)
End If     
 Next
 
'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - 
Dim oAssyFileName As String = System.IO.Path.GetFileNameWithoutExtension(oAsmDoc.FullFileName)
Dim oAssyDrawingFile As String  = oDrawingsFolder & "\" & oAssyFileName & ".idw"
 
If (System.IO.File.Exists(oAssyDrawingFile)) Then
    Dim oAsmDrawDoc As DrawingDocument = ThisApplication.Documents.Open(oAssyDrawingFile, True)
    oAsmDrawDoc.Activate
    oDrgPrintMgr = oAsmDrawDoc.PrintManager
    oDrgPrintMgr.AllColorsAsBlack = oColorAsBlack
    oPrintMgr = ThisApplication.ActiveDocument.PrintManager
    oPrintMgr.PrintRange = kPrintAllSheets 'Prints all sheets in the idw.
    oPrintMgr.NumberOfCopies = 1 ' Set to print one copies.
oPrintMgr.PaperSize = kPaperSizeCustom
oPrintMgr.PaperHeight = 27.94 '11.0 in
oPrintMgr.PaperWidth = 21.59 '8.5 in
oPrintMgr.Scalemode = 13825 'Full Scale print @1:1    
    oPrintMgr.SubmitPrint ' Submit the print.
    oAsmDrawDoc.Close (True)
  numFiles = numFiles + 1
Else
      MessageBox.Show (" No IDW of the Top level file found!" _
    & vbLf & " " _
    & vbLf & "There were " & numFiles & " files sent to the printer.", " Job Complete ") 
Return
End If
 
MessageBox.Show ("There were " & numFiles & " files sent to the printer."," Job Complete ")

 

5 REPLIES 5
Message 2 of 6
WCrihfield
in reply to: dschulteHR4D5

Hi @dschulteHR4D5.  That one line could not be modified to only include the visible referenced documents, without making it super complicated.  There are two primary ways to 'filter' for only the referenced documents that are visible though.  The first would be to check of the Document.Views.Count = 0.  If there are no open views of that document, then it is not visible.  The second idea is to check if that document is included in the ThisApplication.Documents.VisibleDocuments collection, and if not, it is not visibly open.  Either of those checks could be used after that point, to filter that aspect.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

Quick question for you Wcrihfield, i just noticed it this morning when i went to use this rule to print as assembly that is mirrored, so there is LH and RH parts, when i made the print packet for the LH assemblies, it also printed off every refenced drawing from the RH part. Makes sense as this rule looks for reference documents, but is there any way to change this behavior without making it look for occurrences in the assembly instead of reference documents? I'm assuming probably not due to the nature of the code but figured i would ask.

Message 4 of 6
WCrihfield
in reply to: dschulteHR4D5

If that referenced document is unique for the mirrored version of the component, and not the same base model file, then there may still be a chance of checking this.  You may be able to use the AssemblyComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc) method, to get a ComponentOccurrencesEnumerator.  And if its Count = 1, that would make it easy to then check that one component within that collection in some way.  But what property to check about that component is also challenging.  Maybe check its constraints.  If you just grounded the mirrored component, instead of mirroring the constraints, then that may not be a lead.  But if you mirrored the constraints, then maybe you can check something about its constraints.  Often when you mirror a component, it will create new custom WorkPlanes.  If you see that the component is constrained to one or more custom WorkPlanes, especially if those WorkPlanes are grounded, that could be an indication that this referenced document, with one component in the assembly, was created as a mirror of another component.  But that is a long code path, and may not be 100% effective in all situations.  Just typing what's going through my head, just in case it might give you some ideas.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 6

So the assembly i am working in right now, I started and finished the RH side, and then mirrored them to the LH. So LH is made from RH. Doing some testing, when running the rule on the LH is when it prints off the RH component also. Say part number xyz-1 RH, if this part is in the assembly i run the rule on, it will only print xyz-1 RH, but if run in an assembly that has only xyz-1 LH, it prints both LH and RH prints. Assuming because the LH is "tied" to the RH being mirrored, but still odd, i didnt think this could be a possibility. 

 

Also, is there a recourse you can recommend that i could learn more of this from, when you post things like "You may be able to use the AssemblyComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc) method, to get a ComponentOccurrencesEnumerator.  And if its Count = 1, that would make it easy to then check that one component within that collection in some way." I have a hard time figuring out how to write this into the current code i have, not being real familiar with what everything it is looking for/needs to make it run correctly. I can look up what it means but i get lost trying to plug it into the code without getting errors everywhere. 

Message 6 of 6
WCrihfield
in reply to: dschulteHR4D5

Sorry.  When I mirror stuff in my assemblies, I almost never actually have it create any new files.  I just have it reuse the current models, then mirror the constraints and sometimes also ground the new components.  And due to how many people I encounter on the forums, it is difficult to determine what level of iLogic/API/coding skill or understanding the other person is currently at.  Plus, the idea I mentioned is somewhat of a stretch, and would be fairly complex to implement, requiring quite a bit of code.

 

That first line of code I mentioned (Link to Method help) is a way to get a reference to all of the components, at all levels of the assembly, that reference the specified input (oRefDoc in that example, which would represent a referenced Document object), and returns a ComponentOccurrencesEnumerator which will contain all of the components if found, if any.  Just a way to bridge the gap between referenced documents and components, for starters.

 

Then, I was just thinking about what I could check about the component that would indicate to me that it was created by mirroring it in that assembly.  So, I started a new assembly, dropped a component into it, then mirrored it, and looked at what was new or different afterwards.  Not much was coming to mind other than the new, grounded/fixed WorkPlanes that it created.  I looked at the constraints that were created on the new component, but these just seemed to be constrained to the new grounded WorkPlanes, not to the other component that it was mirrored from.  I am using 2024 version of Inventor, and I think those relationships have maybe changed some from some of the older versions of Inventor that I have used.  It seems to me like there used to be a better way to determine that a component was created by mirroring it.  I know that usually when you first attempt to mirror a component, it wants to create a new model file for the other, new component it is about to create, and usually wants to put something like "_MIR" at the end of the new file's name, but that can be overridden or changed.  If there was something unique like that in the new file's name, then that would seem like the simplest way to filter out the model from one side versus the other side in situations like that, but I do not know if that is the case for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report