.NET

Reply
Valued Contributor
fmarcelino
Posts: 61
Registered: ‎10-25-2005
Message 1 of 9 (210 Views)

Change layer

210 Views, 8 Replies
01-13-2006 08:39 AM
Hi,

I developed a DLL in vs .net under vb.net. This DLL will change automatically the current layer to the layer '0' each time a command start. To do so I've done the following code:

Private Shared Sub m_doc_CommandWillStart(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
Dim curdb As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Try
curdb.Clayer = "0"
myT.Commit()
Catch ex As Exception
myT.Abort()
MessageBox.Show("An error ocurred...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
myT.Dispose()
End Try
End Sub

Each time I execute a command this procedure is executed wihout an error, but only when the command 'line' is executed the current layer is acttually changed. When I execute the command 'mirror', 'dtext', etc the current layer doesn't change. I need help on this.

Thanks in advance for your attention,
Filipe Marcelino
Valued Contributor
fmarcelino
Posts: 61
Registered: ‎10-25-2005
Message 2 of 9 (210 Views)

Re: Change layer

01-18-2006 02:25 AM in reply to: fmarcelino
Please help!!!

I need a solution for this matter...
Valued Contributor
fmarcelino
Posts: 61
Registered: ‎10-25-2005
Message 3 of 9 (210 Views)

Re: Change layer

01-20-2006 03:35 AM in reply to: fmarcelino
hi again,

does anyone need some kind of explanation? Am I not being clear?

Thanks,
Filipe Marcelino
Distinguished Contributor
Mikko
Posts: 212
Registered: ‎10-03-2003
Message 4 of 9 (210 Views)

Re: Change layer

01-20-2006 04:22 AM in reply to: fmarcelino
I think this is looking for an objectId not a string.
Maybe something like this?

Try
Dim layerId As ObjectId
Dim lt As LayerTable = myT.GetObject(curbdb.LayerTableId, OpenMode.ForRead)
layerId = lt.Item("0")
curdb.Clayer = layerId
myT.Commit() Message was edited by: Mikko
Valued Contributor
fmarcelino
Posts: 61
Registered: ‎10-25-2005
Message 5 of 9 (210 Views)

Re: Change layer

01-20-2006 04:30 AM in reply to: fmarcelino
Hi Mikko,

thanks for your reply. The same thing is happenning...maybe a SDK error?

Regards,
Filipe Marcelino
Distinguished Contributor
RonnieWilkins
Posts: 453
Registered: ‎04-07-2003
Message 6 of 9 (210 Views)

Re: Change layer

01-20-2006 02:52 PM in reply to: fmarcelino
Thrown together but working:

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices

Public Class Class1
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

Private CurrentDoc As Document

Private Shared Sub m_doc_CommandWillStart(ByVal sender As System.Object, ByVal e As Autodesk.AutoCAD.ApplicationServices.CommandEventArgs)
Dim curdb As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = curdb.TransactionManager
Dim myT As Transaction = tm.StartTransaction()
Try
Dim LayerId As ObjectId
Dim LT As LayerTable = myT.GetObject(curdb.LayerTableId, OpenMode.ForRead)
LayerId = LT.Item("0")
curdb.Clayer = LayerId
myT.Commit()
Catch ex As Exception
myT.Abort()
System.Windows.Forms.MessageBox.Show("An error ocurred...", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)
Finally
myT.Dispose()
End Try
End Sub

Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
CurrentDoc = Application.DocumentManager.MdiActiveDocument

'This will make the function only available to the document use used netload on.
'It's up to you to keep up to date as you switch drawings.
AddHandler CurrentDoc.CommandWillStart, AddressOf m_doc_CommandWillStart
End Sub

Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate

End Sub
End Class
Ronnie Wilkins, Jr.
AMS CAD + CAFM Solutions
Sr. Solutions Developer
Autodesk Certified Instructor: Inventor
Valued Contributor
fmarcelino
Posts: 61
Registered: ‎10-25-2005
Message 7 of 9 (210 Views)

Re: Change layer

01-25-2006 06:13 AM in reply to: fmarcelino
hi,

is happening the same thing...
Distinguished Contributor
RonnieWilkins
Posts: 453
Registered: ‎04-07-2003
Message 8 of 9 (210 Views)

Re: Change layer

01-25-2006 07:50 AM in reply to: fmarcelino
Then it has something to do with your settings.

The code I posted works with VB.NET 2005 and AutoCAD 2006. I tested it before posting.

Which version of VB.NET are you using?
Which version of AutoCAD?
Ronnie Wilkins, Jr.
AMS CAD + CAFM Solutions
Sr. Solutions Developer
Autodesk Certified Instructor: Inventor
Valued Contributor
fmarcelino
Posts: 61
Registered: ‎10-25-2005
Message 9 of 9 (210 Views)

Re: Change layer

01-25-2006 07:55 AM in reply to: fmarcelino
Hi again,

i'm using vb.net 2003 and autocad 2006. I don't understand why this isn't working? Do you have any other possibility to solve this issue.

Regards,
Filipe Marcelino

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community