iLogic - a couple Syntax Questions

iLogic - a couple Syntax Questions

Anonymous
Not applicable
1,346 Views
1 Reply
Message 1 of 2

iLogic - a couple Syntax Questions

Anonymous
Not applicable

Hey,

So 2 questions:

 

1. Why do I so often see people posting code that says things like "oSheet" and "oDrawDoc?" What does the 'o' signify?

2. In the following code snippet, there is a '(1)' after the word 'Item." Is this (1) the item number (and so could be (2), (3), (4), etc), or is it something else?

 

Dim oApp As Inventor.Application
oApp = ThisApplication
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = oApp.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawingDoc.ActiveSheet
Dim oPartslist As PartsList
oPartslist = oSheet.PartsLists.Item(1)
oPartslist.Title = "test"

 

Thanks!

 

  -Luke

0 Likes
Accepted solutions (1)
1,347 Views
1 Reply
Reply (1)
Message 2 of 2

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@Anonymous wrote:

 

 

1. Why do I so often see people posting code that says things like "oSheet" and "oDrawDoc?" What does the 'o' signify?

2. In the following code snippet, there is a '(1)' after the word 'Item." Is this (1) the item number (and so could be (2), (3), (4), etc), or is it something else?

 


Hi nealon.luke ,

 

Q1) the o sort of loosely stands for object. Generally in programming you see variables and constants prefixed to indicate type. sName for instance indicates a String, where as iName is likely an Integer.

 

The other day however, I noticed I posted an example that had something like Dim dNumber as Integer. So d should have been used for a Double but I had it defined as an Integer Inventor saw it as an Integer. In that case it made no difference, but was just poor form on my part. The point here is that the letters are just to help ID they type, but they don't define them. That is done by declaring them using Dim. If we don't declare the variable, you can get "wrong type" errors.

 

In Inventor you'll often see everything prefixed with just o, regardless if it's String, Integer, Double, etc.

 

Somewhere on these forums I read one of the Autodesk employees ( I think) taking credit/blame for starting that trend years ago.

 

The important thing is that the variable can be distinguished as a variable. For instance if I were to create a variable named Length, it might be difficult later for me to figure out if Length is a variable or a model parameter, but naming it oLength makes that easier (although I have been guilty of naming model parameter with the o, which we really should not do).

 

Here's a related link:

https://msdn.microsoft.com/en-us/library/aa240858(v=vs.60).aspx

 

 

Q2) the number relates to the instance of the item in the collection. So you're correct, that is we we're looking at the PartsList collection and there are 3 parts lists on the sheet, and we knew that we want the 2nd one, we can just use something like oPartslist = oSheet.PartsLists.Item(2)

 

Likewise if the items in the collection have names, you can just call them. For instance if I was working with hole features I might use a line such as:

oHole = ThisDoc.Document.ComponentDefinition.Features.Item​("Hole2")

 

or I could use this, assuming that I knew that Hole2 was indeed the second hole in the collection:

oHole = ThisDoc.Document.ComponentDefinition.Features.Item​(2)

 

Sometimes collections such as arrays start with 0, so the first item is .Item(0), the second is .Item(1), and so on.

 

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

EESignature