API to set “Target Mapping => Object Name” is not available in SubassemblyTarget

API to set “Target Mapping => Object Name” is not available in SubassemblyTarget

Anonymous
Not applicable
1,492 Views
4 Replies
Message 1 of 5

API to set “Target Mapping => Object Name” is not available in SubassemblyTarget

Anonymous
Not applicable

Hi,

I am creating new corridor from existing one from APIs.

While doing so I need to set target property to each Baseline regions.

I used “BaselineRegion.GetTargets()” method to get targets and “BaselineRegion.SetTargets()” to set updated targets.

But in SubassemblyTargetInfoCollection, I did not found any API for “Object Name”, so I am unable to set this value.

Please guide me to resolve this issue.

 

Thanking you for all your help,

Mahesh

 

0 Likes
Accepted solutions (1)
1,493 Views
4 Replies
Replies (4)
Message 2 of 5

tyronebk
Collaborator
Collaborator
Accepted solution

I've used these to copy targets from one region to another. It is not overly robust as it assumes that both regions use the same assembly.

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

Note that at one time there was a bug that prevented you from being able to assign a feature line as a target via the API. I haven't tested recently so I'm not sure if it's been fixed.

Message 3 of 5

Anonymous
Not applicable
Thank you.
It is working well for my scenario.
-Mahesh
0 Likes
Message 4 of 5

Anonymous
Not applicable

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

 

0 Likes
Message 5 of 5

tyronebk
Collaborator
Collaborator

You are going to have to give us a bit more to go on. What release of C3D are you using? What subassembly is used for the source? I'm not familiar with a subassembly that lets you specify an alignment as an elevation target. Which line of code throws the error? Can you provide an example drawing where this is failing? It would also be easier for us if you could post all relevant code so that we can properly debug your command.

0 Likes