I have to repost this because people may think, last post was answered, but it wasn't and still I am struggling and need a pro to help me here .
Have a overruled block with attribute in it , I just registered the attributes in my overrule class.
I need to overule (make it simple) just lines ( let's say make them circles) and don't want to show the attributes neither do the rest of objects in block . But if user double click on overruled block I need to show attribute tag input table (Dialog). And don't want to show other objects in block if any exists.
Below is my code and I thought solution would be easy and I have to REM ( or remove the line )
But when I do that the block is not selectable and a regen crash the autocad . That was my story and here is the code.
I appreciate any help here. For your convenience a simple block is attached.
Public Class toverrule Inherits Autodesk.AutoCAD.GraphicsInterface.DrawableOverrul
e Public Overrides Function WorldDraw(ByVal drawable As Autodesk.AutoCAD.GraphicsInterface.Drawable, ByVal Wd As Autodesk.AutoCAD.GraphicsInterface.WorldDraw) As Boolean Dim myBlock As BlockReference = CType(drawable, BlockReference) If Not myBlock.Database Is Nothing Then Dim ListEnts As New List(Of Entity) Dim MyDBObjColl As DBObjectCollection = New DBObjectCollection() myBlock.Explode(MyDBObjColl) Dim myline As New Line For Each mydbobj As DBObject In MyDBObjColl If TypeOf mydbobj Is Line Then myline = TryCast(mydbobj, Line) Dim mycircle As New Circle mycircle.Radius = myline.Length mycircle.Center = myline.StartPoint ListEnts.Add(mycircle) ElseIf TypeOf mydbobj Is AttributeDefinition Then Dim mycircle As New Circle mycircle.Radius = myline.Length / 2 mycircle.Center = myline.StartPoint ListEnts.Add(mycircle) End If Next For Each Ent As Entity In ListEnts Ent.WorldDraw(Wd) Ent.Dispose() Next MyBase.WorldDraw(drawable, Wd) End If Return True End Function End Class
Solved! Go to Solution.
Hopefully the sample code I posted in the other thread on this topic gives you what yuo need to fix your problem.
Mine is working great now.
This is the important bit of Stephens code that you are still missing.
Public Overrides Function SetAttributes(ByVal drawable As Autodesk.AutoCAD.GraphicsInterface.Drawable, ByVal traits As Autodesk.AutoCAD.GraphicsInterface.DrawableTraits) As Integer
Dim res As Integer = MyBase.SetAttributes(drawable, traits)
'See ARX ref guide entry for "AcGiDrawable:etAttributesFlags Enumeration"
'Bit 32 indicates entity has attributes. If we unset that bit,
' then overruling blockref with attributes works fine. We do
' this because we're drawing the attributes ourself.
Dim test As Integer = res And 32
If test Then
res = res - 32
The credit belongs to Stephen Preston. I was already overriding the SetAttributes function in my code, but I did not know that I needed to remove the 32 bit for blocks with attributes. That part came from Stephen, and that is the only part that was missing from my original code, to make it work.
Chief I am facing a new problem again with same overrule.
I have osnaps overrule and it works fine. But when I used distannce command and sanps to overrule block with attribute it crashes. everything else works fine while snapping to overrule block but this is something .
Do you mind to take a look at it if you have time? I can make it simple for your convenience .
Maybe it'll never happen in your circumstance, but you should at least know that if you use the overrule Stephen posted (or any overrule targeting BlockReference for that matter), in a drawing that contains a table that has blocks containing text inserted into the table's cells, AutoCAD will crash when you save the drawing.
Thanks for all support
I did use SP's Attribute Overrides Function. It solved most of my problems. And I realized Geometry Draw acting goofy.
So I used word draw , even though Geometry draw is faster on regen.
Right now everything works fine except for Autocad Distance command. It crashes.
If you or CB can help me, I would be very grateful. Attached is block drawing file and code. Basically I replaced the lines in block with 2 polylines, the same length. Try to do a Distance between polylines. It crashes the machine.
Hope I can get help from you gentlemen again.
Janet, I don't code in VB.NET unfortunately, and can't easily test your code.
What I will tell you, is that overrules are one of the most complicated aspects of AutoCAD .NET programming, and certainly not a good vehicle for an introductory tutorial, so perhaps you've gotten the wrong impression that overrules are relatively-simple to write and debug when in fact, they are a challenge for even highly experienced AutoCAD .NET programmers.
About your code, one major problem I see by just looking at it, is that it calls Explode() on a block reference, and then returns a subset of the entities produced by Expode(), but fails to call Dispose() on the entities that aren't returned to the caller, which will likely cause AutoCAD to crash at some later point, and may very likely be what's happening to you.
Thanks. I thought you are Tony.
But thanks at least you looked at it. In my original code I disposed all entities and still the same.
Just distance command make this crash.
If I convert it in C# would you please look at it ?
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.