Hi, I have x number of rules on a part and I would like to push them into assembly, can anyone help me with a code?
Thanks
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @SpokenEarth. Do you just need to do this action once, or do you need to do it a bunch of times with different parts? If just once, then you may just be able to do this manually easier than trying to do it by code. We can select, then right-click on an internal iLogic rule within the iLogic rules window of one document, then choose copy, then go to the other document, and paste them into that document's iLogic rules window, manually.
Do you already have some existing code for this task that that is maybe just not working the way you want it to yet, and would like some help with it? If so, please post what you have so far, and we may be able to help you get it working the way you want.
There are also ways to do this type of thing by code, but if doing it by code, there are lots of things that we would need to know about how you would need the code to be laid out. For instance:
There are also multiple working examples of codes for copying internal iLogic rules from one document to another here in this forum already that you may be able to find with a search, but they may not be laid out exactly the way you might need them to be.
Wesley Crihfield
(Not an Autodesk Employee)
How Crihfield. I tried copy and paste it didn't work.
The document (SKELETON.ipt) where the codes are, its a part of the destination document (STORAGE TANK.iam) so they need to be left alone, I need to run the codes individually by choice
.
Hi @SpokenEarth. The manual process may only be available in a newer version of Inventor than you currently have, not sure. But the screen capture images below show how I can do it while using Inventor Pro 2024.
Since your first image shows one of the iLogic ruled from the part being within the assembly, I can only assume that the copy & paste part worked, but it must have tried to run that iLogic rule when you pasted it there, then the rule threw an error, because the rule was expecting to find a part document, but it found an assembly document instead, and could not cast (convert) the one type of document to the other type of document. This is a common error when there is no document type check included at the start of an iLogic rule, and it gets ran while another document type is active. I can only speculate if that is what happened there though.
There is something you must be aware of about document associations and referenced documents. When you are working with an assembly, and have placed some components into it, then we can figure out from the assembly side about what documents the assembly is referencing. Each assembly component will be referencing some other model document that is stored in a file somewhere else in your file system. However, we can not figure out if this assembly we are currently working with may be referenced within any other assemblies (as a sub assembly in them), because nothing gets recorded within this assembly when it gets added as a component into another assembly. There will also not be anything in this assembly telling us if it has a drawing or if it is being referenced within any drawings. The same is true for parts. A part essentially does not know if it is being used within any assemblies, or in any drawings, because nothing gets recorded within that part when it gets used in an assembly or drawing. So, when we are working with a part by code, there is no way for us to know if this part is being referenced by an assembly component within any assemblies, or is being shown within any drawings. Therefore technically, the file on disk for a part is not part of any assembly or drawing. That part file can be referenced by either of them, but there is no way for us to know if it is being referenced by any of them. If you are using Vault (I am not), then you may be able to use Vault's functionality to figure out if a part is being used by any assemblies or drawings that are also within the Vault system, because that is one of its advantages. I would not know how to do that by code though.
So, with that in mind, if I write an iLogic code for copying internal iLogic rules, even if the part were the active document (currently showing on your screen) when you started the rule, we could use that to determine the 'source' document to get the rules from, but I still need a way to specify that you want them to be copied to the assembly. There is no direct step from the active part to the assembly, because there is no link on the part's side to that assembly.
Some options:
(term "source" means the document containing the rules to be copied)
(term "destination" means the document that the rule will be copied into)
I will attach a text file containing some code you can copy and paste into an iLogic rule, and try out for this task, but it is using the option of using a file dialog to have you choose both the source and destination files. I added a lot of comments in there, to help you follow along with what the intent of the code is, and what is going on. And I built a lot of potential feedback in there also, for just in case something goes wrong, or something is not right during this process. But as I said, there are lots of different ways a code like this could be designed and created, depending on a lot of different preferences.
Wesley Crihfield
(Not an Autodesk Employee)
I edited the attached text file in my last response, due to an error in the file type filter line of code within its custom Function, resulting in part files not being selectable in the file dialog.
I should have tested the code before posting it, but did not want to copy any rules from one of my existing documents to another at that time. I now see that there was a slight mistake in the formatting of the 'filter' String, within the 'UseFileDialog' Function. It should have been like this:
"Autodesk Inventor Files (*.iam;*.dwg;*.idw;*.ipt)|*.iam;*.dwg;*.idw;*.ipt|All files (*.*)|*.*"
...or even like this:
oFDlg.Filter = "Autodesk Inventor Files (*.iam;*.dwg;*.idw;*.ipt;*.ipn;*.ide) | *.iam;*.dwg;*.idw;*.ipt;*.ipn;*.ide | All files (*.*)|*.*"
...if we wanted to be super detailed, but this second list includes iFeature files and presentation files, which do not seem appropriate for this specific task, because I do not think they can contain iLogic rules.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.