- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Message: Object reference not set to an instance of an object when used of MultiValue.List in assembly doc
When i follow your tutorials and used of This :
Dim doc as AssemblyDocument = ThisApplication.ActivateDocument
Dim oAssDef as AssemblyComponentDefinition = doc.ComponentDefinition
Dim oUsPar as userparametes = oAssDef.parameters.Userparameters
Dim oPar as Userparameter = oUsPar.AddByValue("Side", "", unitstypeenum.ktextunits)
Dim oArr as New ArrayList
oArr = MultiValue.List("Side")
oArr.Add("Left Side")
oArr.Add("Right Side")
MultiValue.List("Side") = oArr
Get this error:
" Object reference not set to an instance of an object"
I think "MultiValue.List()" couldn't get object of userparameter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You've got some Typos in there and setting a multivalue list is done a little differently. Switching up your code to something like this should get you going:
Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAssDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oUsPar As UserParameters = oAssDef.Parameters.UserParameters
Dim oPar As UserParameter = oUsPar.AddByValue("Side", "", UnitsTypeEnum.kTextUnits)
Dim oArr As ArrayList = MultiValue.List("Side")
oArr.Add("Left Side")
oArr.Add("Right Side")
MultiValue.SetList("Side", oArr.ToArray())
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi dear
With Respectfully How I can be able to initialized the "MultiValue.SetList, MultiValue.List, Parameter() and other ilogic property and sub" in visual Studio class AbstractRuleClass, and then used of this with inherits ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It sounds like you have created a separate Class block of code, and are trying to use the common iLogic objects within that Class. This is a common problem, but a very difficult one to explain properly. The iLogic add-in and its user interface (the iLogic Rule editor dialog) do a whole lot of extra stuff for us, to make automating Inventor simpler and easier for beginners, who do not have much (if any) previous coding experience. One of the things it does for us is create a bunch of 'Rule Objects' for us (behind the scenes, where we do not see the code supporting it) to readily use in our simpler rules (rules without Class/Module/Structure type blocks of code). Part of how this is done is with a 'Partial' Class, where we never really see that 'other' partial Class named "ThisRule". The iLogic add-in will automatically create that Class for us, so we do not need to start all of our rules with a Class statement. It will also automatically create the 'Sub Main' block for us, if we do not. But, we never see all that stuff.
The most common way to use those types of objects that are unique to the iLogic add-in within other Classes, is to 'pass' them in, either through input variables to methods (subs or functions) defined within the Class (such as the 'New' sub routine), or through public properties defined within the Class.
You can also review the following topic:
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks so much
As your opinion whats the best way ????
I've many rules in ilogic and want to move all of them to addin with different buttons
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I wouldn't call this the best way, but I often need the Rule Objects in functions that are in an external VB file, and I get them by passing in the iLogicVb object and using the CreateObjectProvider function to get access to the rest of the rule objects. Here's an example using your code, the following would go into VB/whatever:
Sub CreateSideList(iLogicVb As ILowLevelSupport)
Dim doc As AssemblyDocument = iLogicVb.RuleDocument
Dim oAssDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oUsPar As UserParameters = oAssDef.Parameters.UserParameters
Dim oPar As UserParameter = oUsPar.AddByValue("Side", "", UnitsTypeEnum.kTextUnits)
Dim mValue As IMultiValueParam = iLogicVb.CreateObjectProvider(doc).MultiValue
Dim oArr As ArrayList = mValue.List("Side")
oArr.Add("Left Side")
oArr.Add("Right Side")
mValue.SetList("Side", oArr.ToArray())
End SubThen, in an inventor rule, you would call it like this:
CreateSideList(iLogicVb)We make use of an addin to put bottons on our ribbon a lot, but we usually have the button link to iLogic rules so it's easier to update the code as we need to and don't need to update the add-in.
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sincerely, thank you for your time
Posible for you to tell me how i can initialized the ilowlevelsupport in AbstractRuleClass?
Like this:
Public Property ThisApplication as Inventor.Application
Public ReadOnly property Thisdoc as iCadDoc
Get
Return new CadDoc(ThisApplication.activedocument)
End get
Or something along those lines
I dont know what to use to "get" to ilowlevelsupport?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am pretty sure that I have seen forum replies where someone from Autodesk has told us that 'creating' or 'getting' the 'iLogicVb' (ILowLevelSupport) object within external resources like add-ins is not possible, and therefore it must be passed in. There are a few things which are unique to iLogic that we can do in external resources without needing to pass that object in though. Perhaps the oldest, and best known way is to get the actual ApplicationAddIn object for iLogic, then create a variable set to Object type, or more specifically IiLogicAutomation Type, then set its value with the ApplicationAddIn.Automation property. Not all add-ins have a useful value for that, but since iLogic has its own internal API, it does have a useful value. It will act the same as the phrase 'iLogicVb.Automation' does in a normal iLogic rule.
PS. Also, for what its worth, if you go to the Tools tab, then click on the Add-Ins button on the Options panel, it will open the small dialog with two tabs, showing all the current add-ins. If you select one, then look at the bottom of the dialog, you will see the location of the primary DLL file supporting that add-in. This of course is not the only file involved, but sometimes you can add a reference to that DLL in your code, then you can explore some of the stuff that they have publicly accessible in that DLL.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Since most of those types of objects are an Interface, instead of a Class, we can not simply use the New keyword to create a new instance of any of them. So, once we have passed in one of these base Rule Objects like 'iLogicVb', we can use that to set the value of our internal variables. Then we can create our own internal variables for the other Rule Objects, and populate them from the first object, if it has the scope necessary, as that object does.
Below is an basic example Class that requests the iLogicVb object be passed into it within its 'New' Sub routine, like what was suggested multiple times above. It then uses that to set the value of a private, internal variable, which this Class will use for all other things requiring its capabilities. Then, from there, it starts populating the values of other similar private, internal variables. Then it uses one of those variables within a super basic function.
Public Class TestClass
Public Sub New(iLogicVb As ILowLevelSupport)
_iLogicVb = iLogicVb
_InvApp = _iLogicVb.Application
_iLogicAuto = _iLogicVb.Automation
_Doc = _iLogicVb.RuleDocument
_ObjectProvider = _iLogicVb.CreateObjectProvider(_Doc)
_ThisDoc = _ObjectProvider.ThisDocument
End Sub
Private Property _InvApp As Inventor.Application
Private Property _iLogicVb As ILowLevelSupport
Private Property _iLogicAuto As IiLogicAutomation
Private Property _ObjectProvider As IStandardObjectProvider
Private Property _Doc As Inventor.Document
Private Property _ThisDoc As ICadDoc
Public Function Prop(sPropertySetName As String, sPropertyName As String) As Object
Return _ObjectProvider.iProperties.Value(sPropertySetName, sPropertyName)
End Function
End Class
and a regular rule that creates a new instance of this Class, passed the required input, then uses its one public function to retrieve the value of a custom iProperty.
Dim oMyTestClass As New TestClass(iLogicVb)
Dim oValue As Object = oMyTestClass.Prop("Custom", "Testing")
MsgBox(oValue.ToString,,"")
However, in order for this rule to be able to access the definition of that Class, the Class definition must either also be within the same rule, or it must be within an external rule file that has had its option called "Straight VB Code" turned on (checked), and you just include the 'AddVbFile' in the header of this simple rule, followed by the quoted name of that external rule, with file extension included. And that external rule must be in one of the locations specified within your iLogic Configuration settings, so it can find it. Otherwise, you may need to specify the full file path to that file within that header line.
Edit: Almost forgot to mention that...in the external rule, where your custom Class is defined, which is set to Straight VB Code', you can include 'Imports' type lines within that rule's header, but you usually can not include 'AddReference' type lines in that rule's header. So, if that external rule is attempting to access any object Types, or methods that are defined in other references, you will need to include those 'AddReference' lines in the header of the 'regular' rule that will be referencing that external rule, and using it. In this case the required line would be:
AddReference "Autodesk.Inventor.Interop"
That reference is where the object Types 'Inventor.Application', and 'Inventor.Document' are defined. Your regular rules will include references to these, and much, much more for you, behind the scenes, where you never see it, to help you out. But it does not 'help' those externally referenced rules with 'Straight VB Code' set.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You are amazing, thank you for your excellent and comprehensive explanations. I will definitely implement what you said and give you feedback.
Sincerely, thank you for your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You are amazing, thank you for your excellent and comprehensive explanations. I will definitely implement what you said and give you feedback.
Sincerely, thank you for your time 🪴🪴![]()