在.Net中创建Civil 3D对齐会导致“对齐ID无效”错误

时间:2017-08-15 06:31:10

标签: c# .net autodesk ifc

我正在为Civil 3D开发一个IFC(行业基础类)导入/导出加载项,我将在本月晚些时候将其作为开源发布。导出功能已经完全正常。但是,我仍然不太了解如何使用.NET在Civil 3D中创建对象。我的加载项是用C#编写的。

我尝试了以下内容,这是Autodesk的官方示例:

// Uses an existing Alignment Style named "Basic" and Label Set Style named "All Labels" (for example, from
// the _AutoCAD Civil 3D (Imperial) NCS.dwt template.  This call will fail if the named styles
// don't exist. 
// Uses layer 0, and no site (ObjectId.Null)
ObjectId testAlignmentID = Alignment.Create(doc, "New Alignment", ObjectId.Null, "0", "Basic", "All Labels");

来源:https://knowledge.autodesk.com/support/autocad-civil-3d/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/Civil3D-DevGuide/files/GUID-F620DF41-7DF3-450F-8C2A-A92DEB1F9E9E-htm.html

但是,每当我尝试运行我的代码时,都会收到以下错误消息:“无效的对齐ID。”。我的代码如下所示:

var civilDatabase = Application.DocumentManager.MdiActiveDocument.Database;
var civilDocument = CivilApplication.ActiveDocument;
using (Transaction civilTransactionManager =
        civilDatabase.TransactionManager.StartTransaction())
{
   ObjectId civilAlignment = Alignment.Create(civilDocument, "MyName", "" , "0", "Basic", "All Labels");

我还尝试替换为 null ObjectID.Null 提供Alignment网站的“”,两者都不起作用并用 ObjectID.Null 替换它甚至阻止我编译。

任何人都知道错误来自哪里?

2 个答案:

答案 0 :(得分:0)

查看Alignment methods的文档,更具体地说是following重载:

B

它说:

  

System.ArgumentException

     

图纸,图层,样式,labelSet或网站的名称无效。对齐的名称已经存在。

所以似乎有些名字不正确。对于更强大的方法,您可以列出样式并从那里获取名称或objectId。对于无站点对齐,您可以将public static ObjectId Create( CivilDocument document, string alignmentName, string siteName, string layerName, string styleName, string labelSetName ) 作为string.empty参数传递。

答案 1 :(得分:0)

感谢您对Augusto的回答!我也这么认为,因为错误确实指向了那个方向。

然而,来自Autodesk的Jeff能够帮助我并提供了一个有效的解决方案。显然,这是我主要代码或我处理事物的方式的一个更大问题的一部分。 在下面的帖子中提供了Jeff的解决方案,我得到了一切:

https://forums.autodesk.com/t5/autocad-civil-3d-customization/creating-alignment-throws-quot-alignment-id-is-invalid-quot/m-p/7302387/highlight/false#M13831