.NET

Reply
Member
Explosive_Ice
Posts: 4
Registered: ‎10-18-2006
Message 1 of 7 (330 Views)

Set ActiveLayer Problem...

330 Views, 6 Replies
10-18-2006 08:02 AM
Hi, everybody! ADSK have a bug in choosing activelayer, when the AutoCAD Object was created by CreateObject("AutoCAD.Application") in .NET.
How could I choose an activelayer anyway?

Here the code:
Dim CurrentLayer As Object
Dim LayerName As String = "Test Layer"
AutoCADObject = CreateObject("AutoCAD.Application.17")
AutoCADObject.Visible = True
AutoCADObject.ActiveDocument.Layers.Add(LayerName)
CurrentLayer = AutoCADObject.ActiveDocument.Layers.Item("Test Layer")
AutoCADObject.ActiveDocument.ActiveLayer = CurrentLayer
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try

I have exception:
"Member not found."

Thanx a lot.....
Mentor
MarkPendergraft
Posts: 385
Registered: ‎06-27-2005
Message 2 of 7 (330 Views)

Re: Set ActiveLayer Problem...

10-18-2006 04:42 PM in reply to: Explosive_Ice
Well i don't understand why people want to use .NET to create COM applications, after all thats what VBA is all about...... But if you insist.

Try

dim CurrentLayer as AcadLayer

let me know if that doesn't work. :smileyhappy:
Member
Explosive_Ice
Posts: 4
Registered: ‎10-18-2006
Message 3 of 7 (330 Views)

Re: Set ActiveLayer Problem...

10-19-2006 12:25 AM in reply to: Explosive_Ice
You can't use dim CurrentLayer as AcadLayer because, there is no reference to AutoCAD, we have CreateObject and can not to define sub-objects of AutoCAD. Whatever, Thanx for your reply...
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 4 of 7 (330 Views)

Re: Set ActiveLayer Problem...

10-19-2006 12:32 AM in reply to: Explosive_Ice
http://www.autocad.ru/cgi-bin/f1/board.cgi?t=30612rJ#20061018210721
Mentor
MarkPendergraft
Posts: 385
Registered: ‎06-27-2005
Message 5 of 7 (330 Views)

Re: Set ActiveLayer Problem...

10-19-2006 08:49 AM in reply to: Explosive_Ice
Well this code works for me.....

Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim CurrentLayer As AcadLayer
Dim LayerName As String = "Test Layer"
Dim AutoCADObject As AcadApplication = CreateObject("AutoCAD.Application.16")
AutoCADObject.Visible = True
AutoCADObject.ActiveDocument.Layers.Add(LayerName)
CurrentLayer = AutoCADObject.ActiveDocument.Layers.Item(LayerName)
Try
AutoCADObject.ActiveDocument.ActiveLayer = CurrentLayer
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try

End Sub
End Class


Why can't you add a reference?
are you working with multiple versions of AutoCAD?
personally i've had nothing but bad experiences with late binding..... maybe if you could provide more info we could help you.
Member
Explosive_Ice
Posts: 4
Registered: ‎10-18-2006
Message 6 of 7 (330 Views)

Re: Set ActiveLayer Problem...

10-22-2006 12:30 AM in reply to: Explosive_Ice
Yes, I need it for multiple versions of AutoCAD, without reference to specified version. In VB6 it works correctly, in .NET thet's problem with casting in lines like AutoCADObject.ActiveDocument.ActiveLayer = CurrentLayer
or also
Dim outerLoop As Object
outerLoop = AutoCADObject.ActiveDocument.ModelSpace.AddPolyline(HatchPoint)
hatchObj.AppendOuterLoop(outerLoop)
This code also drops to error in .NET and works fine in VB6
Active Member
ChristinaSeay
Posts: 9
Registered: ‎04-08-2009
Message 7 of 7 (330 Views)

Re: Set ActiveLayer Problem...

12-15-2009 01:57 PM in reply to: Explosive_Ice
I'm having this exact same problem... did you ever find an answer to it??

I'm using late binding as well since I have multiple versions of AutoCAD that I'm working with from a .NET application. My code is:

V_AutoCadLayer = V_AutoCad.ActiveDocument.Layers.Add("E9BorderLayer")
V_AutoCadLayer.Color = 3

V_AutoCad.ActiveDocument.ActiveLayer = V_AutoCadLayer

I get an error on the last line where I set ActiveLayer, it returns "Member not found."
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.