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
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
(Not an Autodesk Employee)
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.
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
(Not an Autodesk Employee)
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.
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
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.