Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Do I have to append TIN Surface to the database?

3 REPLIES 3
Reply
Message 1 of 4
heyimsp12
222 Views, 3 Replies

Do I have to append TIN Surface to the database?

I'm trying to create a TIN Surface in the below function and later I want to extrude it into a solid of depth 2 meters. 
While debugging the code, I have noticed that my code runs fine butt I still can't see new surfaces being created on C3D Document. Do I have to append the surface to the Model Space and then also add it to the transaction? If yes, i tried doing that as well but then I am getting error - Object already in database.

 

Here is my code:

 //Create TIN Surface and define its Breaklines and Boundaries.
        public ObjectId CreateTinSurface(Polyline2d boundary, bool ExtrudeSolid = false, double DepthOfSolid = 2.0)
        {
            var surfaceId = new ObjectId(); //Placeholder for surfaceId.
            
            using (var db = Application.DocumentManager.MdiActiveDocument.Database)
            using (var trans = db.TransactionManager.StartTransaction())
            using (var blockTable = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead))
            using (var modelSpace = (BlockTableRecord)trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead))
            {
                try
                {
                    //Create an empty TIN surface
                    surfaceId = TinSurface.Create(db, "TempVisSurface_"+boundary.BlockName.Trim().ToString());

                    //Open the TIN surface
                    TinSurface surface = (TinSurface)trans.GetObject(surfaceId, OpenMode.ForWrite);

                    //Surface Breaklines Definition
                    //BoundarySet will also serve as a BreaklinesSet here, since the surface is empty anyways.
                    ObjectIdCollection breaklineSet = new ObjectIdCollection();
                    breaklineSet.Add(boundary.ObjectId);
                    surface.BreaklinesDefinition.AddStandardBreaklines(breaklineSet, 1.0, 1.0, 1.0, 0);
                   
                    ////Surface Boundary Definition
                    ObjectIdCollection boundaryIdSet = new ObjectIdCollection();
                    boundaryIdSet.Add(boundary.ObjectId);
                    surface.BoundariesDefinition.AddBoundaries(boundaryIdSet, 1.0, Autodesk.Civil.SurfaceBoundaryType.Outer, true); 
                    
                    //Conditionally also convert the surface into solid with given depth
                    //Ideally, Solid will be created with depth 2m.
                    if (ExtrudeSolid == true)
                        surface.CreateSolidsAtDepth(DepthOfSolid, surface.Layer, 0);

                    //***My question is: do i need to run the below code??
                    //modelSpace.AppendEntity(surface);
                    //trans.AddNewlyCreatedDBObject(surface, true);
                    //***End of question
                }
                catch (Exception ex)
                {
                    Application.ShowAlertDialog("Error creating TIN Surface.\n" + ex.Message);
                }
            }
            return surfaceId;
        }
Labels (1)
3 REPLIES 3
Message 2 of 4
hosneyalaa
in reply to: heyimsp12

HI @heyimsp12 

Think

YOU Forgot this to the code

 

trans.Commit();
Message 3 of 4
heyimsp12
in reply to: hosneyalaa

Thanks @hosneyalaa. I will end the transaction, but that still doesn't solve the problem. 

Also btw, since the transaction is in using-statement, I don't think I necessarily need to close it but I'm not sure. It sounds like a good idea to commit the transaction manually.

Message 4 of 4
Jeff_M
in reply to: heyimsp12

C3D handles adding the Surface to the database. 


@heyimsp12 wrote:

Thanks @hosneyalaa. I will end the transaction, but that still doesn't solve the problem. 

Also btw, since the transaction is in using-statement, I don't think I necessarily need to close it but I'm not sure. It sounds like a good idea to commit the transaction manually.


If you don't Commit the transaction, it is disposed when exiting the Using statement.

 

I think you will need to Rebuild the Surface prior to creating the solids.

Jeff_M, also a frequent Swamper
EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report