iLogic IDE and Remembering Methods

iLogic IDE and Remembering Methods

e_frissell
Advocate Advocate
1,146 Views
11 Replies
Message 1 of 12

iLogic IDE and Remembering Methods

e_frissell
Advocate
Advocate

For all you of you guys how do you remember the methods without the built in Object Browser?

 

Programming was crazy easy in VBA but moving into iLogic if you don't recall the exact method you're looking for it's impossible to find.  Website is useless as well.

 

Right now I want to find all parts in an assembly and I know which commands do it, but I can't get the commands into the stupid IDE.  Also no need to post how to do that.  I'll have scrounged it up from one of my other scripts by the time you read this, but I do want to know how the heck people find anything without the IDE

0 Likes
Accepted solutions (1)
1,147 Views
11 Replies
Replies (11)
Message 2 of 12

WCrihfield
Mentor
Mentor

Hi @e_frissell.  One of the primary resources I rely on when creating new iLogic rule code is its built-in Intellisense system.  I start typing in stuff along the lines of where I am going, and after I type each dot (.), there is a list of suggestions of what I can put after that dot.  That list usually includes all the properties and methods available to that last object before the dot.  Having a copy of the Inventor API Object model diagram readily available also helps with early navigation, until you just get used to it, and get it stored in your head.  There is a larger, better quality version of that diagram within the Inventor SDK folder, after you install the available developer tools & user tools MSI files within it.  I also extensively use the iLogic 'snippets' (seen along the left side of the iLogic rule editor screen).  Not just the built-in stuff (which are pretty nice), but also the custom ones.  As I create useful lines or blocks of code, I store them as custom snippets in there.  Then I can look them up by category, and easily drop them into my existing rules.  Super helpful.  Especially if you leave a healthy amount of comments in your snippets for quick/easy look-up.  Then I do use the online help documentation a lot also, because there is a page for every type of object, which lists its methods, properties, and events, with links to each of them, for more information.  Some of that documentation is definitely lacking and seemingly outdated, but when I find stuff like that, I usually try to leave a comment about something that I find that is obviously wrong, or misleading, so they can hopefully fix it soon.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 12

JelteDeJong
Mentor
Mentor

I agree that the iLogic IDE could use some improvements. A while ago I wrote a blog post on this subject with some solutions. you might want to read it. "Writing and debugging iLogic rules"

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 12

e_frissell
Advocate
Advocate

Thanks @WCrihfield , I had forgotten about the Object Model - all the time I find that I'm trying to do something super basic like ensure I'm working with an assembly document and I know I need kAssemblyDocumentObject but can never remember the path to get there.  The object model should help.  Adding the "." after you type a command is helpful a lot of the time, but my headache is I usually remember the method, but not what I need to get there.  In VBA that was way easier and always been a huge frustration in iLogic.  Never used or created custom snippets but that may honestly be the easiest way to solve some of that frustration.

 

Since I've got you on the line...  I'm writing a script that's supposed to replace parts in an assembly with a part that comes from the vault - i.e. your assembly and all it's parts are saved externally from the vault - and I'm getting an error and I think I know why, but don't have a good idea of how to solve it.

 

Dim oDoc As AssemblyDocument = ThisDoc.Document
If oDoc.DocumentType <> kAssemblyDocumentObject Then
	MsgBox("Only run on assemblies")
	Exit Sub
End If

Dim oAsmCompDef As AssemblyComponentDefinition
Dim oComp As ComponentDefinition
Dim oPart As Document
Dim oPartName, oFullName As String
'Dim ticker As Integer

'ticker = 0
For Each oPart In oDoc.ReferencedDocuments
	If oPart.DocumentType <> kPartDocumentObject Then GoTo Skip
	oFullName = oPart.DisplayName
		
	oPartName = iProperties.Value(oPart.DisplayName, "Project", "Part Number")
	'ticker = ticker + 1
	'If ticker >= 10 Then Exit Sub
		
	'MsgBox(oPart.DisplayName & "    " & oPartName) - finds part
	'Build one to many name/value pairs of Property/Value as search criteria
	Dim mSearchParams As New System.Collections.Generic.Dictionary(Of String, String) 'add UDP.DisplayName, Value Pairs
	mSearchParams.Add("Part Number", oPartName)
	
	'returns full file name in local working folder (download enforces override, if local file exists)
	Dim mVaultFile = iLogicVault.GetFileBySearchCriteria(mSearchParams, True, False)
	
	If mVaultFile Is Nothing Then
		Logger.Error("Vault file search: File not found - Please double check that file can be found with search criteria applied.")
	Else
		Logger.Info("File " & mVaultFile & " found by search and downloaded to local workspace.")
		'MsgBox("maybe found?")
		'add next action using the downloaded file here, e.g. Component.Replace("Part1:1", mVaultFile, True)
		Component.Replace(oFullName, mVaultFile, True)
	End If

	Skip :
	
	Next

 

When this runs I get an error noting Component: The component named "123-45678.ipt" was not found and I think Component.Replace is looking for a component occurrence, but I'm not sure how to get their from the part level.  Any thoughts?

0 Likes
Message 5 of 12

WCrihfield
Mentor
Mentor

Hi @e_frissell.  Unfortunately, I am not that familiar with Vault related code, since I do not, and have not used it before.  However, that Component.Replace() method is an iLogic only method, and I assume that the oFullName value did not include the little ":1" portion of the component's name.  Inventor automatically adds that little Integer after all component names to keep any 2 from having the same exact name.  The Inventor API alternative to that method is the ComponentOccurrence.Replace method and the similar, but updated ComponentOccurrence.Replace2 method.  With either of those last two, you start from the actual ComponentOccurrence that you want to replace, then specify the 'replacement' FullDocumentName (among other stuff).  On my way out right now though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 12

e_frissell
Advocate
Advocate

Funny @JelteDeJong appeared since, after I read your response, went back to Google and found his solution which avoided the component.replace built-in in favor of the replace2 method which seems to be working

0 Likes
Message 7 of 12

e_frissell
Advocate
Advocate

Thanks, that's new to me so I'll take a look!

0 Likes
Message 8 of 12

A.Acheson
Mentor
Mentor

The online API help is a great way to work through each objects of the Inventor API. I will admit it isn't great to search with individual objects as it tends to bring back lots of samples from the forum. I like to use the help files shipped with inventor install and then use the various search tools. 

AAcheson_0-1701722931421.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 9 of 12

Frederick_Law
Mentor
Mentor

@e_frissell wrote:

I'm working with an assembly document and I know I need kAssemblyDocumentObject but can never remember the path to get there.

 


kAssemblyDocumentObject is a enum, not a method:

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-7CB39A7A-FA63-4DC4-85A4-2C2F4E1E9BF9

0 Likes
Message 10 of 12

Curtis_Waguespack
Consultant
Consultant

@e_frissell 

 

In addition to the information provided already, see tips 12 and 13 at this link:

https://www.autodesk.com/autodesk-university/class/iLogic-25-Tips-and-Tricks-Boost-Octane-your-Inven...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

Message 11 of 12

WCrihfield
Mentor
Mentor
Accepted solution

One more little tip that ties a few of the above tips together, and addresses another of the primary concerns about the iLogic Intellisense system being a bit different than the one you are used to in the VBA editor...One thing that the iLogic Intellisense system does not do, that the VBA version does do, is offer a list of possible 'values' after you type in an equals sign (=).  The Boolean type value is simple enough that we do not need help with that, but when the Value is supposed to be a variation of an 'Enum', that can be a lot more complicated at times.  The VBA system will suggest a list of Enum variations for you to choose from, which was nice, but although the iLogic system does not offer that automated list to choose from, it does usually offer us a good hint about how to proceed at that point.  Below is a simple iLogic rule example of a very common scenario like that, where we want to check document type, before proceeding, but no help is offered after you type in the "=" character.

Dim oDoc As Document = ThisDoc.Document
If oDoc.DocumentType = 

What I always do, if I am not familiar with what needs to go after the equals sign, is hover my mouse over the previous variable/property to see what the iLogic Intellisense hint says about its 'Type'.

WCrihfield_0-1701780535597.png

That tip informs me that the value should be a variation of the DocumentTypeEnum, as @Frederick_Law pointed out earlier.  Next I type in the name of that Enum after the equals sign, then type the dot after it, and the iLogic system then offers me that list of variations to choose from.

WCrihfield_1-1701781350906.png

By the way, in iLogic, it is always recommended to include the name of the Enum, followed by the Enum variation name, not just the name of the Enum variation, and not just its numerical value.  Not only is it easier to read later, but sometimes if the Enum name is not included, and something in the first part of that line of code is not defined properly, it might not recognize the variation name as a value of that Enum, which can cause problems later.  And of course, there is documentation about every Inventor API Object or Enum within the Inventor API help file/website.

 

One other thing...sometimes the Value of a property is just returned as an Object, instead of a more specific Type, often because it is possible for multiple Types to be returned.  In those situations, once I have tested what Type it is, I will declare a variable as that Type, then assign the Object as its Value, just to enable the Intellisense system to recognize it going forward and offer those tips again, and sometimes that also seems to help avoid errors also.  That is another case for using the iLogic Logger to write stuff to the iLogic Log window, such as:

Logger.Info("Object Type = " & TypeName(oMyVariable))

Which lets me know what Type the Object was, so I can better understand, and/or revise the code for handling specific object Types in the future.

 

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 12 of 12

e_frissell
Advocate
Advocate

@WCrihfield wrote:

What I always do, if I am not familiar with what needs to go after the equals sign, is hover my mouse over the previous variable/property to see what the iLogic IntelliSense hint says about its 'Type'.

WCrihfield_0-1701780535597.png


Holy crap, that is an awesome tip, and exactly what I was hoping to hear by posting my gripe about iLogic's Intellisense because you can know where you need to go, but no help was offered to get there!  Every iLogic rule I've written starts off the same way - with Google, then finding something similar to create an instance of the variables (most likely) needed, then modifying it to get what I needed.  The modification, while not always the easy part, was a heck of a lot easier with the variables already instantiated and assigned to get the IntelliSense to work!

 

Thanks a ton for posting that tip, that will be really helpful!

0 Likes