ILogic Classes and Inventor Snippets

ILogic Classes and Inventor Snippets

alexGX8TC
Participant Participant
1,855 Views
6 Replies
Message 1 of 7

ILogic Classes and Inventor Snippets

alexGX8TC
Participant
Participant

This is a continuation of this post. Basically I want to use classes to clean up one of my programs, as I have many "stations" which are the same for the most part but have several properties which vary between each one. I want to be able to change these properties based on forms which is why I did the last post.

 

As I have begun to flesh out my program some more I keep running into issues where I try to use Inventor snippets inside of the classes and it basically says, "Reference to a non-shared member requires an object reference." A few examples include MultiValue, Logger, ThisDoc.Document.ComponentDefinition.Occurrences, Components.Add and others.

 

I guess I'm asking if there's a way to use all the inventor snippets in classes without bringing each one in like was shown in the previous post solution. Or is there a better alternative to making and editing many instances of similar yet different objects. Thank you!

0 Likes
Accepted solutions (1)
1,856 Views
6 Replies
Replies (6)
Message 2 of 7

Martin-Winkler-Consulting
Advisor
Advisor

@alexGX8TC 

Basically, I can say from my own experience that copying snippets and pasting them into an iLogic rule, VBA or VB.Net programming is not enough. It is important that you understand what is happening in the snippet, which objects and types are used and understanding the context. I recommend that you deal with object-oriented programming. Most errors happen because types are not used correctly or objects are addressed incorrectly. The programming in the VBA environment helped me the most to get a deeper understanding of the structure of the Inventor API. You will also find many explanations and examples in blogs. I would particularly like to mention the modthemachine blog in this context.

Many thanks to @BrianEkins  and @adam.nagy at this point
I hope this helps you a little bit.

Martin Winkler
CAD Developer
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

0 Likes
Message 3 of 7

Anonymous
Not applicable

It really depends on what you're trying to do. Based on your last post, I don't think it's necessary to define a new class for each one of your stations, but I don't know what your code looks like. If you are just trying to organize your code into smaller chunks that can be used in multiple places, without copy/pasting the entire snippet, I think you are better off just using Sub/Functions. ThisRule is a class that already contains all the iLogic functions you need, defining a new class is essentially starting from scratch and you would have to pass them from ThisRule.

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

Is everything you're working with entirely within iLogic rules (internal or external rules)?  Or are you trying to work entirely within the VBA Editor environment and Modules & Macros; or within Visual Studio; or a combination of some of these?

FYI:  Inventor iLogic is an Addin within Inventor, and not really its own programming language.  It mainly uses VB.NET (visual basic).  There are a bunch of classes, subs, functions, etc already defined within the iLogic Addin, to help people that don't have a programming background be able to customize and automate Inventor.

VB.NET has its own set of pre-defined classes, subs, & functions too.  When outside of the iLogic environment, and not referencing it, all those classes, subs, & functions which are only defined within the iLogic Addin won't be available.  If you want the same functionality as something only found within iLogic, you may have to re-define it outside of iLogic (as you would using different modules within the VBA Editor environment.)

However, iLogic can also work similarly to the VBA environment, using external rules, and some advanced techniques, but it is generally more work to use this way than the VBA environment.

I hope this helps clear a few things up.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

alexGX8TC
Participant
Participant

Hey guys thanks for the replies. I've coded a decent bit before, but I've only just started to code in VB and so there's still a lot I don't understand and I totally agree with @Martin-Winkler-Consulting that understanding the actual structure of the language is important. I'm definitely going to do some research and watch some videos on VBs structure. 

 

Moving to my program, I want to establish that I am only working with ILogic rules right now. I am open to using the VBA environment, but would prefer to just stick to ILogic for this program.

 

Responding to @Anonymous I'm not sure if we have the same definitions for classes and objects. I'm only making one "Station" class but making many objects or instances of that class. The reasoning behind this is that each "Station" object is almost identical, but every one has minor differences. I'm also curious about what you said about ThisRule. I tried to Inherit it but it still didn't fix my issue.

 

And for @WCrihfield as I said I'm in the ILogic environment but am creating a class in it. As of right now I believe classes are the best solution to having many instances of similar objects but maybe there's a better way? If there isn't a better solution is there a way to inherit all of the inventor functions/snippets/subs/classes into the class so that I can do stuff within the class?

 

Below is some of my code. It doesn't actually have a station class because I wanted to start these other ones first. They demonstrate a few of the things I want to do. I know it's not super clean or well written as I'm still learning how to write VB classes. If you look BuildTrueSetupList Sub I'm trying to make a list of all of the occurrences in the assembly. It's not possible right now because I can't access ComponentOccurences. There's some other things but this is one example. 

Sub Main
	Dim Props As New SetupProperties(Parameter, MultiValue)
	Props.BuildLists
End Sub

Class BaseProperties
	
	'###FIELDS###
	Dim Parameter As IParamDynamic
	Dim MultiValue As IMultiValueParam
	Public ConstantsList As New List(Of String)
	Public Count As Integer = 0
	
	'###CONSTRUCTOR###
	Public Sub New(oParam As IParamDynamic,multival As IMultiValueParam)
		Parameter = oParam
		MultiValue = multival
	End Sub
	
	'###METHODS###
	Public Sub BaseCurrent()
		BuildBaseModelList()
	End Sub
	Public Sub Update()
		Parameter("Frame:1", "Width") = Parameter("Width")
		Parameter("Frame:1", "Pitch") = Parameter("Pitch")
		Parameter("Frame:1", "WidthCnt") = Parameter("WidthCount")
		Parameter("Frame:1", "LengthCnt") = Parameter("LengthCount")
		Parameter("Frame:1", "Count") = Count
		Parameter("Frame:1", "Spacing") = 10
	End Sub
	Private Sub BuildBaseModelList()
		oFolder = ThisApplication.ActiveDocument.BrowserPanes("Model").TopNode.BrowserFolders.Item("Base")
		Dim oItem As BrowserNode
		
		For Each oItem In oFolder.BrowserNode.BrowserNodes
			ConstantsList.Add(oItem.NativeObject.Name)
		Next	
	End Sub
	
End Class

Class SetupProperties
	Inherits BaseProperties
	Private TrueSetup As List(Of String)
	
	Public Sub New(oParam As IParamDynamic,multival As IMultiValueParam)
		MyBase.New(oParam,multival)
	End Sub
	
	Public Sub BuildLists()
		BaseCurrent
		BuildTrueSetupList
	End Sub
	
	Private Sub BuildTrueSetupList()
		Dim oComp As ComponentOccurrence
		Dim oComps As ComponentOccurrences
		oComps = ThisDoc.Document.ComponentDefinition.Occurrences
		For Each oComp In oComps
			If Not ConstantsList.Contains(oComp.Name)
				TrueSetup.Add(oComp.Name)
			End If
		Next
	End Sub
End Class

 Sorry that was so long winded but at the end of the day if there's an "Inherit 'Something'" line that I can add to the top of the classes which would give me access to all the ILogic stuff that's what I'm looking for. Thank you again!

0 Likes
Message 6 of 7

Anonymous
Not applicable
Accepted solution

I'm not sure if there is an easy way to access the the same iLogic functionality in ThisRule in a new class. 

 

Since you are using more than one of the interfaces from ThisRule, it's probably simpler to pass itself to your new classes instead of each individually. You still have to define new objects for them though.

 

 

Sub Main
	
	Dim al As New Test(Me)
	al.UpdateSize()

End Sub

Public Class Test 
	
	Dim ThisRule As ThisRule
	Dim ThisDoc As Document 
	Dim Parameter As IParamDynamic 
	Dim MultiValue As IMultiValueParam 
	
	Public Sub New(oThisRule As ThisRule)
		
		ThisRule = oThisRule
ThisDoc = ThisRule.ThisDoc.Document
Parameter = ThisRule.Parameter
MultiValue = ThisRule.MultiValue
End Sub Public Sub UpdateSize() Parameter("Part1:1","Length") = Parameter("Length") Parameter("Part1:1", "Width") = Parameter("Width") End Sub End Class

 

0 Likes
Message 7 of 7

alexGX8TC
Participant
Participant

Right ok I'll look at this and if it doesn't work for me I think I might look into maybe just using some structs and sticking with subs and functions. Thank you

0 Likes