Hi all,
I would like to re-encode my plug-in lighter, in order to optimize tasks.
So I would like to store dynamically, in an ArrayList or else, entities properties (ID, Layer, Bounds...etc.) by using reactors.
It works! but not with every entity! For instance AutoCAD crashes when I create a CIRCLE while ObjectAppended is invoking.
Here is a simply code to resume:
Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.EditorInput Public Class Class1 Friend acDoc As Document = Application.DocumentManager.MdiActiveDocument Friend acCurDb As Database = acDoc.Database Friend ed As Editor = acDoc.Editor <CommandMethod("Test")> _ Public Sub Test() AddHandler acCurDb.ObjectAppended, AddressOf MyDelegate End Sub Public Sub MyDelegate(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs) On Error Resume Next Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim acblktbl As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) Dim acblkTblRec As BlockTableRecord = acTrans.GetObject(acblktbl(BlockTableRecord.ModelSpace), OpenMode.ForRead) For Each acObjId As ObjectId In acblkTblRec If acObjId = e.DBObject.ObjectId Then Dim MyEnt As Entity = acTrans.GetObject(acObjId, OpenMode.ForRead) Dim message As String = MyEnt.GetRXClass.DxfName.ToString & vbLf Select Case MyEnt.GetRXClass.DxfName Case Is = "LWPOLYLINE" Dim Mypolyline As Polyline = CType(MyEnt, Entity) message += "Area= " & Mypolyline.Area.ToString & vbLf message += "Layer= " & Mypolyline.Layer.ToString & vbLf message += "Min point= " & Mypolyline.Bounds.Value.MinPoint.ToString & vbLf message += "Max point= " & Mypolyline.Bounds.Value.MaxPoint.ToString & vbLf Case Is = "CIRCLE" Dim Mycircle As Circle = CType(MyEnt, Circle) message += "Area= " & Mycircle.Area.ToString & vbLf message += "Calque= " & Mycircle.Layer.ToString & vbLf message += "Radius= " & Mycircle.Radius.ToString & vbLf End Select MsgBox(message) End If Next End Using End Sub End Class
What can I do to solve that!?
I would imagine that this post would get more traction over in the customizations forums.
Sure! But how could I put it in the right section, I mean .NET section!?
HI all,
I solved the problem by adding this line:
acTrans.Commit
AutoCAD now no longer crashes but another problem occurs when adding circles.
Specific properties (like center, circumference, radius, diameter) are initialized to 0, while those of other entities are well notified.
Here is the code:
Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.EditorInput Public Class Class1 Friend acDoc As Document = Application.DocumentManager.MdiActiveDocument Friend acCurDb As Database = acDoc.Database Friend ed As Editor = acDoc.Editor <CommandMethod("Test")> _ Public Sub Test() AddHandler acCurDb.ObjectAppended, AddressOf MyDelegate End Sub Public Sub MyDelegate(ByVal sender As Object, ByVal e As Autodesk.AutoCAD.DatabaseServices.ObjectEventArgs) Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim acblktbl As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) Dim acblkTblRec As BlockTableRecord = acTrans.GetObject(acblktbl(BlockTableRecord.ModelSpace), OpenMode.ForRead) For Each acObjId As ObjectId In acblkTblRec If acObjId = e.DBObject.ObjectId Then Dim MyEnt As Entity = acTrans.GetObject(acObjId, OpenMode.ForRead) Dim message As String = "Object: " & MyEnt.GetRXClass.DxfName.ToString & vbLf message += "Layer= " & MyEnt.Layer.ToString & vbLf message += "Color Index= " & MyEnt.ColorIndex.ToString & vbLf Select Case MyEnt.GetRXClass.DxfName Case Is = "ARC" Dim Myarc As Arc = CType(MyEnt, Arc) message += "Bounds Min point= " & Myarc.Bounds.Value.MinPoint.ToString & vbLf message += "Bounds Max point= " & Myarc.Bounds.Value.MaxPoint.ToString & vbLf message += "Center= " & Myarc.Center.ToString & vbLf message += "Radius= " & Myarc.Radius.ToString Case Is = "CIRCLE" Dim Mycircle As Circle = CType(MyEnt, Circle) message += "Bounds Min point= " & Mycircle.Bounds.Value.MinPoint.ToString & vbLf message += "Bounds Max point= " & Mycircle.Bounds.Value.MaxPoint.ToString & vbLf message += "Center= " & Mycircle.Center.ToString & vbLf message += "Radius= " & Mycircle.Radius.ToString & vbLf message += "Diameter= " & Mycircle.Diameter.ToString & vbLf message += "Circumference= " & Mycircle.Circumference Case Is = "LWPOLYLINE" Dim Mypolyline As Polyline = CType(MyEnt, Polyline) message += "Bounds Min point= " & Mypolyline.Bounds.Value.MinPoint.ToString & vbLf message += "Bounds Max point= " & Mypolyline.Bounds.Value.MaxPoint.ToString & vbLf message += "Area= " & Mypolyline.Area.ToString & vbLf message += "Length= " & Mypolyline.Length.ToString Case Is = "XLINE" Dim Myxline As Xline = TryCast(MyEnt, Xline) message += "Handle= " & Myxline.Handle.ToString End Select MsgBox(message) End If Next acTrans.Commit() End Using End Sub End Class
What's wrong with my code?
Hi!
By looking in my code, does anyone knows why, while adding "Circle" in model space, it returns null specifics properties!?