Custom iProperty is type Number; needs to write to type string

Custom iProperty is type Number; needs to write to type string

jwitt1983
Enthusiast Enthusiast
1,680 Views
4 Replies
Message 1 of 5

Custom iProperty is type Number; needs to write to type string

jwitt1983
Enthusiast
Enthusiast
Our new ERP system requires a custom iproperty called "gss_rm_qty" for raw material measurement in string format.


I would like our users to be able to choose whether this value is actual face area or bounding box size (basically length x width)... I've already put together the code to create these custom iproperties (SheetMetalExtentsArea vs SheetMetalActualArea below), however, they are "number" type. Which is preventing me from writing the choice directly to "gss_rm_qty" with the error:

         Overload resolution failed because no Public '=' can be called with these arguments:
         'Public Shared Operator =(a As String, b As String) As Boolean':
         Argument matching parameter 'a' cannot convert from '__ComObject' to 'String'.


Below is the part of the code that is not working...


oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
	'Setting a userParameter as text parameter
Try
	otester = oMyParameter.Item("ActualOrEstimated")
Catch
	oAreaType = oMyParameter.AddByValue("ActualOrEstimated", "Estimated", UnitsTypeEnum.kTextUnits) 
	'make parameter a multivalue list parameter
	MultiValue.SetList("ActualOrEstimated", "Estimated", "Actual")
End Try

If oMyParameter.Item("ActualOrEstimated") = "Estimated" Then
	oCustomProps.Item("gss_rm_qty") = Convert.ToString(oCustomProps.Item("SheetMetalExtentsArea").Value)
Else
	oCustomProps.Item("gss_rm_qty") = Convert.ToString(oCustomProps.Item("SheetMetalActualArea").Value)
End If​




I tried to use CStr() & Convert.ToString()in but it doesn't seem to work either. Maybe I'm not formatting them correctly, idk.

oCustomProps.Item("gss_rm_qty") = Convert.ToString(oCustomProps.Item("SheetMetalActualArea").Value)

oCustomProps.Item("gss_rm_qty") = CStr(oCustomProps.Item("SheetMetalActualArea").Value)


Any help to get this formatted correctly to output would be appreciated. Thanks!
0 Likes
Accepted solutions (1)
1,681 Views
4 Replies
Replies (4)
Message 2 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

AFAIK, Inventor defines the data type of an iProp by itself. I think your problem is, that you try to assign a property value to another property, not to another propertys value.

Try:

If oMyParameter.Item("ActualOrEstimated") = "Estimated" Then
	oCustomProps.Item("gss_rm_qty").value = Convert.ToString(oCustomProps.Item("SheetMetalExtentsArea").Value)
Else
	oCustomProps.Item("gss_rm_qty").value = Convert.ToString(oCustomProps.Item("SheetMetalActualArea").Value)
End If​

R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 5

jwitt1983
Enthusiast
Enthusiast

I tried your suggestion of adding .Value to the "gss_rm_qty" property... still same error.

 

Also tried your suggestion along with using CStr() instead of Convert.ToString()... I believe these are the same but thought it would be worth a shot either way, still same error:

 

Overload resolution failed because no Public '=' can be called with these arguments:
         'Public Shared Operator =(a As String, b As String) As Boolean':
         Argument matching parameter 'a' cannot convert from '__ComObject' to 'String'.

 

0 Likes
Message 4 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

Sorry, forgot to say the parameter value is the string you want to compare with "Estimated"

If oMyParameter.Item("ActualOrEstimated").value = "Estimated" Then

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 5 of 5

Michael.Navara
Advisor
Advisor
Accepted solution

Your code fragment can't be tested, but try the following modified and commented code

 

'Define oMyParameter type explicitly for better intellisense
Dim oMyParameter As UserParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
'Setting a userParameter as text parameter
Try
	Dim otester = oMyParameter.Item("ActualOrEstimated")
Catch
	oAreaType = oMyParameter.AddByValue("ActualOrEstimated", "Estimated", UnitsTypeEnum.kTextUnits)
	'make parameter a multivalue list parameter
	MultiValue.SetList("ActualOrEstimated", "Estimated", "Actual")
End Try


'If oMyParameter.Item("ActualOrEstimated").Value.ToString() = "Estimated" Then
'oCustomProps.Item("gss_rm_qty") = Convert.ToString(oCustomProps.Item("SheetMetalExtentsArea").Value)
'Else
'oCustomProps.Item("gss_rm_qty") = Convert.ToString(oCustomProps.Item("SheetMetalActualArea").Value)
'End If

Dim doubleValue As Double
If oMyParameter.Item("ActualOrEstimated").Value.ToString() = "Estimated" Then
	doubleValue = oCustomProps.Item("SheetMetalExtentsArea").Value
Else
	doubleValue= oCustomProps.Item("SheetMetalActualArea").Value
End If

'Use string.Format function with possible formatting 
'For example {0:N3} => converst value to string rounded to 3 decimal places
oCustomProps.Item("gss_rm_qty").Value = String.Format("{0:N3}", doubleValue)

 

0 Likes