TinSurface Class Explode Method not populating DBObjectCollection

TinSurface Class Explode Method not populating DBObjectCollection

Anonymous
Not applicable
820 Views
7 Replies
Message 1 of 8

TinSurface Class Explode Method not populating DBObjectCollection

Anonymous
Not applicable

Could someone shed some light on why the DBObjectCollection isn't being populated here?

 

For Each id As ObjectId In btr

     Dim obj1 As Autodesk.AutoCAD.DatabaseServices.DBObject = tr.GetObject(id, OpenMode.ForRead)

     Dim srf As Autodesk.Civil.Land.DatabaseServices.TinSurface = TryCast(obj1, Autodesk.Civil.Land.DatabaseServices.TinSurface)

          If Not srf Is Nothing Then

               Dim acDBObjColl As DBObjectCollection = New DBObjectCollection()

               srf.Explode(acDBObjColl)

                    For Each acEnt As Autodesk.AutoCAD.DatabaseServices.Entity In acDBObjColl

                         btr.AppendEntity(acEnt)
                         tr.AddNewlyCreatedDBObject(acEnt, True)

                    Next

          End If

Next

 

I can't for the life of me figure it out and it's been driving me nuts for the last day.  Any direction or advice (other than telling me not to explode a surface!) would be greatly appreciated.

Thanks in advance.

0 Likes
821 Views
7 Replies
Replies (7)
Message 2 of 8

Jeff_M
Consultant
Consultant

Do you Commit the transaction?

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 8

Anonymous
Not applicable

Hey Jeff thanks for the repl;

 

I commit the transaction outside of the For Loop (maybe not the best place?)

 

I don't think that's the issue here though, as I created a break and checked the DBObjectCollection count after the Explode takes place and it's still 0?

0 Likes
Message 4 of 8

Jeff_M
Consultant
Consultant

OK, I just ran a test using your code and I get a block of the surface objects. Is your surface set to display any objects?

 

Here's what I used.

 

    <CommandMethod("TestExplode")> _
    Public Sub TestExplode()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim tr As Transaction = doc.TransactionManager.StartTransaction

        Dim bt As BlockTable = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForWrite)
        Dim btr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
        Try

            For Each id As ObjectId In btr

                Dim obj1 As Autodesk.AutoCAD.DatabaseServices.DBObject = tr.GetObject(id, OpenMode.ForRead)

                Dim srf As Autodesk.Civil.Land.DatabaseServices.TinSurface = TryCast(obj1, Autodesk.Civil.Land.DatabaseServices.TinSurface)

                If Not srf Is Nothing Then

                    Dim acDBObjColl As DBObjectCollection = New DBObjectCollection()

                    srf.Explode(acDBObjColl)

                    For Each acEnt As Autodesk.AutoCAD.DatabaseServices.Entity In acDBObjColl

                        btr.AppendEntity(acEnt)
                        tr.AddNewlyCreatedDBObject(acEnt, True)

                    Next

                End If

            Next

        Catch
        End Try
        tr.Commit()
    End Sub

 

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 5 of 8

Anonymous
Not applicable

Hey Jeff, I've been trying to do this without having the document open in the editor...that seems to be the issue because I just tested it with the file open in the editor and it worked.

 

So do you think that's a limitation of the explode method?  A file has to be open in the editor?  I hope not because I was really hoping to batch process a number of drawings without using the editor.

 

Thanks again for your help on this.

0 Likes
Message 6 of 8

Jeff_M
Consultant
Consultant

The C3D API is currently not meant to work on anything except the current drawing. So that is definitely what the problem is.

 

One of these days we may be able to edit C3D objects in unopened drawings, but not today. Oh how I wish this would happen soon.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 7 of 8

Anonymous
Not applicable

Noooooo!  I was afraid that's what you were going to say.  That's too bad - back to the drawing board I guess.  Thanks Jeff, as always, you're help is greatly appreciated.

0 Likes
Message 8 of 8

Civil3DReminders
Collaborator
Collaborator

Why explode? It seems to me you can get most of the displayable surface objects from the API. Contours, Triangles, points, etc. If you have the triangles you can figure out any elevation banding or slope shadings. Not as easy as exploding, but would get the job done without having the drawing open.

 

I had a link to a site with the math, but it looks dead. (http://blog.civil3dreminders.com/2009/02/calculate-slope-of-tin-triangle.html)

 

Christopher

0 Likes