Solved! Go to solution

Getting variables

I was following a tutorial on modifying assemblies, and it features this code:


oVars.Edit("ShaftDiameter", txtShaftDiameter.Text);


I'm looking for but fail to find a way to do something like this:


txtShaftDiameter.Text = ovars.Get("ShaftDiameter");


Accepted by topic author AlanBaljeu
‎08-26-2015 04:32 AM

Re: Getting variables

txtShaftDiameter.Text = oVars.Item("ShaftDiameter").Value

So you were almost there Smiley Happy


I will be covering this in the next installment of the Automation series, but it's not about assemblies - that's slated for the farther next tutorial.



Tushar Suradkar


Re: Getting variables

Thank you.  This works.  Next problem: I got a part to change size, but the assembly didn't adapt.

Re: Getting variables

Can you elaborate more on the issue - with more details.

Are you changing the size of the part from an assembly via peer variables ?

Any pictures or video would be of great help to understand the problem.




Re: Getting variables

Using this code.  Basically reading data from XML and putting that data into part dimensions, specifically setting the formula. When the sizes change, the parts are updated in the assembly view, but the part positions are not.  Until I click on Update Structure, then everything is good.


private static void SetSizeVariables(SolidEdgeAssembly.Occurrences occurrences)
PlateSetter plateSetter = new PlateSetter();

foreach (var oc in occurrences)
SolidEdgeAssembly.Occurrence moldo = oc as SolidEdgeAssembly.Occurrence;

foreach (object parto in moldo.SubOccurrences)
SolidEdgeAssembly.SubOccurrence part = (SolidEdgeAssembly.SubOccurrence)parto;
var doc = (SolidEdgePart.PartDocument) part.SubOccurrenceDocument;
Console.WriteLine("File ({0})", doc.FullName);

var variables = (SolidEdgeFramework.Variables)doc.Variables;
string plateName = Path.GetFileNameWithoutExtension(doc.FullName);

XElement xmlplate = plateSetter.XmlPlate(plateName);
if (xmlplate != null)
ProcessVariables(variables, xmlplate);
static void ProcessVariables(SolidEdgeFramework.Variables variables, XElement xmlplate)

SolidEdgeFramework.VariableList variableList = null;
dynamic variableListItem = null; // In C#, the dynamic keyword is used so we don't have to call InvokeMember().

// Get a reference to the variablelist.
variableList = (SolidEdgeFramework.VariableList)variables.Query(
pFindCriterium: "*",
NamedBy: SolidEdgeConstants.VariableNameBy.seVariableNameByBoth,
VarType: SolidEdgeConstants.VariableVarType.SeVariableVarTypeBoth);

// Process variables.
for (int i = 1; i <= variableList.Count; i++)
// Get a reference to variable item.
variableListItem = variableList.Item(i);

// Determine the variable item type.
SolidEdgeConstants.ObjectType objectType = (SolidEdgeConstants.ObjectType)variableListItem.Type;

Console.WriteLine("Variable({0}) is of type '{1}'", i, objectType);

// Process the specific variable item type.

SolidEdgeFramework.variable variable = null;
SolidEdgeFrameworkSupport.Dimension dimension = null;

switch (objectType)
case SolidEdgeConstants.ObjectType.igDimension:
dimension = (SolidEdgeFrameworkSupport.Dimension)variableListItem;
Console.WriteLine("Dimension {0} = {1}", dimension.Name, dimension.Value);

string xname = dimension.DisplayName.ToLower();
XElement xdim_element = xmlplate.Element(xname);
string val = xdim_element.Attribute("value").Value;
dimension.Formula = val;

//dimension.Value = 3.0 * 0.0254;
case SolidEdgeConstants.ObjectType.igVariable:
variable = (SolidEdgeFramework.variable)variableListItem;
Console.WriteLine("Variable {0} = {1}", variable.Name, variable.Value);

//variable.Value = 3.0 * 0.0254;
// Other SolidEdgeConstants.ObjectType's may exist.


Re: Getting variables

I could only find time to lookup the SDK for 'Update' and came up with the following:



All of which apply to the main assembly doument. See if one of these helps.




Re: Getting variables

UpdateAll() seems to do the trick.  I got lost among the myriad of Update() methods in the API and couldn't figure out where to start.  Thank you.

Re: Getting variables

Thanks for confirming, for it was just a guess.




Re: Getting variables

[ Edited ]

I don't know why, but now this call is no longer effective.  Clicking on "Update Level" in Solid Edge works, but calling this does nothing.  


Edit: Restarting Solid Edge and my program fixed this.  Odd, because every other operation worked normally.