Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to add a mesh ( well, in this case, it's just a triangle) to Surface, via the following code:
private Editor ACADEditor => ActiveACADDocument.Editor;
private static Document ActiveACADDocument => ACADDocumentManager.MdiActiveDocument;
private static DocumentCollection ACADDocumentManager => Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager;
private CivilDocument ActiveCivil3DDocument=> CivilApplication.ActiveDocument;
[CommandMethod("FromMeshTest")]
public void FromMesh()
{
try
{
using (var ts = ActiveACADDocument.TransactionManager.StartOpenCloseTransaction())
{
var surfaceId2 = TinSurface.Create(ActiveACADDocument.Database, "FromMeshTest");
var platformSurface = ts.GetObject(surfaceId2, OpenMode.ForWrite) as TINSurface;
var bt = (BlockTable)ts.GetObject(ActiveACADDocument.Database.BlockTableId, OpenMode.ForRead, false);
var btr = (BlockTableRecord)ts.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
var polyMesh = new PolyFaceMesh();
polyMesh.SetDatabaseDefaults();
btr.AppendEntity(polyMesh);
var vertex1 = new PolyFaceMeshVertex(new Point3d(0, 0, 0));
polyMesh.AppendVertex(vertex1);
ts.AddNewlyCreatedDBObject(vertex1, true);
var vertex2 = new PolyFaceMeshVertex(new Point3d(10, 0, 0));
polyMesh.AppendVertex(vertex2);
ts.AddNewlyCreatedDBObject(vertex2, true);
var vertex3 = new PolyFaceMeshVertex(new Point3d(10, 10, 0));
polyMesh.AppendVertex(vertex3);
ts.AddNewlyCreatedDBObject(vertex3, true);
var faceRecord = new FaceRecord(1, 2, 3, 0); //this is one based right? Furthermore, this is a triangle, so the last argument is 0. I hope my intepretation is correct!
polyMesh.AppendFaceRecord(faceRecord);
ts.AddNewlyCreatedDBObject(faceRecord, true);
platformSurface.DrawingObjectsDefinition.AddFromPolyFaces(new ObjectIdCollection(new[] { polyMesh.Id }),
true, $"Normal Platform");
platformSurface.Rebuild();
ts.Commit();
ACADEditor.ZoomExtents();
}
}
catch (System.Exception e)
{
MessageBox.Show(e.ToString());
}
}
But, running the above code will throw me an exception at:
Autodesk.Civil.DatabaseServices.SurfaceDefinitionDrawingObjects.AddFromPolyFaces(Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection, bool, string)
System.ArgumentException: 'Value does not fall within the expected range.'
This is strange because I thought that I am passing in the correct arguments; as my ObjectIdCollection is a list of PolyFaceMesh, the kind of object types that the guide approves!
Anything that I miss?
##########
Ngu Soon Hui
##########
I'm the Benevolent Dictator for Life for MiTS Software. Read more here
I also setup Civil WHIZ in order to share what I learnt about Civil 3D
Ngu Soon Hui
##########
I'm the Benevolent Dictator for Life for MiTS Software. Read more here
I also setup Civil WHIZ in order to share what I learnt about Civil 3D
Solved! Go to Solution.