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

Really basic select question

2 REPLIES 2
Reply
Message 1 of 3
ahmed.felix
164 Views, 2 Replies

Really basic select question

I'm an experienced developer with VBA but am now moving everything to .NET, which I'm new to concerning AutoCAD (as of this week new) so this should be a pretty easy stuff that I can't get to work. I built a function that should return a reference to an object that I want to change some properties to, lets say the layer for example. The problem is, the object returns all right, I can read the ObjectId or anything else, but if I try to change the layer an eNotOpenForWrite error pops up and AutoCAD crashes. Why is this happening if I am opening it in a ForWrite mode? Am I perhaps writing a whole lot of nonesense in the GetEntity function that appears to work but really doesn't? I've tried this with existing objects, objects I draw at the moment, and objects created from code... no positive result. Could anyone point me in the right direction? Thanks.

Note: Both routines are in different projects each on it's own class, acadDB and acadTrans are previously declared in the class that GetEntity belongs to cause other functions use them as well. objModelLayout is an instance of the class that contains GetEntity. I am using Visual Studio 2005 and AutoCAD 2006.


Public Function GetEntity(ByVal Prompt As String) As Entity
Dim optEntityOptions As New PromptEntityOptions(vbCrLf & Prompt)
Dim presEntity As PromptEntityResult
Dim dbobjObject As DBObject = Nothing
Dim Command As Editor

Command = acadApp.DocumentManager.MdiActiveDocument.Editor
presEntity = Command.GetEntity(optEntityOptions)

acadDB = HostApplicationServices.WorkingDatabase
acadTrans = acadDB.TransactionManager.StartTransaction()
Try
dbobjObject = acadTrans.GetObject(presEntity.ObjectId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
acadTrans.Commit()

Catch
acadTrans.Abort()

Finally
If Not IsNothing(dbobjObject) Then
GetEntity = CType(dbobjObject, Entity)
Else
GetEntity = Nothing
End If

If Not IsNothing(acadTrans) Then acadTrans.Dispose()
If Not IsNothing(acadDB) Then acadDB.Dispose()

End Try

End Function



_
Public Sub TestGetObject()
Dim acEntity As Entity
Dim Command As Editor

Command = acadApp.DocumentManager.MdiActiveDocument.Editor

Try
acEntity = objModelLayout.GetEntity("Select object to change its layer: ")
Catch ex As Exception
Exit Sub
End Try

Try
Command.WriteMessage(acEntity.ObjectId.ToString)
acEntity.Layer = "Layer1"
Catch ex As Exception
MsgBox("Layer Missing!")
End Try

End Sub
2 REPLIES 2
Message 2 of 3
NathTay
in reply to: ahmed.felix

You have committed and disposed of the transaction before you set the layer. Anything you do to the entity has to be done in the transaction.

Regards - Nathan
Message 3 of 3
ahmed.felix
in reply to: ahmed.felix

Thanks Nathan, there was a little more of work to do orginizing the transactions to get it running but what you said was pretty much it. I'm getting the hold of how this thing works.

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