Reply

Exception when calling GetDiscreteValues in Dimension

Hi I am getting an exception when calling GetDiscreteValues function.

HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

 

I need to get all discrete values from the variable but it seems the API is using the wrong type in the interop. Any ideas?

 


Dim application = MyAddIn.Instance.Application Dim part As SolidEdgePart.PartDocument = Nothing Dim variables As SolidEdgeFramework.Variables = Nothing Dim variableList As SolidEdgeFramework.VariableList = Nothing part = application.ActiveDocument variables = part.Variables variableList = variables.Query("*", SolidEdgeConstants.VariableNameBy.seVariableNameByBoth, SolidEdgeConstants.VariableVarType.SeVariableVarTypePMIDimension) For i = 1 To variableList.Count Dim variable As Object variable = variableList.Item(i) If variable.Type = SolidEdgeFramework.ObjectType.igDimension Then Dim dimension = DirectCast(variable, SolidEdgeFrameworkSupport.Dimension) Dim numDiscreteValues As Integer Dim discreteValues As Array 'crashes in this line - Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)) 'tried using Double() instead of Array, and it didnt work as well dimension.GetDiscreteValues(numDiscreteValues, discreteValues) System.Diagnostics.Debug.WriteLine(numDiscreteValues) End If System.Diagnostics.Debug.WriteLine(variable.DisplayName) System.Diagnostics.Debug.WriteLine(variable.ExposeName) System.Diagnostics.Debug.WriteLine(variable.SystemName) System.Diagnostics.Debug.WriteLine(variable.Type) System.Diagnostics.Debug.WriteLine(variable.Formula) Next

 

 

3 REPLIES

Re: Exception when calling GetDiscreteValues in Dimension

I don't have my handy dandy C# to VB converter at the moment but in C#, you need to initialize the array like this:

 

discreteValues = Array.CreateInstance(typeof(double), 0);

 

before your call to:

 

dimension.GetDiscreteValues(numDiscreteValues, discreteValues)

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Exception when calling GetDiscreteValues in Dimension

Ty man! Spot on! Problem solved.

 

Would you know how to extract the min an max limit values from the variable? It seems the API does exposes these values.

Re: Exception when calling GetDiscreteValues in Dimension

Sure thing. Again, C# code but you can figure it out.

 

// The following lines are just setup code to populate the array since I'm in a hurry.
var discreteValues = Array.CreateInstance(typeof(double), 3);
discreteValues.SetValue(1.0, 0);
discreteValues.SetValue(2.0, 1);
discreteValues.SetValue(3.0, 2);

// This code is what you're after.
var min = discreteValues.OfType<double>().Min();
var max = discreteValues.OfType<double>().Max();
Jason Newell
Applications Architect
www.jasonnewell.net