.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Civil3d and vb.net

5 REPLIES 5
Reply
Message 1 of 6
saluki
350 Views, 5 Replies

Civil3d and vb.net

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.
5 REPLIES 5
Message 2 of 6
MarkPendergraft
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!
Message 3 of 6
saluki
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)
Message 4 of 6
MarkPendergraft
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
Message 5 of 6
saluki
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?
Message 6 of 6
MarkPendergraft
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

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost