Showing results for 
Search instead for 
Did you mean: 

Accessing variable table variables

Valued Contributor
Valued Contributor

I am trying to access all of the variables in a part variable table so I can export the name/value pairs to a csv file. I have everything sorted except for an error which occurs on the second pass through the for-each loop. The test count returns a value of 4 which is a little confusing as there are only two variables defined in a new part (created from template - no geometry), PhysicalProperties_Density and PhysicalProperties_Accuracy. One thing I noticed is that if I add some geometry and some dimensions to the part file, the variable table shows these but the count remains at 4. If I add a user variable to the parts variable table the count increases to 5.


Anyway the output to the immediate window (assuming a blank part is used) is:




A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll


And the code (stripped down to only show the basics of the problem) is:


[code type=vbnet]Imports System.Runtime.InteropServices


Module Program

Sub Main()

Dim objApplication As SolidEdgeFramework.Application = Nothing

Dim objPart As SolidEdgePart.PartDocument = Nothing

Dim objVariables As SolidEdgeFramework.Variables = Nothing

Dim objVariable As SolidEdgeFramework.variable = Nothing




' Connect to a running instance of Solid Edge

objApplication = Marshal.GetActiveObject("SolidEdge.Application")


' Get a reference to the active document

objPart = objApplication.ActiveDocument


' Get a reference to the variables collection

objVariables = objPart.Variables


'Check number of variables in collection



For Each objVariable In objVariables




Catch ex As Exception




End Try

End Sub

End Module[/code]


Please help with this. It's doing my head in.


Posted by: Dan Lanigan
Post date: 3/7/2013 10:11:21 PM


Accessing variable table variables

Valued Contributor
Valued Contributor

Hold on a minute, I just found this thread:


I think this solves my problem. If it does, I'll post the working code here for anyone who's interested. Thanks Jason!


Posted by: Dan Lanigan
Post date: 3/8/2013 1:52:42 AM