CivilTinSurface creation
Hello, I'm trying to create a CivilTinSurface under C# as shown in the following code segment:
using Bricscad.CivilTin;
...
CivilTinSurface tinSurface = new CivilTinSurface();
objId = tinSurface.Id;
objId.GetObject(OpenMode.ForWrite);
tinSurface.Initialize(new Point3d(0, 0, 0), new Point3d(20, 20, 10), 10);
The objid is null, thus obtaining an error.
I would appreciate it if you could you send me the correct way of creating a Tin Surface, assigning a name and initialize it.
Thank you
Comments
-
The example below will create a new CivilTinSurface, and add some points to it. Then it will strike a line across (using two points) to obtain the points that form a profile using its drape function. Lastly it labels some points using the surfaces ability to calculate elevations at random locations.
Imports Bricscad.CivilTin <CommandMethod("BcTinEx")> _ Public Shared Sub BcTinEx() Dim DatBas As Database = Application.DocumentManager.MdiActiveDocument.Database Using TrnAct As Transaction = DatBas.TransactionManager.StartTransaction Dim MdlOid As ObjectId = SymbolUtilityServices.GetBlockModelSpaceId(DatBas) Dim MdlSpc As BlockTableRecord = MdlOid.GetObject(OpenMode.ForWrite) ' ' Create TinSur using handful of points ' Dim TinObj As New CivilTinSurface TinObj.AddPoint(New Point3d(189.6, 384.0, 90.0)) ' 0 TinObj.AddPoint(New Point3d(448.8, 319.2, 95.0)) ' 1 TinObj.AddPoint(New Point3d(319.2, 124.8, 60.0)) ' 2 TinObj.AddPoint(New Point3d(384.0, 448.8, 80.0)) ' 3 TinObj.AddPoint(New Point3d(60.0, 189.6, 35.0)) ' 4 TinObj.AddPoint(New Point3d(124.8, 60.0, 25.0)) ' 5 MdlSpc.AppendEntity(TinObj) TrnAct.AddNewlyCreatedDBObject(TinObj, True) ' ' Drape two points to form 3dPoly profile ' Dim InpCol As New Point3dCollection InpCol.Add(New Point3d(80.0, 125.0, 0.0)) InpCol.Add(New Point3d(425.0, 390.0, 0.0)) Dim ResLst As List(Of Point3dCollection) = TinObj.Drape(InpCol) Dim ResCol As Point3dCollection = ResLst(0) Dim PlnObj As New Polyline3d(Poly3dType.SimplePoly, ResCol, False) PlnObj.ColorIndex = 1 MdlSpc.AppendEntity(PlnObj) TrnAct.AddNewlyCreatedDBObject(PlnObj, True) ' ' Label some random points along surface ' Dim PntLst As New List(Of Point3d) PntLst.Add(New Point3d(145.0, 120.0, 0.0)) PntLst.Add(New Point3d(170.0, 250.0, 0.0)) PntLst.Add(New Point3d(325.0, 265.0, 0.0)) PntLst.Add(New Point3d(340.0, 390.0, 0.0)) For Each PntLoc As Point3d In PntLst Dim AddMtx As New MText AddMtx.Location = PntLoc AddMtx.TextHeight = 8.0 AddMtx.Contents = TinObj.ElevationAtPoint(PntLoc).ToString("0.00") MdlSpc.AppendEntity(AddMtx) TrnAct.AddNewlyCreatedDBObject(AddMtx, True) Next ' TrnAct.Commit() End Using End Sub
0 -
Terry, thank you very much for your immediate response.
I introduced some changes under C#. I'm not quite sure if the block table (bt) definition is necessary. I had to add it otherwise, an error occurred (Can't convert implicitly type 'Teigha.Database Service.DBObject' into 'Teigha.Database Service.BlockRecord').I also added a contour style.
[CommandMethod("CVN")] public void CVN() { using (Transaction TrnAct = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()) { Database DatBas = Application.DocumentManager.MdiActiveDocument.Database; BlockTable bt = DatBas.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable; ObjectId MdlOid = SymbolUtilityServices.GetBlockModelSpaceId(DatBas); BlockTableRecord MdlSpc = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord; _CivTin.CivilTinSurface tinSurface = new _CivTin.CivilTinSurface(); tinSurface.AddPoint(new Point3d(189.6, 384.0, 90.0)); tinSurface.AddPoint(new Point3d(448.8, 319.2, 95.0)); tinSurface.AddPoint(new Point3d(319.2, 124.8, 60.0)); tinSurface.AddPoint(new Point3d(384.0, 448.8, 80.0)); tinSurface.AddPoint(new Point3d(60.0, 189.6, 35.0)); MdlSpc.AppendEntity(tinSurface); TrnAct.AddNewlyCreatedDBObject(tinSurface, true); tinSurface.Style = _CivTin.TinSurfaceStyle.TinStyleContours; TrnAct.Commit(); } }
0