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

Change layer

8 REPLIES 8
Reply
Message 1 of 9
fmarcelino
602 Views, 8 Replies

Change layer

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
8 REPLIES 8
Message 2 of 9
fmarcelino
in reply to: fmarcelino

Please help!!!

I need a solution for this matter...
Message 3 of 9
fmarcelino
in reply to: fmarcelino

hi again,

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

Thanks,
Filipe Marcelino
Message 4 of 9
Mikko
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
Message 5 of 9
fmarcelino
in reply to: fmarcelino

Hi Mikko,

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

Regards,
Filipe Marcelino
Message 6 of 9
RonnieWilkins
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.
Message 7 of 9
fmarcelino
in reply to: fmarcelino

hi,

is happening the same thing...
Message 8 of 9
RonnieWilkins
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.
Message 9 of 9
fmarcelino
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

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