Customizing iLogic: Managing External Rules and Custom Snippets | Autodesk Virtual Academy

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning everybody welcome to another week installment of autodesk virtual academy as presented by katie technologies we got another fan favorite topic for you guys this week we're going to be talking about some eye logic here today on this lovely september morning 9 9 2021 so thanks for being here everybody uh cameron you're on the line with us cam how you doing good i'm good adam nice cam one of the friendliest most helpful application engineers on the team he's been very busy lately so he's been generous enough to lend us some of his time to teach us the audience about some external rules and customizing snippets in high logic which isn't just helpful for simplifying your eye logic but for simplifying and uh streamlining your guys's industrial workflows um as a whole so thanks for being on here cameron how you doing today doing great glad to be here nice right on and so yeah this is a you know ilogic and automation have been a particularly interesting topic for a lot of people i think and so i hope you guys are appreciating the kind of frequency of topics that we have coming up over here but as always you know to zoom webinars let's get into it right zoom webinar uh there's going to be a few stuff on screen right so you have a few buttons like the chat window and the q a section if you want to ask us any questions q a lets us just track questions a bit more efficiently in chat we might be sending links through there so be on the lookout for that stuff as always if there's any issues with video quality or audio just let us know happen to take a moment and fix any of that and if you guys have any feedback any curiosities more questions topic suggestions for the future there will be a survey going out at the end of this presentation as well via email which we do peruse and cry over or rejoice over depending on how friendly you guys are as well as take additional topics for the future um with that said cameron i'll get out of your way man i'll let the subject matter expert get on his way over here man all right let's see what you got man okay thanks adam all right welcome everyone uh like adam said today we're going to be talking more eye logic and talking about how to manage our external rules and custom snippets so first i'll introduce myself and then we'll talk a bit about uh some of the tools that we can use to save you your development time and then uh i'll mention another video that is tangentially related to the topics we're maybe talking about today and then we'll jump right into it switch over to inventor and go through the demonstration and then at the end we'll go have some time for some questions and answers so like adam said if you've got questions uh you don't have to save them for the end you can just throughout the session today just type them into their q a and we'll try to get them to them as best as we can at the end so i'm on kitties automation team where i develop adding applications for inventor primarily my teammates and i write programs that automate the product design process and my current project that i'm working on is an inventor add-in that automatically generates a modular assembly it configures custom bills and materials and generates proposal documentation so that's the kind of stuff that we do so if your company needs to speed up the design process whether in inventor or vault autocad etc please reach out to us here at the tv and find the best way to meet that mean i personally been using inventor for 15 years and have been writing ilogic codes since the capability was first added to inventor about 10 years ago now over the years i've written many eye logic rules and i found that there are many blocks of code that i find myself writing over and over again and there are even entire rules that i end up writing over and over again now my logic rules live inside the document that they are written in but some rules provide functionality that's useful in any document and you might find yourself copying the rule and pasting it into another document so it can be used there but today we are going to check out some tools that will help you to reuse your code custom snippets let you save blocks of code that you use often so you don't need to write them each time external rules make it possible to extend the functionality of an ilogic rule so that you can use it from any document instead of just the document that i've created in and then finally we're going to show you how to take advantage of custom snippets to make it easier to call on your external rules so when when we talk about external rules today i'll be using a bit of code from the last ava session that i did at the end of june uh if you missed that session don't worry you don't need to have seen it first for what we're talking about today but if you want more information about ways to reuse code you can go ahead and check out that video uh on our youtube channel fatigue technologies and the the title of the video is advanced eye logic function subroutines and external rules so it's a good supplemental to what we're talking about today all right all right so let's pop over to inventor and talk some my logic [Music] now switch over to inventor all right so uh for inventor i'm just going to open up our ilogic editor here i'll just quickly add a rule here just to get into our ilogic editor so we can take a look at some things so if you've done any work in eye logic at all then you're familiar with these uh snippets right here which are essentially just little bits of code that are pre-written for you so that you can just quickly write your code by you know selecting something and you double click it and it drops wherever your cursor is it's going to drop in a little bit of code and so all of these snippets here are uh the built-in ones that come with inventor that autodesk has already written up for us and provided them for our use they're very handy i use them all the time um but there are times like i said where you may find yourself writing the same bit of code over and over again and it would be useful it would be nice to be able to just use it like you do these these built-in snippets and so uh inventor has that functionality so that we can do that and it's over here if you've never noticed there's a system tab up here which is what we're seeing here with all the built-in snippets but if we switch over to this custom tab and this is so allows us the ability to save our own snippets so we can use them just like the built-in ones but it's our own custom code so in fact if there's this folder here called my snippets and if you expand that underneath that is there's already some snippets that are provided for us i guess they're quote unquote custom snippets even though they're kind of built in already but these ones actually provide quite a bit of additional functionality that's useful and you can see there's quite a bit of code involved if we hover over this the little tool tip shows us a quick description of you know what the snippet is what it does and the actual it gives us a preview of some of the code so if i if i just insert one of these uh like let's say i don't know html report templates there's quite a bit of code that that writes for you um yeah so there's there's some useful stuff here so but not only does it are these built-in snippets here for us but it also provides us the functionality to save and manage our own library of custom snippets so uh we're going to be talking about that today i want to show you how to create snippets how to manage them where they get stored how all that works and the idea is that when you save a custom snippet it's actually saving that little bit of code into an xml file that's stored on disk somewhere and inventor knows where to look for it and you can see so these built-in ones these are being stored in xml somewhere if you want to see where they're being stored you just go up to this little button here this custom snippets properties if we click on that this is going to show us the file location where it's actually reading these snippets so under program it gets installed within better under program files your inventor version and then this file here ilogic user snippets.xml has all of these snippets are in that one file so uh what we're going to be doing when we create custom snippets is we you can add to this library but i like to just uh start my own just kind of keep it separate from what inventor's doing what it installs because if you ever have to reinstall or upgrade to a new version or something you want to keep your custom snippets separate from the ones that are built into inventor and so i create my own custom snippets file library file xml to get stored so the first thing you want to consider when you're creating any new snippets is you want to decide where you're going to store them where that xml file is going to be saved and it's got to be in a place obviously that you have right access to and you also want to consider if you've got other people on your team that are also developing in ilogic then they might chances are those snippets will be useful for them as well and so you want to consider okay saving in a place where it's accessible to other members of your team so that might be a network folder or if you're using vault you definitely would want to place those in the vault so that other members of your team can get access to those so like i said it gets stored in xml file you could have multiple xml files that have different snippets in them and you can just you know tell which telling vendor which custom snippets file to show here so if you just hit this open pulls up a window you can browse to wherever your snippets xml is going to be like i said if you have multiple then you can just you know switch between them by opening different ones or you can even merge them all into one list here i have never really found a meme to keep multiple snippet xmls i tend to just have one that i manage that has all of my custom snippets in it and find it it's just easier to manage that way but that is an option that's available to you if you want to have multiple snippet xml library files um so let's go ahead and make one now usually so when you when you create a custom snippets file and load it up it's going to show you what's in that snippets file if you haven't um i like to actually just bring these ones along with me so i like i said i just manage one custom snippets file i don't like to have multiples but i also like to have access to these ones that are built in in case they're in case i need them and so i actually just like to bring those over and save these into my new custom snippets file so the way i'll do that is to just start out here i'm just going to use this save as command and that's going to take the the current snippets file that's loaded and i'm going to save it out to a new location so here i'm just going to go browse my folder uh let's go into my ava let's do today's session here and i'll just put it right here and i'll give it a prefix this is going to be my aba i logic user sniff but you can call that whatever you want we'll go and save that there and then that's what gets loaded out as soon as you do that save as that's what gets loaded here you can see if you click on your little properties button again if you show okay now this is the folder that i just chose my aba folder my aba ilogic user snippets.xml so that's what we're using right now and it's got all these uh built-in ones uh brought over to it so let's go ahead and take a look at that folder real quick if i open that up in windows explorer here i browse to my documents ava customizing i logic to a session here and then there's that folder or that file that i just created ava ilogic user snippets now if i open this up like a notepad or something or uh you know an xml viewer or something you can see kind of how that's stored these are all the built-in ones that i've brought over with it if i didn't do that this would have just been you know basically xml without any snippets in it yet but in this case i've got snippets so okay so now we've got our library file that's set up ready to like go ahead and start adding my own custom statements to this um and you can see there's a folder here called my snippets and underneath that are all of the built-in ones you can create additional folders underneath here by just right clicking inside here uh inventory calls and categories but you know they're like folders so you can just insert the category and then uh you can name it whatever you like you can name it your your company name if you want that kind of makes it clear that these are you know snippets that are customized for your company's development environment or you could uh take a lead from the system snippets where they've got them broken out by parameters properties components uh all that kind of stuff i think we kind of organize follow that similar organizational structure that you like i'm just going to go ahead and keep this simple for today and just call it ada and then so now i've got a folder there i'm ready to go i can add a snippet so let's let's figure out what kind of a good snippet would be good for our first one here so uh one that i find that i use a lot like i said i work on the automation team and i develop a lot of automated assembly building assemblies and configuring assemblies and a part of that is something i do very often is i need to control the bomb structure of components in an assembly to set the bomb structure to reference or phantom or something like that and so i found myself writing that little bit of code over and over and over again and it's not a lot of code but um especially when i was just starting out with biologic and learning how to do this stuff i couldn't remember the right magic words to write to set the bond structure and so it was helpful to go ahead and create a snippet for it so that way i could just quickly get access to it and it's sped things up quite a bit so i think that's going to be a good example let's go ahead and write a little bit of code that's going to set the bomb structure and so let's say i need to get access to my component here first component of current so we'll call it bracket occurrence equals component uh inventor component and we give it a give it the browser name say bracket that gets our occurrence and then we need to set the bomb structure and then structure we'll set that equal to and like i said i've done this enough that i know what the right words are now but when i was first starting out i didn't and so i'd have to look this up quite often so it's very useful to have this as a snippet so i didn't have to look it up all the time okay so we're going to set the let's set that to reference instead of default okay reference all right so we're going to set that to reference so that's a little bit of code that we're going to use often so let's go ahead and save it we want to save that as a snippet so the way you do that is you highlight the code that you want to save and then you right click on it and down here you've got an option to capture snippet i'll go ahead and do that and then that's going to pull up this little edit snippet editor dialog where we can set this up so first thing we're going to want to do is set a title now that's going to be the text that shows up over here in the browser and so we want to choose something that is uh succinct but you know can't be very long but it's also needs to be descriptive so people know what it does when they see the title so in this case i'm just going to keep it simple and call it bomb structure to reference and then we can choose what category we want to store it in it defaults to the top one there but i want to store that under my folder ava choose that and then this is the tool tip here you can um just write whatever you want in there you can use the code as a tooltip and that just like takes whatever your code is down here and puts it up in the tooltip i don't usually like to do that that's not very helpful because you can see the code anyway when you hover over the tooltip it shows you that tooltip and then underneath that a preview of the code um so i like to actually put some useful information here but we'll come back to that in a second the first thing that i like to do here is make sure that my code is going to be good for a snippet and what i mean by that is um right now this is written with a bracket in mind and so that works for this particular situation that i'm using it in right now for this bracket file but you know next time i use this snippet might be for a completely different document it has nothing to do with brackets and so it would not it might be confusing to the user to have that in there so this is something they're going to have to change every time they use this snippet they're going to have to give it the name of the occurrence that they're trying to set the bond structure for and so we want to make this more generic and also indicate to the developer that when they use the snippet this is something they're going to have to change every time and so we can put something in like uh my component name here something like that that way when the developer inserts the snippet they can see okay that's that should stand out as something that they need to change every time they use this and because that's something they need to change every time i like to be able to just instead of like highlighting this slowly by you know they need to cover this whole thing highlight this whole thing and then start typing what they want i like to be able to just double click to quickly highlight things but if i use spaces here it sees those as separate words and then i can't just quickly select the whole thing i mean you can still kind of drag and do stuff but what i like to do instead of spaces is put underscores here that way i can it's it sees it as all one word so when i double click it just highlights the whole thing that i can just type my actual component so that's just a little quality of life thing that makes these snippets much more convenient to use for your developers so keep that in mind um also let's see the second line is not anything that really needs to change there but i still it's not very generic still like i've named this variable bracket occurrence which again is fine for this particular situation but it's not going to be fine for other situations and so we might want to genericize that a little bit so that it's just it's not confusing down the road so uh we could just like i said make this little more generic and say maybe comp currents but then we've also got to make sure we name that here as well and this is all stuff you could do so you could just set it up this way from the beginning out here in the editor um but i just wanted to show you that you can do that kind of stuff in here as well so we've got compoc my component name here and then we're getting the compound and sending its bomb structure to reference so there we go uh another thing you might want to consider in here is adding comments that explain what different parts of your code are doing it's not necessary um and i wouldn't go overboard with it because again you this is something you might use many many times throughout a piece of code and so every time you insert the snippet it's going to enter insert those comments so just keep that in mind but we might want to maybe explain what this is doing here like get the component for ins for that one and then here maybe you know set structure to reference um this one you know we could probably leave that one out that's probably because it's pretty clear with from that line what it's doing there so we could probably leave that one out just to kind of compact make our code more compact since we're not inserting that extra lines every time we use this so there we go um that's good for our snipping and last thing we want to do is set up our tool tip and this is the place you want to uh explain what the snippet does any modifications that the the developer is going to need to make when they use the snippet like for example changing the name of the component here that's something they're going to have to change every time so we want to make note of that in the tooltip um we want to make note of any prerequisites like one of the snippets we'll do later is going to require an external rule to exist so we'll want to make sure we know that and any other relevant info you want to put up here so let's go ahead and just write our tool tip here and we'll just say that we're going to explain what it does it sets a component currencies bomb structure reference and then i want to add some additional lines but if i hit enter here like to you know go to the next line it's not actually going to do that it's going to just hit okay like that and then it actually saves it out um if you accidentally do that it's fine you just right click here and go back into edit and it'll pull that back up but if you want to go to the next line you have to hit hold down control and then hit enter and then that will give you a line return and then let's see we're gonna we need to tell the user that they've gotta make some modifications to the snippety 10 they use it so we'll say replace uh my oh i'm just going to copy and paste that paste and you'll see it's starting it copied the formatting the green color up here that's that's fine you'll see that it doesn't actually remember that don't worry about it so that's our tooltip go ahead and hit okay so now when we hover over that you'll see over the top in bold is the tool tip and then down below is a preview of the code in this case it's photoshop so it's just the whole thing of what is actually inserted when you hit the snippet and then just to show you i'm going to go back in and edit that you'll see that green text doesn't get saved it's just just a weird little quirk of the copy and paste there all right so there's our snippet so anytime we want to use that we just double click and it reflects that little bit of code in there for us and we just have to remember to change the name of our component here and then we're good to go and then if we wanted you know write one that was similar for setting it back to default then we can just you know modify this highlight that capture the snippet copy and paste the tooltip and change what we need once once you get started it's super easy to create custom snippets so one important thing after you do that remember to save you have to actually hit the save button to save the changes you've made to your custom snippets library xml file uh if you if you cancel out or close out of this editor without saving it's not gonna save the any custom snippets you've edited or added new so you've got to make sure you hit that save and that it actually um will work here so now if i cancel here i actually don't want to run this rule it wouldn't even work in the context of a part file anyway it's a more of an assembly thing there but if we go back into the editor then we'll see and go over our custom snippets there's our aba folder and there's our custom snippet there okay all right so yeah okay we got a question over here too and so just to clarify on the cu you kind of you change that string for my component name here to make it kind of generalized for future components right yeah do you do you need to do the same with comp occ as well the variable name at the beginning no you don't have to that's just a variable name that would have worked just fine if i left it as bracket occ but uh i wanted to make it more generic because again like i said you you're the situation you're going to use this in down the road will probably have nothing to do with the bracket and so that wording will just end up being confusing even though it would actually work and the code would run just fine it's going to be confusing to the reader you know anyone who's reading that code later down the road so that's that's the reason i made it that makes a lot of sense right yeah because the variable name doesn't refer to a specific instance in the assembly that's only the string in that actual function there so right thanks okay hope that answers your question scott let me know okay so let's uh let's talk about external rules for a minute we're going to come back to do some more custom snippets later after we talk about external rules because uh we're gonna talk about how we can use the two together so um so external rules like i said are rules that live outside of any inventor document so normally when you create a an ielogic rule it's going to be saved in the actual document that you've written the rule in so like these two i've got a size rule and a description will they live inside of this bracket document if i open up another document i'm not going to have access to those and so if i've got a rule that is useful that can be useful in more than one place then i will want to save that rule as an external rule that gives me the option of being able to see that rule from any other document um so the way it works is when you create an external rule it's actually saving it as a separate file on disk somewhere and so when you build up a library of external rules you've just got a bunch of little files that represent each of those rules they have the text of those rules in them and the first thing we want to do when we're setting up external rules is we have to tell inventor where to look so it knows where to find those external rules because if we just go on my logic browser here and switch right over here to external rules there's nothing there because i haven't told inventor where it can find any external rules so we have to tell it to do that so uh there we go all right so the way we do that is we go to the tools tab in inventor we go to this options panel and there's a drop down here on the label if you click on that and you'll see there's this ilogic configuration button there we want to hit that and this is just a setup thing you'll want to do just one time only just set up inventor unless you reinstall or you know update to another version you don't have to do this again but we want to go to this advanced ilogic configuration and this this top section here is telling us uh where inventor what folders inventors should look in to find external rules and it can be more than one folder so when you add a folder here let's go and add one i just hit the plus button and then go browse let's see i actually want to go to documents ava customizing so i've already got a folder that i've set up called external rules if i select on that and that's going to add that to the list of external rule directory so now that i've added that folder called external rules what's going to show up over here when i hit ok is there's going to be a folder there called external rules and any external rule files that are stored in there are going to be listed underneath that folder now if you want more than one folder you can just add additional folders here um i tend to kind of keep them all kind of close together so one folder that has all my external rules in it but there'll be some folders underneath that that actually help me to organize all of my external rules and i definitely encourage you to do that if you you know if you're organizing your rules by type whether it's you know working with part documents or assembly documents or drawing you know rules for drawings um or you could do something more generic like for just automating models versus drawings or you know the sky's the limit you can organize it however you like but it's definitely nice to have multiple folders that you can and they'll just show up as multiple folders listed over here on the browser okay now in this case today if we're just neither one so i'll just use that one extra rules folder the next thing we want to look at in here is this default extension for external rule files so when you store an external rule file it's going it can be either an ilogic vb file a text file or a vp file those are the three different types that inventor will recognize as external rules and you can save any and all types you can mix and match computer doesn't really care just the default here is if when you're creating a new external rule which we'll do in a minute um if you don't specify the file extension when you create it it's just going to use what you've got set up here is the default so that's all that's doing here but you can certainly save it as any type at any time i like to use txt just because it's you can open it up in notepad and just quickly see the contents of an external if you need to i've never really had a need for either of these other types there may be advantages to them or disadvantages i i've never really needed anything other than txt for my external rules so that's typically what i use but uh that's completely up to you so go ahead and hit okay so that's all we need to set up for external rules today so now we've added this external rules folder and i've actually already got an external rule in there so let me open up that folder so you can see if i go into external rules i've already got one that's in here but we'll talk about in a minute so that shows up as a list under external rules right here and we'll talk about that one we'll come back to that one first uh i want to uh talk about how to add uh add create new rules and add rules so you if you right click under like here you can create a new external rule you can also just right click here and add external rules which is like if there's an existing file that you want to add you can browse to it and it'll add it to the list and i think it actually copies it over into the folder but in this case we're just going to we're going to right click we're going to say create a new external rule and that's going to open up well first it's going to ask us what we want to call it the file name so we want to make sure we're in the right folder here which we are and then this one we'll just call it hello world and if i don't i can say txt or dot vb and it'll just make whatever i want if i don't specify then it's going to use the default that i chose in the options so for my case that'll be a text file and then hit save i had another question here cam and so when you're setting the directories for the external rules and stuff are you setting just like the top level folder or can you have like nested folders under the explicit directories there and will it still pick up those rules and subfolders that's a good question i don't know if let's find out um [Music] let's go back in here and let's let's remove that one and instead we'll add just the higher level folder above that and we'll see yeah if it picks up everything beneath it yeah let's let's try that yeah uh sure does all right so there you go that's another option to help you organize stuff great great question all right i'm going to switch that back just to simplify things here that [Music] one folder okay there we go all right so you can see uh it's an empty rule for now we haven't added anything to it but it's there because when we actually hit save it actually save the txt file so if i go over to my windows explorer you'll see now there's a hello world text document in there nothing in it yet but we're gonna let's go ahead and open up that and let's add some stuff to it we'll just do something real simple here we'll say this doc meaning stream get the display name and then this document and then we'll concatenate that with just some text here and then we'll go back to our built-in snippets and go to our message box and show then we'll take our message text and we'll have it display the message text instead of just the word message and then this will be our title all right so there's our external rules we're going to save that and run we'll see how that does okay so this this file is called custom bracket and it says hello so now this is an external rule so if i actually open up let's start a new part document and go over to our ilogic tab go to external rules so there we go so we created a rule that's now available from any document if we just run it straight from here because i've set it up to you know work with to just read the document name at the time it runs then it's going to say okay this is part two it says hello there we go there's our first external rule now let's do something a little more complicated an external rule that we need to send the information to and get information back from and this this ties into that other aba session that i mentioned at the beginning today uh the the session that i did back in june where we talked about function of routines and external rules and and we talked briefly about how to pass information data from one rule into another rule from from a rule in this document into an external rule and how to get information back so we're going to be doing that sort of thing today in fact we're going to be using the rule that we created in that session so this may look familiar if you saw that session if not don't worry about it i'll just give you a quick summary of what's happening here the idea is we have we want to be able to take a decimal value like you know 1.79 and we want to round it to the nearest fraction of an inch and then return that rounded value but not as a decimal but as a mixed fraction string so for example 1.79 is gonna get rounded to let's say the nearest quarter inch that'll be 1.75 and then we convert that into an actual fraction which is one so instead of sending 1.75 back it'll actually send one and three quarters one space three slash four right so that's what this rule here is doing it's doing all that conversion and rounding and all that stuff and then we pass the value back as a mismix fraction and the way that we are passing values um so the idea is here like in this bracket document i've got some parameters already set up like a thickness and a length in the z direction the length in the x direction that i want to be able to do this conversion on and get a string value back so i could inside of my i logic rule where i'm instead of you know run the the decimal value that i'm going to round i could just put in a parameter for length z or length x or thickness and then have it use that and that would work fine for this particular document but again we want this functionality to be useful this is useful in any type of inventory document so we want to make this as an external rule and so when we are running it in another part file or something there's not necessary there's no guarantee that there's going to be a thickness parameter or a length of x parameter so we can't just put that parameter inside this external rule because when it runs in another document in the future if that parameter doesn't exist it's going to fail because it's going to try and look for it and not find it so we have to think a little bit differently when we're running external rules we have to think okay when this rule runs in a different context from another document is it going to work correctly what kind of information do we need to have so the in this case the decimal value is something we're going to need the round increment is something we're going to need and so we have to send that value from another rule to this and the way we're going to do that is with this thing called a shared variable which is just a an ilogic snippet you can find in the the built-in snippets go over to system and go down to variables there's uh different options here we're looking at this shared variable here so um when we use that command that shared variable it's uh when we use it on one side it's going to create the shared variable and store a value into it and that just stores it in the inventor environment in memory so that when we run another rule later we can just say okay check for a shared variable called decimal value and if it exists get the value from it and store it here into this local decimal value that we're going to use down here and do some math with so that's what we're doing here we're just giving access to that shared variable that has to exist but we'll take care of that in our ilogic rule that exists inside this bracket part i'll show you that later but just this is how it's going to work um when we write this external rule we're going to assume that that shared variable exists and we're going to get its value now if you wanted to be more robust and not have errors being thrown up if that shared variable hasn't been created properly you could add in some additional code here for error checking just to check like this right here this shared variable exists you can do a check first like an if statement says okay if shared variable exists then go ahead and do all this stuff if it doesn't exist then maybe you display a message box to the user that says hey uh i was looking for this variable couldn't find it please fix that so um but we're going to keep it simple today we're just going to assume that shared variable exists we're going to grab its value and another shared variable for the rounding permit we're going to grab its value we're going to do some math and some string manipulation get our mixed fraction and now we need to be able to send the mixed fraction back to whatever rule or document is going to be running this external rule and so again we're going to take advantage of shared variables so we're going to just in this case you'll see that the order is reversed instead of up here we're actually finding the shared variable with that name and getting its value and storing it locally down here we've reversed and so now we're saying shared variable what we're in this case what we're doing is we're actually creating the shared variable names mixed fraction and storing the value that we've calculated up here into that shared variable so that we can then access it from another rule which i think will make sense as as we go on i'll show you how that works all that gets set up so but the idea is here to set this this rule up so that we can uh run this as an external rule from any document that we want to okay so this rule's already all set up all we need to do is now we want to call it from this particular document this uh bracket document so i've already got a description rule that i've started the setup here and we're going to expand on that and actually make it work so let's go ahead and take a look at this and what we want to do here is i want to actually take the take the length z length x and the thickness and convert those to mixed fractions so i can put them in a description stream for the the i property description so if we i'm going to close out of this for now we're going to go into our eye properties just so you can see what i'm talking about and this description property right now is empty we're going to write a string that actually tells us you know the width by the length by the thickness and all using fractional values so that's the purpose of this description rule right here and so we we want to get the thickness we want to round it the length z and the length x around those and we're going to concatenate those into a description string here so we want to use our external rule that does this whole rounding and converging to a mixed fraction for us so let's go ahead and write that and what that's going to look like is first uh we need to create those shared variables that we have to pass information to so we're going to create shared variables and the way that works is we just use our built-in snippet over here for shared variable and then we have to tell it what the name of the shared variable that we're trying to create and this has to match exactly what the external rule is expecting to find so if we switch back over that just to check real quick that's the wrong one decimal inches so here's what we want we want decimal value and we also want to create one called round increment and those names have to match exactly because this is what it's going to look for if it doesn't find it it's going to fail so let's go back to our description rule and then this is going to be decimal value and then we have to set what the value of that shared variable is going to be so in this case we're looking for the thickness so i'm going to go grab the value from the actual thickness parameter and drop that in there and now we're going to write another shared variable and this one's going to be for the round increment and then this one if i had a parameter i would use it in this case i don't need one so i'm just going to type in a decimal value there okay so now we've created those two shared variables so we're ready to run the external rule so we're going to go over here again in our built-in snippets and we're going to go to run other that's where you'll find the code to run other ilogic rules and here's one here for run external rule so we'll double click that and then we've got to put in the name of that external rule and it's got to match exactly so decimal inches to fraction so that's going to run that external rule and because we've already created the shared variables this should run just fine but then when that rule is finished running it's going to create a shared variable that stores the value of our mixed fraction so we need to get that value back and use it so we can use it in here in fact what we want where we want to use that is right here in this thickness rounded variable so what i want to do those out and we want this to be the shared variable that is called mixed fraction right and that name's got to match again so if you're not sure what it is you got to go check within our external rule and down to the bottom here okay it's creating a variable called mix fraction and just copy that bring it over here into your description rule and paste that there so now we're grabbing the value of that mixed fraction we're storing it in our thickness rounded so later down here we can put that into our description okay so that'll work for the first one we want to do the same thing for the length x and the length z but i don't want to write all that over again and i could just copy and paste it that would be a quick way to do it but i what i want to do is i want to be able to use that external rule in many many other documents and so and rather than having to set all this stuff up every time i just want to create a snippet for it so i can just super easy to use because i don't want to have to every time i want to call this external one i have to go okay what did i call that variable i got to open it up go okay i need decimal right increment mix fraction do that every single time if i just store this as a snippet now then i don't have to do any of that crap ever again i just run i just insert my snippet change a couple things and i'm good to go okay so i'm just going to add some comments here so we know what's going on okay all right so i'm going to capture this as a snippet so i don't i don't want that comment because that's specific to what i'm doing here but all of this stuff should go into my snippets grab all that and right click capture snippet i'm going to switch over to my custom here so i can see what i'm working with and then my title here uh again you want it to be succinct but descriptive so we'll say decimal into two action i want to store that in my aba folder we'll come back to the tooltip in a second let's go down to our code make sure it's going to work it's generic enough and so let's see that stuff we definitely want to change that's specific to the external rule we're trying to run thickness though that's again that's not something that's going to exist in other documents so we don't want to have that in there that'll just be confusing uh in the other example we had like a string we put in there like my component name in this case i don't want to put a string here i don't want to imply that that should be a string value so i don't want to do that we need to make sure they understand okay this needs to be a number so i'm just going to put something in my line like 1.25 it doesn't really matter we'll make it clear in the tooltip that this is something that the user needs to the developer is going to need to change each time they use this snippet so i'll just leave those two decimals that's just fine the external rule that doesn't need to change that's going to be the same every time we're going to read the shared variable that that shared variable name is going to be the same but this right here we probably want to generize this like we were talking about earlier i mean it would work just fine with that variable name but it's going to be confusing to someone down the road if we leave it like that so let's just give it something else mixed this fraction will do and it doesn't really matter that's the same name there that's not going to cause conflict these shared variables are stored separately so okay so there's our rule it's a little more generic um should be good to go so let's just write up a tooltip real quick here like i said we want to make sure we understand what it is we communicate what this does round to decimal value fraction and we want to explain what the user is going to change so i typically do this by just saying okay this is the variable and what you need to do with it so and then in this case we want to tell them this is actually going to send a value back so we want to make that clear so they know what they're going to get what this thing does so it's going to return okay and then also uh this rule has a pr or this snippet has a prerequisite what it's doing is it's running this rule named decimal inches diffraction and so in order for this to work properly that external rule has to be available in the external rules and so just make a note here that this requires okay all right here we go there is our uh new external rule let's go ahead and make sure we save that so we don't yep and now we're just gonna now we've got it here we're just going to insert it drop it there double click and then we want to make sure we change the things we need to change so in this case we're doing length x let's grab that guy and then this value i'll change that to 16. um this is all fine this right here though we're storing it as mixed fraction but i've already got a variable that i've created uh to use for that so i'm just going to go ahead and just copy this down here we're going to take that mixed fraction shared variable and store it there instead and i'll get rid of that line okay and then let's add it here again and this will be our like z and then we'll do the same thing here copy this just use the variable that i've already set up there we go so now let's go ahead and save this is a suppress rule let's go and unsuppress that because now it's actually functional we'll save and run and now when we go into our i properties we'll see there's the description they got the fractional mixed fraction values one thing to consider when using shared variables like this to pass values between rules and especially with external rules is there's this option for down under variables to remove a shared variable or even remove all that's something you might consider you might need if there's a potential for you might be running some other rules maybe further down this rule or later on that might use the same shared variable names and if you don't want them to kind of get the streams crossed then you can go ahead and as soon as you're done with them here you can remove them i don't need to remove them each time here even though i'm using the same shared variable name multiple times that's fine it'll just create it it'll see that it already exists and it'll just store a new value in it and then just use it that shouldn't that won't cause any conflicts here but if there's ever a potential for a conflict to exist you could consider removing the shared variables you could even do that inside of the external rule itself inside here and this is actually what i would do if i was concerned about that is right here after we've actually got the value from the shared variables we don't need those anymore so i would add some extra lines here to remove those shared variables just in case and then after this one gets created we don't want to remove it here because we still need to use it in the other rule so back in the snippet in here i would probably add to our custom snippet here after we grab the shared variable and stored it we don't need any more so i'd add another line here that removes that particular shared variable and so that way you don't have to do it every single time it's already stored in a snippet already in the external rule so it just works that way automatically each time so um there we go that was pretty much what i wanted to cover today we've still got some a little bit of time left over for some questions so let's go ahead and get to that perfect you know that's really interesting stuff yeah so i didn't realize you could kind of work together with external rules and snippets like that that'll save a lot of time i'm sure absolutely we got a few questions over here someone's asking is there a limit to how many parameters you could send to an external rule for example in your decimal interest a fraction rule could you send the decimal values and precision 8th 16th and 30 seconds i think i'm interpreting your question correctly there jerry but is there a limit to the number of parameters you could pass up to an external rule uh not that i know of i mean there might be you know if you max out the memory on your computer but that's unlikely to happen so yeah i i for all practical purposes no there's no limit right then another comment from eric as well you can't add an input box and assign the precision at runtime yeah i was curious about that too is there any kind of like prompted entry for these kind of ilogic rules you're talking about so instead of just editing the rules directly because they're just you know user prompts that you could put in there uh well like for when you're inserting the snippets uh it's just like when you're running the rule perhaps like so yeah i guess at runtime specifically right can you just access a pull down and then choose i want eighths precision or sixteenth precision uh i mean there there are inputs you can do like you can run in a rule so uh let's see the word the message box uh another message box so there's different inputs you can do to prompt the actual user at the run at the time you're running the rule but when you're actually developing the rule and like insert writing code and inserting snippets uh there's not really a way to do that inside of the um i logic development environment i got you i got you right right okay yeah that's fine by me that sounds good uh yeah then this is just for gentry are the recordings available yes uh they usually go up like within the next week or so so it might take a bit of lead time but everything that you see here all the avas from previous sessions and beyond are on our on our youtube channel just switch kativ on youtube you should find us pretty easy there i'm gonna close out here and on the topic of external rules as well um can you say anything about global forms as well is that something might be interested in in the future perhaps i think that's just the external equivalent to forms isn't it yeah yeah global form is an external or is the form equivalent of an external rule exactly so um like normally when you create a foreign logic form it lives inside this document just like a standard iological does but if you want to make a form that's available to any document like what i've got here this is kind of old one in the olden days it's not really necessary anymore but then you can do that uh there's a little bit more involved today i think we might have an aba on that um maybe last year yeah and it's it's relatively recent but um you know not within the last few months or whatever but yeah when you go and search our youtube channel for uh baby videos i think there's one where we talk about eyelogic forums and uh global forms i think is something we've covered there as well yeah and you know someone's else someone else is asking here actually do you have a session on inserting a part into an assembly and constraining it with ilogic i think you might be the one to have the answer to that yeah yeah i did one of those um last year yeah exactly 2020 there was one i did on there's actually several of those we also have some um from justin cow there's several different ways of approaching that uh justin cow did one i'm configuring an assembly um i did one on generating assembly like from scratches and start with an empty assembly and white eyeliner will replace components constrain them so yeah definitely go check out our catalog of videos there's one on that very topic yeah i actually have a playlist and i've watched that particular video of yours multiple times actually it's pretty interesting it's pretty good um i i'm gonna link you guys the actual playlist over here so we have like 26 videos and counting on this playlist now so yeah i mean a lot of people love animation man it's a good it's good stuff and we have a lot of um a lot of resources available on um on our website so check it out check out that playlist in particular there's a lot of good stuff um i won't say one yeah i won't say one is better than the other per se but there's a lot of good videos for sure i like cameron's a lot especially if you're looking for you know really really scalable types of operations and assembly stuff but um they're all pretty good all right so i think we're about at the end of time over here um see any any last words over here cameron we're about to at the end of the hour appreciate the time as always man yeah yeah glad glad to be here i think i covered everything i wanted to so yeah yeah hopefully we'll see you guys again and i guess just a heads up for everyone else on the call we're trying to trying out a new schedule so i think in about four weeks time we'll have another sort of automation type of session so possibly we'll see you guys again in four four weeks or so so um look up yeah we're still doing aba every week it's just yeah topics are kind of cycle so an automation topic like what we talked about today will be you know one week out of a month exactly exactly so you know stay tuned we got a lot of good stuff here thank you again cameron for being on and your busy schedule thank you audience for being on here with us here today and uh we'll be back we'll be back next week okay thank you everybody bye
Info
Channel: KETIV Technologies
Views: 736
Rating: undefined out of 5
Keywords: autodesk, akn_include, autodesk inventor, ketiv ava, ketiv academy, ketiv autodesk academy, design automation, inventor ilogic, rules driven design, autodesk academy, ketiv technologies inc., ava: introduction to ilogic, ava academy, autodesk software, ketiv technologies, autodesk virtual academy, help with ilogic, autodesk inventor 2020, computer aided manufacturing, autodesk presentation, autodesk inventor tutorial 2021, inventor ilogic assembly
Id: asWQptBwAH4
Channel Id: undefined
Length: 58min 27sec (3507 seconds)
Published: Tue Sep 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.