I'm trying to populate an array with a few iProperties, but get an error: Ongeldige klassereeks (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))
To explain:
In a part I have 15 text variables. I also have 15 custom iProperties. At the and of the porgram the iProperty value must match the corresponding variable value.
With a for-each-loop I want to handle each iProperty the same.
Private Sub iPropertyUpdate() ' Connect to a running instance of Inventor. Dim invApp As Inventor.Application invApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") ' Get the active document. Dim Doc As Inventor.Document Doc = invApp.ActiveDocument Dim prop As Inventor.Property ' Add iProperties in an array. Dim projectPropSet As Inventor.PropertySet = Doc.PropertySets.Item("Project") Dim customPropSet As Inventor.PropertySet = Doc.PropertySets.Item("Inventor User Defined Properties") Dim iPropertyArray() As String = {projectPropSet.Item("Project"), _ 'error-line... customPropSet.Item("customTest1"), _ customPropSet.Item("customTest2")}
I probably declare as wrong type. How to deal, or is it impossible?
Solved! Go to Solution.
Solved by VdVeek. Go to Solution.
I find out I have a complete other problem (beside of the above)
Line 3 of this code triggers an error. Is it possible I damaged this Project-item in earlier attempts? Is it possible to reset the environment or re-register the name Project as PropertySet. BTW, this is in the rule editor of iLogic...
Dim Doc As Document = ThisApplication.ActiveDocument Dim projectPropSet As PropertySet projectPropSet = Doc.PropertySets.Item("Project")
Error in rule: Rule0, in document: Part1
Error in rule: Rule0, in document: Part1 Ongeldige klassereeks (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))
System.Runtime.InteropServices.COMException (0x800401F3): Ongeldige klassereeks (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING)) at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at Inventor.PropertySets.get_Item(Object Index) at LmiRuleScript.Main() at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem) at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
"Project" did work before. Now "Inventor User Defined Properties" is still working well. I'm afraid I damaged something in an attempt to put 1 Project-property and a bunch of Custom Properties in an array to have carried out a number of read and write operations.
Is this repairable...?
Thanks in advance
I have made a mistake...
"Project" has never been a member of the PropertySets. I probably have edit the wrong piece of code.
I still wonder if it's possible to put a bunch of iProperties in an array....
I'm not sure why you want to put iProperties in an Array, is the following procedure an option for you?
Writen out in plain language and some code:
Dim TextArray = New String() {"value 1", "value 2", "value 3"}
Dim i As Integer = 0
Dim customPropSet As PropertySet
customPropSet = Doc.PropertySets.Item("Inventor User Defined Properties")
For Each value in TextArray
customPropSet.Item("customTest" & i) = value
'i is used as counter
i=i+1
Next
You can give this a try, "there are more ways to Rome".
Rob
I know there are more ways to Rome . I cannot find a nice one.
The reason why I want the iProperties in an array is because I have a piece of program that relates to all these iProperties.
I have 15 iProperties (2 in the PropertySet "Design Tracking Properties" and 13 in the PropertySet "Inventor User Defined Properties").
I also have 15 parameters and an iLogic user form.
For all of these iProperties, I want (among other things):
- check if excist (only necessary for the "Inventor User Defined Properties")
- create if not excist
- if excist and not "" then copy the value to one of the corrsponding 15 parameters, else do nothing
A possibility is to write all the code for each iProperty.
I prefer however the way described below.
' array with iProperty names Dim mijnArray1() As ? = {projectPropSet.Item("Project"), customPropSet.Item("customBouwjaar"), customPropSet.Item("customOntwerp_Type")} ' array with variable names Dim mijnArray2() As String = {"resultaat1", "resultaat2", "resultaat3"} Dim n As Integer Dim i, j As String For n = 0 To 2 ' MessageBox.Show(mijnArray1(n) + " " + mijnArray2(n)) Piece of code... Next
I'm not sure what part of the iProperty I need in the array. iProperties are Objects right..? When I dim mijnArray1 As Object it says: conversion from Property type String type is invallid. I also notice that none excisting properties creates another error so I have to catch the in a try.
During this writing I'm wondering if it is possible to make a multidimensional array with propertyset value and item name. In the For Each loop I can recreate the connection to each iProperty.
In iLogic you don't need to work with the PropertySet, iLogic is taking care of that. It makes the code simpler. I changed your code a bit and tested this example and it's working this way. Is this a way you can go
' array with iProperty names Dim mijnArray1() As String = {iProperties.Value("Custom", "customBouwjaar"), iProperties.Value("Custom", "customOntwerp_Type")}' array with variable names Dim mijnArray2() As String = {"resultaat1", "resultaat2"} Dim n As Integer Dim i, j As String For Each ArrayWaarde In mijnArray1 MessageBox.Show(ArrayWaarde + " - " + mijnArray2(n)) n=n+1 Next