Announcements

Announcement: We’re aware of an issue affecting starting a new topic from category pages and creating new blog posts. New topics can still be started directly from the relevant board. Learn more here.

SubassemblyTargetInfo.TargetIds error with FeatureLines

SubassemblyTargetInfo.TargetIds error with FeatureLines

tyronebk
Collaborator Collaborator
2,739 Views
9 Replies
Message 1 of 10

SubassemblyTargetInfo.TargetIds error with FeatureLines

tyronebk
Collaborator
Collaborator

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

 

2,740 Views
9 Replies
Replies (9)
Message 2 of 10

tyronebk
Collaborator
Collaborator

Forgot to mention that the code above was taken and modified from the code available here.

0 Likes
Message 3 of 10

Daniel.Du
Alumni
Alumni

Hi,

 

I think it pretty much depends on the drawing and which element do you select as target. Do you complete your operation with UI? If you can do it with UI but has problem with API, would you please send us a sample drawing and direct me which element I should select as corridor offset target to reproduce your problem? 



Daniel Du
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 4 of 10

tyronebk
Collaborator
Collaborator

You can use the attached drawing as a test. The original code provided by the Dev blog I based the sample on just said to use any of the help sample drawings. This drawing is based on Corridor 1a.dwg.

 

When you run the test command, all of the common target types work fine except the standard Featureline (as specified in the original post). Attaching a featureline target through the UI works fine.

 

I attached some new code to work a bit nicer with the example drawing.

0 Likes
Message 5 of 10

Daniel.Du
Alumni
Alumni

Thank you for the sample, I am contacting with engineering team for this issue, I will get back to you when I get a response.



Daniel Du
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 6 of 10

Daniel.Du
Alumni
Alumni
Thank you for the sample code and test drawing. 
 
Currently for the offset type, it only supports the following types:
AeccDbAlignment
AeccDbAutoFeatureLine
AeccDbAutoCorridorFeatureLine
AeccDbSvFigure
AcDbPolyline
AcDb2dPolyline
AcDb3dPolyline
 
AeccDbFeatureLine as the one in your test drawing is not supported in API yet.


Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 7 of 10

tyronebk
Collaborator
Collaborator

Thanks for looking into this Daniel.

 

Is there such a thing as a AeccDbAutoFeatureLine? I don't see a class for it and I haven't come across one in a drawing.

 

The API documentation simply calls for a FeatureLine:

When TargetType is Offset, the type of ObjectId should be Alignment, FeatureLine, SurveyFigure, Polyline, Polyline2d or Polyline3d.

 

0 Likes
Message 8 of 10

Daniel.Du
Alumni
Alumni

Thank you for the feedback, I've logged a change request to support AeccDbFeatureLine for API to engineering team.



Daniel Du
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 9 of 10

joantopo
Mentor
Mentor

I am in the same needs.

It is November 2016........ (2 YEARS LATER)  and there is no news in C3D 2017 SP1.1  API ¿?  WTF...

 

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
0 Likes
Message 10 of 10

Anonymous
Not applicable

Hi all,

 

I am facing similar problem with API.

It does not allow me to set feature line as offset target.

Is there any update on this issue?

 

Please suggest me if there is any other solution for this.

 

Thanking you,

Rahul.

0 Likes