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

Set ActiveLayer Problem...

6 REPLIES 6
Reply
Message 1 of 7
Explosive_Ice
3177 Views, 6 Replies

Set ActiveLayer Problem...

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.....
6 REPLIES 6
Message 2 of 7

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. 🙂
Message 3 of 7

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...
Message 4 of 7
Anonymous
in reply to: Explosive_Ice

http://www.autocad.ru/cgi-bin/f1/board.cgi?t=30612rJ#20061018210721
Message 5 of 7

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.
Message 6 of 7

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
Message 7 of 7

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

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