Implentation of GetPropertyInfo in C#

Implentation of GetPropertyInfo in C#

nedeljko.sovljanski
Advocate Advocate
618 Views
5 Replies
Message 1 of 6

Implentation of GetPropertyInfo in C#

nedeljko.sovljanski
Advocate
Advocate

Hi everyone,

 

I have problem with implementation in C# this method

PropertySet myCustomProp = ...... ;

myCustomProp .GetPropertyInfo(out int[] Ids, out string[] Names, out object[] Values);

 

It throws exception.

Did any one use this method in C#?

 

Best regards

0 Likes
Accepted solutions (1)
619 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @nedeljko.sovljanski.  What a coincidence.  I was just trying to use that same method earlier today within an iLogic rule, and was also running into lots of trouble for some reason, so I would like to tag in on this conversation.  I eventually just created my own custom Function to handle this task.

This is the function I created in iLogic (vb.net):

Function RecordProperties(oPropSet As PropertySet) As List(Of Object())
	Dim oMainList As New List(Of Object())
	If oPropSet.Count = 0 Then Return oMainList
	For Each oProp As Inventor.Property In oPropSet
		Dim oData(2) As Object
		oData(0) = oProp.Value
		oData(1) = oProp.Name
		oData(2) = oProp.PropId
		oMainList.Add(oData)
	Next
	Return oMainList
End Function

It records the property data in the same order that you need to use it when using the PropertySet.Add method to create new properties, on purpose.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

nedeljko.sovljanski
Advocate
Advocate

It works on this way:

private string[] SetCustomProp(PropertySet propSet, string name, string propValue)
        {
            int count = propSet.Count;
            int[] IDs = new int[count];
            string[] Names = new string[count];
            object[] Values = new object[count];
            propSet.GetPropertyInfo(out IDs, out Names, out  Values);
            return Names;
        }

but I don't want to count members and initialize three variables. Method GetPropertyInfo should do it inside and return those arrays. Instead of one line it asks 4 lines more.

0 Likes
Message 4 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

I think you always need to initialize and set the array's before you can feed them to function. But the strange thing is that you don't need to set the correct array length. so you can just give the function an empty array. For C# that looks like this:

int[] Ids = { };
string[] Names = { };
Object[] Values = { };
propSet.GetPropertyInfo(out Ids, out Names, out Values);

And for VB.net/iLogic

Dim Ids As Integer() = {}
Dim Names As String() = {}
Dim Values As Object() = {}
propSet.GetPropertyInfo(Ids, Names, Values)

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

Message 5 of 6

nedeljko.sovljanski
Advocate
Advocate

Sometimes works, sometimes doesn't. For this method you can done it in line.

oOcc.CreateGeometryProxy(basePlateWorkPlane, out object workPlaneProxy);

where oOcc is ComponentOccurence.

Anyway, users can implement your solution if inline makes problem.

 

Best regards

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Odd situation indeed.  But setting those initial 'empty' values seemed to do the trick for some reason.  If I don't set those empty initial values, it fails with a "Type mismatch." message.  This sure seems like a bug though.  I don't recall having to do that in other similar situations.  Having that figured out, even if I have to use 3 'Dim' lines, is still shorter and simpler than the custom function route. 😉  Thanks.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes