Problems with modify variables

[ Edited ]



I`m beginner in SE programing and i have some problem. . .

how do I connect to a variable that is already in the Solid Edge variable table and modify it ?

I want write some value in TextBox and then change the dimensions but i stop in  deadlock

Public Class Form1

    'Declare the program variables.

    Dim objApp As Object

    Dim objVariables As Object

    Dim objDims As Object

    Dim objDim1 As Object

    Dim objDim2 As Object

    Dim objNamedDim As Object






    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub


    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click


    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



        'Connect to a running instance of Solid Edge.

        objApp = GetObject(, "SolidEdge.Application")


        'Access the Variables collection.

        objVariables = objApp.ActiveDocument.Variables

        objDim1.Value = Val(TextBox1)

        objDim2.Value = Val(TextBox2)



    End Sub

End Class


Any help would be greatly appreciated!


Posted by: Rafa P
Post date: 6/3/2009 11:07:34 AM


RE: Problems with modify variables

[ Edited ]


You can use following function:




Posted by: Mithun **bleep**ole
Post date: 6/4/2009 8:06:14 PM

RE: Problems with modify variables

[ Edited ]

Dim value As Double ????


Posted by: Rafa P
Post date: 6/4/2009 10:56:56 PM

RE: Problems with modify variables

[ Edited ]

Posted By rafael86 on 06/05/2009 3:56 AM

Dim value As Double ????


yea, also you can specify formula (like sin(30)) if required.

But you may encounter problems while pushing negative values using edit function.


Posted by: Mithun **bleep**ole
Post date: 6/4/2009 11:12:29 PM

RE: Problems with modify variables

[ Edited ]

hmmm . . . i understand that

value = val(TextBox1)



Posted by: Rafa P
Post date: 6/4/2009 11:47:09 PM

RE: Problems with modify variables

[ Edited ]

I use this way of editing existing variables;


Dim strValue as String

Dim strName as String


strValue = TextBox1.value

strName = "MyVar"


objVariables.Edit strName, strValue


Note that the value is declared as a String (it works fine). I'm not really sure if a double works since you are editing the formula of the variable.






Posted by: Wouter Sloof
Post date: 6/8/2009 2:05:47 AM

RE: Problems with modify variables

[ Edited ]

Some tricks when playing with variables:

You can assign a variable value with:

1. objVariables.Edit(strName, strValue)

2. objVariable.Formula=strValue

3. objVariable.SetValue(strValue)

4. objVariable.value=dblValue


5. objVariables.EditFromClipboard(strName)


Numbers 1,2, and 3: strValue must be a string


Numbers 1 and 2: strValue can be a formula.


Numbers 1, 2 and 3 can accept strings with a value and a unit. For example:

strValue="3 mm" or strValue="3 in" (very useful to convert units without headaches)

Be careful if sending a string with literal values with decimals. Decimal separator must be correct.

This is a problem in Spain, for example, where a lot of people use "," as decimal separator and others use "."

If your Windows decimal separator is "," (for example) you cannot assign strValue="3.5 mm" you must use "3,5 mm"

So if in your country you don't use "." your program may fail depending on the computer that runs your program.


Number 4 must be a number (a double by default).

Units are internal SE units so you must send distance values in meters and angle values in radians


Number 5 is used to link up with Excel.


dim rng as Microsoft.Office.Interop.Excel.Range




'In SE you do and get the link from cell "A1" from clipboard

objVariables.EditFromClipboard("Length") 'Variable Length must exist.


More tricks:

When you want to get a variable by name you can do it in two ways:

objVariables.Item("Length") 'This returns a Variable object. It will fail if it is a Dimension!!!

You know that in Variable Table you have Dimension and Variable objects (marked as "Dim" and "Var"


If you search for "Length" and you want to get it even if it is a Dim or Var then you do:

Dim objMyVar as Object 'Very Important to declare this as Object. If declared as Variable it will generate an error and you won't get Dimension objects and viceversa.

Dim qo as Object 'This is a QueryObjects collection. It can be treated as a simple collection of objects. Index starts in 1, not 0

qo=objVariables.Query("Length") 'This will return one var or dim "Length" if exists. If you would like to find all the var and dim starting with "L" you could do a qo=objVariables.Query("L*")

qo.item(1).Value=0.003 'qo.item(1) is the var or dim "Length"






Posted by: Julian Guillo
Post date: 6/8/2009 5:48:51 AM

RE: Problems with modify variables

[ Edited ]

Thanks for this comprehensive answer Smiley Happy


Beer for you, i also thanks another users Smiley Very Happy


Posted by: Rafa P
Post date: 6/8/2009 8:06:57 AM

RE: Problems with modify variables

[ Edited ]

Whow! Impressive Julian! This has cleared a lot. In the past I also had problems with getting the values of dimensions, and now I know why (I didn't knew there is a difference between a Dimension an a Variable..)




Posted by: Wouter Sloof
Post date: 6/8/2009 8:32:19 PM

RE: Problems with modify variables

[ Edited ]

Nice post Julian - will make it easier for a lot of people.


Just a tip for .Net users:


If you need to get a number with the correct decimal seperator you can use the following:


double dbl = 2.5;


/* Check the current culture */



/* Format the string using the current culture */



/* Change the culture */

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");


/* Format the string using the new culture */



/* Format the string using a different culture */

Console.WriteLine(dbl.ToString(new System.Globalization.CultureInfo("es-PR")));


/* Format the string using the invariant culture */



/* Note: The CurrentUICulture is used for formatting the display of text in controls etc.

* whereas the CurrentCulture is used for variables etc.

* There is also the System.Globalization.CultureInfo.CurrentCulture (and CurrentUICulture)

* but these are read-only.

* DISCLAIMER: This is all from memory and I'm too lazy to look it up again in msdn. If you

* want more information about thread cultures and string formatting then read up in the

* visual studio help or msdn.

* Here is a list of culture names:








Posted by: Calum McLellan
Post date: 6/8/2009 9:30:53 PM