Getting variables

Valued Contributor
Valued Contributor

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");

 

8 REPLIES

Re: Getting variables

Phenom
Phenom

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.

 

Regards,

Tushar Suradkar

http://www.cadvertex.com

http://surfandcode.blogspot.in

 

Re: Getting variables

Valued Contributor
Valued Contributor

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

Re: Getting variables

Phenom
Phenom

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.

 

Regards,

 

Re: Getting variables

Valued Contributor
Valued Contributor

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;
break;
case SolidEdgeConstants.ObjectType.igVariable:
variable = (SolidEdgeFramework.variable)variableListItem;
Console.WriteLine("Variable {0} = {1}", variable.Name, variable.Value);

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

}
}

Re: Getting variables

Phenom
Phenom

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

UpdateAll()
UpdateLink()
UpdateStructureCache(1)

 

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

 

Regards,

 

Re: Getting variables

Valued Contributor
Valued Contributor

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

Phenom
Phenom

Thanks for confirming, for it was just a guess.

 

Regards,

 

Re: Getting variables

Valued Contributor
Valued Contributor

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.