Distinguished Contributor
188 Posts
0 Kudos
Registered: ‎09-18-2005
Post 1 of 6

Civil3d and vb.net

177 Views, 5 Replies
09-20-2006 07:40 AM
I'm having problems with a managed vb.net project and civil3d.

I'm trying to create a basic routine that manipulates layers.

I've referenced the acmgd and acdbmgd dll's follow a sample from an AU 2005 handout.

vb.net is not recognizing the Import namespaces from the sample.

I tried starting with a vb.net sample from the ARX SDK and the namespaces are recognized and I can run the dll in Civil3D and get my dialog box to come up.

The next issue I have ran into is that acadlayer is not recognized in the vb.net and isn't showing up in a search for it in the object explorer model explorer.

Are there any issues with creating a managed .net app with civil3d or are there issues with my code.

thanks in advance.
385 Posts
10 Kudos
Registered: ‎06-27-2005
Post 2 of 6

Re: Civil3d and vb.net

09-20-2006 10:34 AM in reply to: saluki
Hi Scott,
I beleive you have to access the layers via the layertable object. When you access the record, just like you would access the blocktable, you can pass a name to the program and get back an LayerId. Then you can use that layerID to set a layertablerecord to the specified layer. After that you i believe you can manipulate the object like it was an AcadLayer object.

here is some code from one of the labs in the .Net training.

Private Function CreateLayer() As ObjectId
Dim layerId As ObjectId 'the return value for this function
Dim db As Database = HostApplicationServices.WorkingDatabase
Using trans As Transaction = db.TransactionManager.StartTransaction()
'Get the layer table first, open for read as it may already be there
Dim lt As LayerTable = trans.GetObject(db.LayerTableId, OpenMode.ForRead)

'Check if EmployeeLayer exists...
If lt.Has("EmployeeLayer") Then
layerId = lt.Item("EmployeeLayer")
'If not, create the layer here.
Dim ltr As LayerTableRecord = New LayerTableRecord()
ltr.Name = "EmployeeLayer" ' Set the layer name
ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 2)
' it doesn't exist so add it, but first upgrade the open to write
layerId = lt.Add(ltr)
trans.AddNewlyCreatedDBObject(ltr, True)
End If
End Using

Return layerId
End Function

Hope that helps. Definitely a lot of code involved to set a layer!
Distinguished Contributor
188 Posts
0 Kudos
Registered: ‎09-18-2005
Post 3 of 6

Re: Civil3d and vb.net

09-20-2006 11:01 AM in reply to: saluki
Thanks cadkid, I was hoping to be able to use something from this post:


Dim NewLayer As AcadLayer

NewLayer = acadDoc.Layers.Add("Layer1")

NewLayer.TrueColor.SetRGB(255, 0, 0)
385 Posts
10 Kudos
Registered: ‎06-27-2005
Post 4 of 6

Re: Civil3d and vb.net

09-20-2006 11:18 AM in reply to: saluki
No problem. You should be able to reference the COM interface of AutoCAD even though you are using Civil3D.

First make sure you have a reference set to the following under the COM tab, in references
"AutoCAD 2006 Type Library"
"AutoCAD/Object DBX Common 16.0 Library"

then use the Imports Autodesk.AutoCad.Interop.Common statement at the beginning of your code.

Then you should be able to use the line:

"Dim NewLayer as AcadLayer"

Let me know if that works.

-Mark P
Distinguished Contributor
188 Posts
0 Kudos
Registered: ‎09-18-2005
Post 5 of 6

Re: Civil3d and vb.net

09-20-2006 12:34 PM in reply to: saluki
ahhhhhhhhh . . . now it makes sense.

I didn't realize the mgd .net object model was that different from the COM model.

What kind of performance difference is there between COM and the .net mgd code?
385 Posts
10 Kudos
Registered: ‎06-27-2005
Post 6 of 6

Re: Civil3d and vb.net

09-20-2006 12:52 PM in reply to: saluki
Yeah, i know what you mean. I taught myself to program in VBA and it's really not all that difficult. Now I've joined the .NET world, and i feel like i'm re-learning the basics. But it seems worth it to learn the Managed API's because you can do so much more... Create custom tool palletes, custom tabs in the AutoCAD options menu, and i can use the JIG function..
.NET programs definitely feel more like an extension of AutoCAD than VBA/COM programs do. However it takes about 20 lines of code to do the same thing as 4 lines of code in COM

I'm not quite sure about performance speed. I think that using COM in VB is slightly faster than VBA. And .NET is only slightly slower than ObjectARX

check out this post, there is a graph and some comments. i think the graph is slightly misleading though...


i believe the order is as follows:
-.NET (Managed API)
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post