.NET

Reply
Distinguished Contributor
saluki
Posts: 188
Registered: ‎09-18-2005
Message 1 of 6 (171 Views)

Civil3d and vb.net

171 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.
Mentor
MarkPendergraft
Posts: 375
Registered: ‎06-27-2005
Message 2 of 6 (171 Views)

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")
Else
'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
lt.UpgradeOpen()
layerId = lt.Add(ltr)
trans.AddNewlyCreatedDBObject(ltr, True)
End If
trans.Commit()
End Using

Return layerId
End Function

Hope that helps. Definitely a lot of code involved to set a layer!
Distinguished Contributor
saluki
Posts: 188
Registered: ‎09-18-2005
Message 3 of 6 (171 Views)

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:

http://discussion.autodesk.com/thread.jspa?messageID=5187189

Dim NewLayer As AcadLayer

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

NewLayer.TrueColor.SetRGB(255, 0, 0)
Mentor
MarkPendergraft
Posts: 375
Registered: ‎06-27-2005
Message 4 of 6 (171 Views)

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
saluki
Posts: 188
Registered: ‎09-18-2005
Message 5 of 6 (171 Views)

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?
Mentor
MarkPendergraft
Posts: 375
Registered: ‎06-27-2005
Message 6 of 6 (171 Views)

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...

http://discussion.autodesk.com/thread.jspa?messageID=5312479

i believe the order is as follows:
-ObjectARX
-.NET (Managed API)
-.NET (COM)
-VBA (COM)
-VLISP
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.