AddTinSurface Method

AddTinSurface Method

Anonymous
Not applicable
1,386 Views
12 Replies
Message 1 of 13

AddTinSurface Method

Anonymous
Not applicable
Is there a bug in the current method to create a new TIN surface? I keep getting an error when the time comes to create the new surface object.

'AeccDB is set public already
'create the new tin surface (my engineered fill surface)
Dim surfs As AeccSurfaces
Dim efsurf As AeccSurface 'tin surface
Dim efdata As AeccTinCreationData

Set efdata = New AeccTinCreationData
efdata.name = "TestTIN"
efdata.Style = "Standard"
efdata.BaseLayer = "0"
efdata.Description = "Test"
efdata.Layer = "0"

Set surfs = AeccDb.Surfaces
Set efsurf = surfs.AddTinSurface(efdata)

It bugs out at the last line "Invalid procedure call or arguement"...

i have played with it long enough, Help?

Thanks

-Jeff
0 Likes
1,387 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable
Jeff,

I just tried this:

Option Explicit

Public g_oCivilApp As AeccApplication
Public g_oAeccDoc As AeccDocument
Public AeccDb As AeccDatabase
'
' Start Civil 3D and create Civil 3D document and database objects.
'
Function getCivilObjects() As Boolean
Dim oApp As AcadApplication
Set oApp = ThisDrawing.Application
Const sAppName = "AeccXUiLand.AeccApplication"
Set g_oCivilApp = oApp.GetInterfaceObject(sAppName)
If g_oCivilApp Is Nothing Then
MsgBox "Error creating " & sAppName & ", exit."
getCivilObjects = False
Exit Function
End If
Set g_oAeccDoc = g_oCivilApp.ActiveDocument
Set AeccDb = g_oAeccDoc.Database
getCivilObjects = True

'create the new tin surface (my engineered fill surface)
Dim surfs As AeccSurfaces
Dim efsurf As AeccSurface 'tin surface
Dim efdata As AeccTinCreationData

Set efdata = New AeccTinCreationData
efdata.Name = "TestTIN"
efdata.Style = "Standard"
efdata.BaseLayer = "0"
efdata.Description = "Test"
efdata.Layer = "0"

Set surfs = AeccDb.Surfaces
Set efsurf = surfs.AddTinSurface(efdata)

End Function


Works fine for me. I am running SP3.
Nick
wrote in message news:5384758@discussion.autodesk.com...
Is there a bug in the current method to create a new TIN surface? I keep
getting an error when the time comes to create the new surface object.

'AeccDB is set public already
'create the new tin surface (my engineered fill surface)
Dim surfs As AeccSurfaces
Dim efsurf As AeccSurface 'tin surface
Dim efdata As AeccTinCreationData

Set efdata = New AeccTinCreationData
efdata.name = "TestTIN"
efdata.Style = "Standard"
efdata.BaseLayer = "0"
efdata.Description = "Test"
efdata.Layer = "0"

Set surfs = AeccDb.Surfaces
Set efsurf = surfs.AddTinSurface(efdata)

It bugs out at the last line "Invalid procedure call or arguement"...

i have played with it long enough, Help?

Thanks

-Jeff
0 Likes
Message 3 of 13

Anonymous
Not applicable
Thanks Nick,

My code "looked" the same...and when I tried yours on my test drawing it bugged out again...good news! I just discovered that if the new surface "style" property (in this case it was called "standard" is not found in the current document the method cannot create the tin surface object...after I changed this to something that does exist (ie.._No Display) it worked fine,

Therefore, I will need to test for the style name before I assume that "standard" already exists, or populate a form/combo surface style list and have the user pick what they would like to have for the new surface style...

Thanks again

--Jeff
0 Likes
Message 4 of 13

Anonymous
Not applicable
Ah ya that is always a problem when creating objects thru vba. The style
you are using must exist. I have added the same check to a bunch of my
code.
Nick
wrote in message news:5388023@discussion.autodesk.com...
Thanks Nick,

My code "looked" the same...and when I tried yours on my test drawing it
bugged out again...good news! I just discovered that if the new surface
"style" property (in this case it was called "standard" is not found in the
current document the method cannot create the tin surface object...after I
changed this to something that does exist (ie.._No Display) it worked fine,

Therefore, I will need to test for the style name before I assume that
"standard" already exists, or populate a form/combo surface style list and
have the user pick what they would like to have for the new surface style...

Thanks again

--Jeff
0 Likes
Message 5 of 13

Anonymous
Not applicable
Hi,

I'm not sure if it is possible to create a drawing with no "style", but
assuming it isn't, then you can use the Styles Collection item (0). It
should always exist.

In reality, it's better to check how styles exist with a select case
statement.

0 - report an error, or create a style and allow the user to customise it
later
1 use it
2 or more, have a standard form with a list box which you populate with the
available style and ask the suer to select one.


--
Regards


Laurie Comerford
www.cadapps.com.au
www.civil3dtools.com

"Nick Zeeben" wrote in message
news:5388213@discussion.autodesk.com...
Ah ya that is always a problem when creating objects thru vba. The style
you are using must exist. I have added the same check to a bunch of my
code.
Nick
wrote in message news:5388023@discussion.autodesk.com...
Thanks Nick,

My code "looked" the same...and when I tried yours on my test drawing it
bugged out again...good news! I just discovered that if the new surface
"style" property (in this case it was called "standard" is not found in the
current document the method cannot create the tin surface object...after I
changed this to something that does exist (ie.._No Display) it worked fine,

Therefore, I will need to test for the style name before I assume that
"standard" already exists, or populate a form/combo surface style list and
have the user pick what they would like to have for the new surface style...

Thanks again

--Jeff
0 Likes
Message 6 of 13

Anonymous
Not applicable
Thanks for the input Laurie/Nick,

As a final note, I was able to basically complete my task at hand (EngFill Volume Calculator) and I have to say that the combination of the API to create Volume Surfaces on the fly with Cut-Fill-Net Statistics with an applied Custom Surface Style to display results is amazing. I will be comparing my volumes with "old" Land Desktop methods today and I have my fingers crossed that the numbers are fine...

--Jeff
0 Likes
Message 7 of 13

DRossger
Advocate
Advocate

Hi Jeff!

I have exactly the same problem as you described. Did you get a solution or is it continue problem to create tinsurfaces externly ?!

0 Likes
Message 8 of 13

Civil3DReminders_com
Mentor
Mentor

Here is some code that I did a while ago. 

 

    Private Function CreateEGSurface() As AeccLandLib.AeccTinSurface
        Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
        Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
        Dim trans As Autodesk.AutoCAD.DatabaseServices.Transaction = tm.StartTransaction()
        Try

            Dim oSurface As AeccLandLib.AeccTinSurface
            Dim oTinCreationData As New AeccLandLib.AeccTinCreationData

            ' Make sure the layer exists.
            Dim oLayer As LayerTableRecord
            Dim oLayerID As ObjectId = Nothing
            Dim oLayerTbl As LayerTable = trans.GetObject(db.LayerTableId, OpenMode.ForRead, False)
            Dim sLayerName As String

            sLayerName = "EX-SRF-EG"

            If oLayerTbl.Has(sLayerName) = False Then

                ' Create a new layer table record.
                oLayer = New LayerTableRecord
                oLayer.Name = sLayerName
                oLayer.Color = Color.FromColorIndex(ColorMethod.ByAci, 9)

                oLayerTbl.UpgradeOpen()
                oLayerTbl.Add(oLayer)
                trans.AddNewlyCreatedDBObject(oLayer, True)
                oLayerTbl.DowngradeOpen()

            End If

            oTinCreationData.BaseLayer = sLayerName
            oTinCreationData.Description = "Existing Surface"
            ' Need to add code to make sure the surface layer exists, if not create it.
            oTinCreationData.Layer = sLayerName
            oTinCreationData.Name = "EG"
            ' Need to add code to make sure the style exists, if not create it.

            Dim i As Integer
            Dim bStyleExists As Boolean
            Dim sStyleName As String

            sStyleName = "Existing Surface Contours [Background]"

            bStyleExists = False

            Dim oCivil As New AeccAppConnection

            For i = 0 To oCivil.AeccDoc.SurfaceStyles.Count - 1
                If oCivil.AeccDoc.SurfaceStyles.Item(i).Name = sStyleName Then
                    bStyleExists = True
                    Exit For
                End If
            Next

            If bStyleExists = False Then
                ' Use first surface stye in the list.
                sStyleName = oCivil.AeccDoc.SurfaceStyles.Item(0).Name
            End If

            oTinCreationData.Style = sStyleName

            oSurface = oCivil.AeccDoc.Surfaces.AddTinSurface(oTinCreationData)

            trans.Commit() ' Keep the Changes

            Return oSurface

        Catch ex As Autodesk.AutoCAD.Runtime.Exception

            trans.Abort()
            Return Nothing
        Finally

            trans.Dispose() ' Done with transaction

        End Try

    End Function
Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
0 Likes
Message 9 of 13

DRossger
Advocate
Advocate

I didn´t find the class for AeccTinCreationData in C#.NET

 

        private TinSurface CreateEGSurface()
        {
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            Autodesk.AutoCAD.DatabaseServices.Transaction trans = tm.StartTransaction();

            try
            {
                TinSurface oSurface = default(TinSurface);
                AeccTinCreationData oTinCreationData = new AeccLandLib.AeccTinCreationData();

                // Make sure the layer exists.
                LayerTableRecord oLayer = default(LayerTableRecord);
                ObjectId oLayerID = ObjectId.Null;
                LayerTable oLayerTbl = trans.GetObject(db.LayerTableId, OpenMode.ForRead, false);
                string sLayerName = null;

                sLayerName = "EX-SRF-EG";


                if (oLayerTbl.Has(sLayerName) == false)
                {
                    // Create a new layer table record.
                    oLayer = new LayerTableRecord();
                    oLayer.Name = sLayerName;
                    oLayer.Color = Color.FromColorIndex(ColorMethod.ByAci, 9);

                    oLayerTbl.UpgradeOpen();
                    oLayerTbl.Add(oLayer);
                    trans.AddNewlyCreatedDBObject(oLayer, true);
                    oLayerTbl.DowngradeOpen();

                }

                oTinCreationData.BaseLayer = sLayerName;
                oTinCreationData.Description = "Existing Surface";
                // Need to add code to make sure the surface layer exists, if not create it.
                oTinCreationData.Layer = sLayerName;
                oTinCreationData.Name = "EG";
                // Need to add code to make sure the style exists, if not create it.

                int i = 0;
                bool bStyleExists = false;
                string sStyleName = null;

                sStyleName = "Existing Surface Contours [Background]";

                bStyleExists = false;

                AeccAppConnection oCivil = new AeccAppConnection();

                for (i = 0; i <= oCivil.AeccDoc.SurfaceStyles.Count - 1; i++)
                {
                    if (oCivil.AeccDoc.SurfaceStyles.Item(i).Name == sStyleName)
                    {
                        bStyleExists = true;
                        break; // TODO: might not be correct. Was : Exit For
                    }
                }

                if (bStyleExists == false)
                {
                    // Use first surface stye in the list.
                    sStyleName = oCivil.AeccDoc.SurfaceStyles.Item(0).Name;
                }

                oTinCreationData.Style = sStyleName;

                oSurface = oCivil.AeccDoc.Surfaces.AddTinSurface(oTinCreationData);

                trans.Commit();
                // Keep the Changes

                return oSurface;


            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                trans.Abort();
                return null;

            }
            finally
            {
                trans.Dispose();
                // Done with transaction

            }

        }
0 Likes
Message 10 of 13

Civil3DReminders_com
Mentor
Mentor

The thread was using COM so I provided that solution. 

 

If you want to use .NET then check out this post: http://adndevblog.typepad.com/infrastructure/2014/01/creating-civil-3d-tin-surface-from-contours-pol...

Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
0 Likes
Message 11 of 13

DRossger
Advocate
Advocate

The same problem with this code. I only want create a empty surface


using (Transaction m_Tr = db.TransactionManager.StartTransaction()) { try { m_SurfaceStyleId = civilDoc.Styles.SurfaceStyles["your style"]; m_SurfaceId = TinSurface.Create("TIN_Surface_From_Contours", m_SurfaceStyleId);

It have to work, but not for me, have I annother way to make it possible ?!

 

0 Likes
Message 12 of 13

Jeff_M
Consultant
Consultant
cadplayer, could you be a bit more specific? You say 'it doesn't work'...does it throw an error? If it is, and you aren't Catching it advise the user, the try will just bypass it. What version of C3D? Your first reply mentioned 'externly', are you trying to do this from a standalone application or from inside a running instance of C3D? Can you post your code that 'doesn't work'...or was that it a few replies back?
Jeff_M, also a frequent Swamper
EESignature
0 Likes