Message 1 of 10
SubassemblyTargetInfo.TargetIds error with FeatureLines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am seeing the error (Value does not fall within the expected range.) being thrown whenever the new ObjectIdCollection contains a Featureline (Auto Corridor Featurelines work though) and I try SubassemblyTargetInfo.TargetIds = newObjectIdCollection. Anyone else come across this error?
Sample code to play with:
[CommandMethod( "TargetExample" )]
public void RunCommand()
{
var id = SelectTarget();
var db = Application.DocumentManager.MdiActiveDocument.Database;
var ed = Application.DocumentManager.MdiActiveDocument.Editor;
var civilDoc = CivilApplication.ActiveDocument;
using ( var trans = db.TransactionManager.StartTransaction() )
{
try
{
var alignmentId = civilDoc.GetAlignmentIds()[0];
var alignment = trans.GetObject( alignmentId, OpenMode.ForRead ) as Alignment;
var profileId = alignment.GetProfileIds()[0];
var assemblyId = civilDoc.AssemblyCollection[0];
var newCorridorId = civilDoc.CorridorCollection.Add( "Proposed Corridor", "Proposed Baseline", alignmentId, profileId, "Proposed BaselineRegion", assemblyId );
var corridor = trans.GetObject( newCorridorId, OpenMode.ForWrite ) as Corridor;
var subtargetinfocoll = corridor.GetTargets();
for ( int i = 0; i < subtargetinfocoll.Count; i++ )
{
var subassemblytargetinfo = subtargetinfocoll[i];
if ( subassemblytargetinfo.TargetType == SubassemblyLogicalNameType.Offset )
{
var ids = new ObjectIdCollection();
ids.Add( id );
subassemblytargetinfo.TargetIds = ids;
}
}
corridor.SetTargets( subtargetinfocoll );
corridor.Rebuild();
trans.Commit();
}
catch ( Exception ex )
{
ed.WriteMessage( "\nError: {0}\nTarget type: {1}",
ex.Message, id.ObjectClass.DxfName );
}
}
}
private ObjectId SelectTarget()
{
var result = ObjectId.Null;
var peo = new PromptEntityOptions( "\nSelect the corridor offset target" );
var per = Application.DocumentManager.MdiActiveDocument.Editor.GetEntity( peo );
switch ( per.Status )
{
case PromptStatus.OK:
{
result = per.ObjectId;
}
break;
default:
break;
}
return result;
}