Civil 3D 二次开发 名称模板不能正常工作

时间:2022-11-18 11:13:28
using Autodesk.AECC.Interop.Land;
using Autodesk.AECC.Interop.UiLand;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.Settings;
[assembly: CommandClass(typeof(NameTemplate.NameTemplateTest))]
namespace NameTemplate
{
class NameTemplateTest
{
string m_sAeccAppProgId = "AeccXUiLand.AeccApplication.11.0";
protected Document doc;
protected Database db;
protected Editor ed;
protected CivilDocument civilDoc;
ObjectId alignmentId;
ObjectId samplineGroupId; private IAcadApplication m_oAcadApp = null;
private IAeccApplication m_oAeccApp = null;
private IAeccDocument m_oAeccDoc = null;
private IAeccDatabase m_oAeccDb = null; AeccAlignment comAlignment;
AeccSampleLineGroup comSLG; public NameTemplateTest()
{
doc = Application.DocumentManager.MdiActiveDocument;
ed = doc.Editor;
db = doc.Database;
civilDoc = CivilApplication.ActiveDocument; m_oAcadApp = (IAcadApplication)Application.AcadApplication;
if (m_oAcadApp != null)
{
m_oAeccApp = (IAeccApplication)m_oAcadApp.GetInterfaceObject(m_sAeccAppProgId);
m_oAeccDoc = (IAeccDocument)m_oAeccApp.ActiveDocument;
m_oAeccDb = (IAeccDatabase)m_oAeccApp.ActiveDocument.Database;
}
}
public void ComNameTemplateTest()
{
if (m_oAeccDoc == null) return;
string name = m_oAeccDoc.Settings.AlignmentSettings.NameTemplate.Value;
object alignmentStyle = m_oAeccDoc.AlignmentStyles[];
object alignmentLadelset = m_oAeccDoc.AlignmentLabelStyleSets[];
string slgName = m_oAeccDoc.Settings.SampleLineSettings.GroupNameTemplate.Value;
AeccGroupPlotStyle GroupPlotStyle = m_oAeccDoc.GroupPlotStyles[];
AeccSampleLineStyle SampleLineStyle = m_oAeccDoc.SampleLineStyles[];
AeccLabelStyle SampleLineLabelStyle = m_oAeccDoc.SampleLineLabelStyles[];
string slName = m_oAeccDoc.Settings.SampleLineSettings.NameTemplate.Value;
double[] sp = new double[] { , , };
double[] ep = new double[] { , , }; for (int i = ; i < ; i++)
{
comAlignment = m_oAeccDoc.AlignmentsSiteless.Add(
name, "", alignmentStyle, alignmentLadelset);
comAlignment.Entities.AddFixedLine1(sp,ep);
for (int j = ; j < ; j++)
{
comSLG = comAlignment.SampleLineGroups.Add(
slgName, "", GroupPlotStyle, SampleLineStyle, SampleLineLabelStyle); double[] stations = new double[] { , , , , }; foreach (double sta in stations)
{
comSLG.SampleLines.AddByStation(slName, sta, , );
}
}
} } public void CreateSurfaceTest()
{
string name = civilDoc.Settings.GetSettings<
SettingsCmdCreateSurface>().NameFormat.Surface.Value;
//Create 3 TinSurface
for (int i = ; i < ; i++)
{
TinSurface.Create(db, name);
}
}
public void CreateSampleLineGroupTest()
{
if (alignmentId == ObjectId.Null) return;
try
{ string name = civilDoc.Settings.GetSettings<
SettingsSampleLine>().NameFormat.SampleLineGroup.Value;
//Create 3 SampleLineGroup
for (int i = ; i < ; i++)
{
samplineGroupId = SampleLineGroup.Create(name, alignmentId);
} }
catch (System.Exception ex)
{
ed.WriteMessage("\n" + ex.Message);
}
}
public void CreateSampleLineTest()
{
if (samplineGroupId == ObjectId.Null) return;
try
{ string name = civilDoc.Settings.GetSettings<
SettingsSampleLine>().NameFormat.SampleLine.Value;
double[] stations = new double[] { , , , , }; foreach (double sta in stations)
{
SampleLine.Create(name, samplineGroupId, sta);
}
}
catch (System.Exception ex)
{
ed.WriteMessage("\n" + ex.Message);
}
} public void CreateAlignmentTest()
{
try
{
string name = civilDoc.Settings.GetSettings<
SettingsCmdCreateAlignmentLayout>()
.DefaultNameFormat.AlignmentNameTemplate.Value;
ObjectId layerId;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable layertable = db.LayerTableId.GetObject(
OpenMode.ForRead) as LayerTable;
layerId = layertable[""];
tr.Commit();
}
ObjectId styleId = civilDoc.Styles.AlignmentStyles[];
ObjectId labelsetId = civilDoc.Styles.LabelSetStyles
.AlignmentLabelSetStyles[];
for (int i = ; i < ; i++)
{
alignmentId= Alignment.Create(
civilDoc, name, ObjectId.Null, layerId, styleId, labelsetId);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Alignment al = alignmentId.GetObject(OpenMode.ForWrite) as Alignment;
al.Entities.AddFixedLine(new Point3d(, , ), new Point3d(, , ));
tr.Commit();
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage("\n" + ex.Message);
}
} [CommandMethod("ComTest")]
public void ComTest()
{
NameTemplateTest ntt = new NameTemplateTest();
ntt.ComNameTemplateTest();
}
[CommandMethod("NetTest")]
public void NetTest()
{
NameTemplateTest ntt = new NameTemplateTest();
ntt.CreateSurfaceTest();
ntt.CreateAlignmentTest();
ntt.CreateSampleLineGroupTest();
ntt.CreateSampleLineTest(); }
}
} 使用NET API,曲面名称模板可以正常工作,采样线和路线名称模板不能正常工作。  使用COM API 路线的采样线名称模板正常工作,采样线编组不行。 Civil 3D 二次开发 名称模板不能正常工作
Civil 3D 二次开发 名称模板不能正常工作