CorridorSetTargets Method

Sets the target information. The updatedTargets parameter is a SubassemblyTargetInfoCollection object that should be obtained from the GetTargets() method.

Namespace: Autodesk.Civil.DatabaseServices
Assembly: AeccDbMgd (in AeccDbMgd.dll) Version: 13.8.0.292
Syntax
public void SetTargets(
	SubassemblyTargetInfoCollection updatedTargets
)

Parameters

updatedTargets  SubassemblyTargetInfoCollection
 
Exceptions
ExceptionCondition
ArgumentException Thrown when the updatedTargets object has not been acquired through the GetTargets() method.
Remarks

The updatedTargets object must be acquired through the GetTargets() method before making any modifications.

Example
C#
 1// Test command SetTargets by using tutorial file "Corridor-5c.dwg".
 2[CommandMethod(ReferenceGuideSample.GoupId, "SetTargets", CommandFlags.Modal)]
 3public void SetTargets()
 4{
 5    using (Transaction tr = startTransaction())
 6    {
 7        // Create feature lines that will be used as target later.
 8        ObjectId oidF1 = CreateFeatureLine("FL1", new Point2dCollection(new Point2d[] { new Point2d(3679, 4453), new Point2d(4046, 4633) }));
 9        ObjectId oidF2 = CreateFeatureLine("FL2", new Point2dCollection(new Point2d[] { new Point2d(4339, 3643), new Point2d(4653, 3780) }));
10
11        // Target info can be gotten by different object level: Baseline Region, Baseline, Corridor.
12        Corridor corridor = _civildoc.CorridorCollection["Corridor - (1)"].GetObject(OpenMode.ForWrite) as Corridor;
13        Baseline baseline = corridor.Baselines["Baseline (1)"];
14        BaselineRegion baselineRegion = baseline.BaselineRegions[0];
15        SubassemblyTargetInfoCollection saTargetInfoCol = baselineRegion.GetTargets();
16
17        // Target info can be set by different object level: Baseline Region, Baseline, Corridor.
18        SubassemblyTargetInfo saTargetInfo = FindSATargetInfo(saTargetInfoCol, "LaneSuperelevationAOR - (Left)", "Width Target", SubassemblyLogicalNameType.Offset);
19        saTargetInfo.TargetIds = new ObjectIdCollection(new ObjectId[] { oidF1, oidF2 });
20        saTargetInfo.TargetToOption = SubassemblyTargetToOption.Nearest;
21        saTargetInfo.UseSameSideTarget = true;
22        baselineRegion.SetTargets(saTargetInfoCol); // Set target back to make corridor out of date
23
24        // Rebuild the corridor after corridor is out of date.
25        corridor.Rebuild();
26
27        tr.Commit();
28    }
29}
30private SubassemblyTargetInfo FindSATargetInfo(SubassemblyTargetInfoCollection saTargetInfoCol, string saName, string targetDisplayName, SubassemblyLogicalNameType targetType)
31{
32    for (int i = 0; i < saTargetInfoCol.Count; ++i)
33    {
34        SubassemblyTargetInfo saInfo = saTargetInfoCol[i];
35        if (saInfo.SubassemblyName == saName && saInfo.DisplayName == targetDisplayName && saInfo.TargetType == targetType)
36        {
37            return saInfo;
38        }
39    }
40    return null;
41}
42
43private ObjectId CreateFeatureLine(string name, Point2dCollection points)
44{
45    Polyline polyline = new Polyline();
46    int index = 0;
47    foreach (Point2d p in points)
48    {
49        polyline.AddVertexAt(index++, p, 0, 0, 0);
50    }
51    ObjectId oidPolyline = AddEntityToDatabase(polyline);
52    return FeatureLine.Create(name, oidPolyline);
53}
54private ObjectId AddEntityToDatabase(Autodesk.AutoCAD.DatabaseServices.Entity obj)
55{
56    ObjectId objId = ObjectId.Null;
57    Database db = HostApplicationServices.WorkingDatabase;
58    using (Transaction trans = db.TransactionManager.StartTransaction())
59    {
60        BlockTable bt = (BlockTable)db.TransactionManager.GetObject(db.BlockTableId, OpenMode.ForRead, false);
61        BlockTableRecord btr = db.TransactionManager.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
62        objId = btr.AppendEntity(obj);
63        trans.AddNewlyCreatedDBObject(obj, true);
64        trans.Commit();
65    }
66    return objId;
67}
See Also