Hello,
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 )
MyBase.WorldDraw(drawable, Wd).
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.
Janet
Public Class toverrule Inherits Autodesk.AutoCAD.GraphicsInterface.DrawableOverrule 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.
Solved by chiefbraincloud. Go to Solution.
I don't have time to play. but : Just a WAG.
Are your entitys being redrawn while they are being selected for the DIST command ??
If so, this may be causing havoc with some of the AutoCAD Assemblies behind the scenes.
As I said, just a guess.
//-------------
And just for my curiosity : why do you have 2 attribute tags with the same name ??
// Called Kerry in my other life.
Everything will work just as you expect it to, unless your expectations are incorrect.
class keyThumper<T> : Lazy<T>; another Swamper
@JanetDavidson wrote:
originally in my code had a [ ref ] for ListEnts, which in your revised version it was removed.
Below is what I had originally
if (!toverrule.GetExplodedEnts(myBlock,ref ListEnts))
and this is your revised one
if (!toverrule.GetExplodedEnts(myBlock,ref ListEnts))
I had to put ref back to make the code work properly
Hi Janet. 'ref' (or ByRef in VB) is not necessary in both the call and the called method's argument list. The object you're passing (a List<Entity>) is a reference type, which is implicitly passed by reference (e.g, a copy of the object is not passed, only a reference to it). So, when you are writing methods that take reference types as parameters, you should never use 'ref' (or 'ByRef' in VB).
Hey guys,
I think the problem stems from having attribute reference's.
Janet if you try your code on a block without attributereferences does it still crash?
I guess it would need to call get GetObjectSnapPoints() on the attribute references also.
Should a blockrefence just handle insertion snap point, and let the entites inside the definition handle the overloaded GetObjectSnapPoints with insertionMatrix?
But GetObjectSnapPoints uses graphics on the screen I think?
Jeff.
I did a lot of try and error to narrow down the problem. Yes, this happens if block has attribute and in or overrule we try to draw a polyline. I did a circel instead of polyline and this doesn't happen.
I am not a pro and don't understand your other suggestions and questions. Sorry . My fault . You helped me beofre a lot of times and you know my skills are very limited. Sorry again.
Kerry.
Quote<
Are your entities being redrawn while they are being selected for the DIST command ??
Quote>
How would I know ? It crashes before I do anything. If you don't have time please dont' waste your time to read this thread I will send you a private message when it is solved! Typical Kerry
Quote<
And just for my curiosity : why do you have 2 attribute tags with the same name ??
Quote>
It was just accident . Even having one attribute cause this crash.
Tony.
AutoCad 2012 64 - Windows 7 -
Any Running Snaps make this happen.
Thank you gentlemen for looking into this.
Regards,
Janet.
Hi folks
I stumbled across overrule from one of Kean's blogs.
But I could not for the life of me find any documentation on it.
a request for documentation on this other thread was not successful.
Do you know where and how I can learn more about ovverrules.
While Kean's post was useful: http://through-the-interface.typepad.com/through_the_interface/2009/02/the-new-apis-in-autocad-2010-... there a still a lot of questions i have.
anyways, if any body has ideas on how people can learn and master this thing - that would be much appreciated.
kind regards
BK
Hi!
I see one issue with the worldraw implementation:
For Each Ent As Entity In ListEnts Ent.WorldDraw(Wd) Ent.Dispose() Next
The documentation for worldraw has the following statement:
Warning When a custom entity implements subWorldDraw() or subViewportDraw(), and if a native entity (e.g., AcDbCircle) is created within the scope of the method, the native entity needs to exist beyond the method’s scope. The variable should be declared in a global or class level, or some level where the object is alive even after exiting the method.
So you shouldn't dispose them at this time.. You should store them somewhere, and dispose the entities from the previous call to worlddraw upon entering the method.