set parameters in subassembly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I try to set parameters in a subassembly by C#. I followed https://knowledge.autodesk.com/support/autocad-civil-3d/learn-explore/caas/CloudHelp/cloudhelp/2017/...
but when I run the script the parameter is changed if I read the parameters, but the parameter in the subassembly itself it's not changed. How do I change a parameter of a subassembly in a corridor?
CivilDocument doc = CivilApplication.ActiveDocument;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Editor _editor = Application.DocumentManager.MdiActiveDocument.Editor;
using (Transaction ts = Application.DocumentManager.MdiActiveDocument.
Database.TransactionManager.StartTransaction())
{
string corridorname = "COR_ALM_N_2016";
//get the corrdior by name:
ObjectId corridorId = doc.CorridorCollection[corridorname];
Corridor corridor = ts.GetObject(corridorId, OpenMode.ForRead) as Corridor;
//get the first applied subassembly in the first assembly in the first BaselineRegion:
BaselineRegion baselineregion = corridor.Baselines[0].BaselineRegions[0];
AppliedAssembly appliedassembly = baselineregion.AppliedAssemblies[0];
AppliedSubassembly appliedsubassembly = appliedassembly.GetAppliedSubassemblies()[0];
var adds = appliedassembly.GetAppliedSubassemblies();
ed.WriteMessage("\nAantal subassemblies {0}\n", adds.Count);
//get parameter key names:
foreach (IAppliedSubassemblyParam parama in appliedsubassembly.Parameters)
{ ed.WriteMessage("\nParameter key name: {0} & {1} & {2}\n", parama.KeyName, parama.ValueAsObject, parama.ValueType); }
foreach (var p in appliedsubassembly.Parameters)
{
_editor.WriteMessage("Parameter information: name: {0}, value type: {1}\n", p.KeyName, p.ValueType);
Object vobj = p.ValueAsObject;
if (p.ValueType == typeof(System.String))
{ _editor.WriteMessage("Parameter string value: {0}\n", (String)vobj); }
else if (p.ValueType == typeof(System.Double))
{ _editor.WriteMessage("Parameter double value: {0}\n", (Double)vobj); }
else if (p.ValueType == typeof(System.Int32))
{ _editor.WriteMessage("Parameter int32 value: {0}\n", (Int32)vobj); }
else if (p.ValueType == typeof(System.Boolean))
{ _editor.WriteMessage("Parameter bool value: { 0}\n", (Boolean)vobj); }
// we should never get here:
else { _editor.WriteMessage("Unexpected type.\n"); }
}
// Check whether a parameter exists
bool result = appliedsubassembly.Contains("Bteen");
// Change a parameter’s value
AppliedSubassemblyParam<double> param = appliedsubassembly.GetParameter<double>("Bteen");
ed.WriteMessage("\nValue before {0}m dik {1}\n", param.KeyName, param.Value);
param.Value = 4.0;
appliedsubassembly.GetParameter<double>("Bteen").Value = 4.0;
ed.WriteMessage("\nValue after {0}m dik {1}\n", param.KeyName, param.Value);
}