Hi,
I am creating new corridor with some of baselines and regions of existing one and used below code to copy targets from one region to another.
We could set all targets from one region to another except slope or elevation targets.
We are getting an error that "Unexpected error copying targets. Value does not fall within the expected range".
Please guide us.
Please find attached *.PNG for reference.
/*private void AssignTargets( BaselineRegion reg, BaselineRegion regNew, Baseline bl )
{
var targetsNew = regNew.GetTargets();
var targets = reg.GetTargets();
for ( int i = 0; i < targets.Count; i++ ) {
AssignTarget( targets[i], targetsNew[i], bl.Name, reg.Name );
}
regNew.SetTargets( targetsNew );
}
private void AssignTarget( SubassemblyTargetInfo stiSource, SubassemblyTargetInfo stiTarget, string blName, string regName )
{
var ids = new ObjectIdCollection();
try {
foreach ( ObjectId id in stiSource.TargetIds ) {
ids.Add( id );
}
stiTarget.TargetIds = ids;
if ( stiSource.TargetIds.Count > 1 && stiTarget.TargetIds.Count > 1 ) {
stiTarget.TargetToOption = stiSource.TargetToOption;
}
} catch {
var newIds = new ObjectIdCollection();
try {
foreach ( ObjectId id in ids ) {
if ( string.Compare( id.ObjectClass.DxfName, RXObject.GetClass( typeof( FeatureLine ) ).DxfName, true ) != 0 ) {
newIds.Add( id );
} else {
var fl = (FeatureLine)id.GetObject( OpenMode.ForRead );
Editor.WriteMessage( "Could not assign target:{0} Baseline: {1}{0} Region: {2}{0} Feature line name: {3}{0} Target type: {4}", System.Environment.NewLine, blName, regName, fl.Name, stiSource.TargetType.ToString() );
}
}
stiTarget.TargetIds = newIds;
} catch ( System.Exception ex ) {
Editor.WriteMessage( "Unexpected error copying targets. {0}", ex.Message );
}
}
}*/
Thanks in advance.
Regards,
Rahul