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: 

Pushing rules from ipt to iam

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
SpokenEarth
265 Views, 4 Replies

Pushing rules from ipt to iam

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

4 REPLIES 4
Message 2 of 5
WCrihfield
in reply to: SpokenEarth

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:

  • How do you intend for the code to know which document to get the original rules from?
  • How do you intend to specify which other document that those rules should be copied into?
    • There are lots of possibilities for those first two.
  • Do you need for the original rules to be deleted after they are copied, or should they be left alone in the source document?
  • Do you want the rules to be ran on the destination document immediately after they are copied into it, or just copied into it, without running them.
    • And if they should be ran, then how would you specify in what order they should be ran.

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

EESignature

(Not an Autodesk Employee)

Message 3 of 5
SpokenEarth
in reply to: WCrihfield

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

3.JPG

1.JPG

2.JPG

   

.

Message 4 of 5
WCrihfield
in reply to: SpokenEarth

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.

WCrihfield_0-1715618927749.png

WCrihfield_1-1715619003859.png

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)

  • The code can contain the full path & file name of both files.
  • The code can contain try to use the currently 'active' document as the 'source' file, then the code can contain the full path & file name of the destination file.
  • The code can contain try to use the currently 'active' document as the 'destination' file, then the code can contain the full path & file name of the source file.
  • The code can contain a routine that will show you a file dialog, which would allow you to browse for either the source file, the destination file, or both.
  • If the code will always be started while an assembly is active (never while a part or drawing is active), then we could include code for allowing assembly component selection.  Then some more code could extract what document that assembly component is referencing, and use that as either the source file or destination file, but it would have to be specified which is source, and which is destination.

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

EESignature

(Not an Autodesk Employee)

Message 5 of 5
WCrihfield
in reply to: WCrihfield

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

EESignature

(Not an Autodesk Employee)

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

Post to forums  

Autodesk Design & Make Report