Showing results for 
Search instead for 
Did you mean: 

Reading Variables from a part


Hey everyone

I have been trying to figure out a way to read the values from the variable table of a part, and I have tried a few different suggestions found either on here or in the SDK documentation. 

I can read the value of a Variable object using: 


but getting that assigning the right variable is proving very difficult. 


Using the Variables class's Item() method won't work when given the variable name as I have seen and when given an index it either returns a value that isn't in the table or repeats a previous one. In the code below the output is the density, the physical property accuracy, the physical property accuracy (again), and then the density (again). (or other order of those 2)




 documents = objApplication.Documents
 Dim vVars As SolidEdgeFramework.Variables = Nothing
 Dim objPart As SolidEdgePart.PartDocument = Nothing
 Dim objVars(4) As SolidEdgeFramework.variable
 Dim objVarsT As SolidEdgeFramework.variable = Nothing
 objPart = documents.Open(Core)
 vVars = objPart.Variables

 'doesn't work
 'objVars(1) = vVars.Item("D")
 'objVars(2) = vVars.Item("E")
 'objVars(3) = vVars.Item("F")
 'objVars(4) = vVars.Item("G")

 objVars(1) = vVars.Item(1)
 objVars(2) = vVars.Item(4)
 objVars(3) = vVars.Item(3)
 objVars(4) = vVars.Item(2)

 For i As Integer = 1 To 4
 MessageBox.Show(String.Format("{0}", objVars(i).Value), i.ToString)

 'doesn't work either
 'objVars(1) = vVars.Translate("D")
 'objVars(2) = vVars.Translate("E")
 'objVars(3) = vVars.Translate("F")
 'objVars(4) = vVars.Translate("G")


Things I have tried and didn't help:


I know its probably something simple, but I am still pretty new to this. 

Thanks Keegan




Re: Reading Variables from a part

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Hi Keegan, 

the Item method only accepts an integer parameter.

So you could loop throug all items an compare the name property of the returned Variable object.

I also found that Item(2) and Item(4) return a "corrupted" object, which throws an exeption when accessing the name property. The following code lists all variables.


   Dim vVars As SEFramework.Variables = Nothing
   Dim VarTemp As SEFramework.variable = Nothing
   Dim VarsTemp As SEFramework.VariableList = Nothing

   vVars = DirectCast(objDoc.Variables, SEFramework.Variables)

For i = 1 To vVars.Count VarTemp = DirectCast(vVars.Item(i), SEFramework.variable) Try Debug.Print(String.Format("({2}) Name {0}, Value {1}", VarTemp.Name, VarTemp.Value.ToString, i)) Catch ex As Exception Debug.Print(String.Format("Undefined Name index {0}", i)) End Try Next

If there is a Variable defined with name "Var1" then this works also:


VarTemp = DirectCast(vVars.Translate("Var1"), SEFramework.variable)

or this this finds all variables with name starting with "Var"

VarsTemp = DirectCast(vVars.Query("Var*"), SEFramework.VariableList)

For Each v As SEFramework.variable In VarsTemp

When your code does not retrun variable, then maybe you have Dimensions that you are searching. The variable table displayed in the Solid Edge User interface shows a mix of dimensions and variables (see first colum "Dim" or "Var"). That are different objects internally!

To find all these also use the query method:


VarList = DirectCast(PartVariables.Query("A",
                        False), SEFramework.VariableList)

Dim vType As SEFramework.ObjectType
Dim TempDim As SEFrameworkSupport.Dimension = Nothing
Dim TempVar As SEFramework.variable = Nothing

For Each v As Object In VarList
      vType = GetObjectType(v)
      If vType = SEFramework.ObjectType.igDimension Then
                            TempDim = DirectCast(v, SEFrameworkSupport.Dimension)
                            Debug.Print(String.Format("Name {0}, Display {1}", TempDim.Name, 
     ElseIf vType = SEFramework.ObjectType.igVariable Then
                            TempVar = DirectCast(v, SEFramework.variable)
     End If


 This returns the Dimension that is user renamed to "A"

I use a function that returns the object type of the COM object:

    Public Function GetObjectType(ComObject As Object) As SEFramework.ObjectType

        Return DirectCast(ComObject.GetType().InvokeMember("Type", Reflection.BindingFlags.GetProperty, Nothing, ComObject, Nothing), SEFramework.ObjectType)

    End Function

Hope this helps. 




Re: Reading Variables from a part


That works thanks.

I didn't know there was a difference between variables and dimensions as I had changed dimensions pretty easily lots before. I was trying to read a dimension value.

I had seen the samples on github that looked similar , but thought there had to be an easier way. But this stuff is just about over my head.

Thanks a lot.