Hello guys & gals,
The company I work for recently bought Solid Edge and Microsoft Visual Studio 2005 and I need help! My question is, how do I connect to a variable that is already in the Solid Edge variable table and modify it? I can use the following script to add a variable and modify the value of that variable, but being the newbie that I am, I can't figure out how to modify a variable that is already in the variable table.
Any help would be greatly appreciated!
ImportsSystem.Runtime.InteropServicesPublic Class Form1PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.LoadDim objApplication As SolidEdgeFramework.Application = NothingDim objPart As SolidEdgePart.PartDocument = NothingDim objVariables As SolidEdgeFramework.Variables = NothingDim objVariable As SolidEdgeFramework.variable = NothingTry' 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'Add a variable objVariable = objVariables.Add("Dim0", "1")'Change the formula of the variable to a function objVariable.Formula = Math.Sin(0.1).ToString()'Change the name of the variable objVariable.Name = "Dim1"'Change the value of the variable. This will not change the value of the variable objVariable.Value = 1'Change the formula of the variable to a static value This causes the formula to be removed and sets the valueobjVariable.Formula = "456"'Change the value of the variable. It works now objVariable.Value = 789'Delete the variable objVariable.Delete()Catch ex As ExceptionConsole.WriteLine(ex.Message)FinallyIfNot (objVariable IsNothing) ThenMarshal.ReleaseComObject(objVariable)objVariable = NothingEndIfIfNot (objVariables IsNothing) ThenMarshal.ReleaseComObject(objVariables)objVariables = NothingEndIfIfNot (objPart IsNothing) ThenMarshal.ReleaseComObject(objPart)objPart = NothingEndIfIfNot (objApplication IsNothing) ThenMarshal.ReleaseComObject(objApplication)objApplication = NothingEndIfEndTryEndSubClassEnd
Posted by: Eddie Miller
Post date: 12/2/2008 8:29:46 AM
You need to use the Query method, passing it the name of the variable (you can also use wildcards). Sorry, couldn't find a decent code example but this should get you started:
Dim results As VariableList
results = objVariables.Query("MyVariable")
Debug.WriteLine(results.Item(1).Name) 'Pretty sure it's a 1-based collection
Hope this helps
Posted by: Calum McLellan
Post date: 12/2/2008 9:35:05 PM