.NET

Reply
Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 1 of 24 (699 Views)
Accepted Solution

overrule is really confusing ....

699 Views, 23 Replies
08-14-2012 12:02 PM

 

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

 

 

 

 

 

 

 

ADN Support Specialist
Posts: 349
Registered: ‎05-22-2006
Message 2 of 24 (641 Views)

Re: overrule is really confusing ....

08-16-2012 04:07 PM in reply to: JanetDavidson

Hi janet,

 

Hopefully the sample code I posted in the other thread on this topic gives you what yuo need to fix your problem.

 

Cheers,

Stephen Preston
Autodesk Developer Network
*Expert Elite*
chiefbraincloud
Posts: 750
Registered: ‎02-13-2008
Message 3 of 24 (605 Views)

Re: overrule is really confusing ....

08-20-2012 08:41 AM in reply to: JanetDavidson

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::smileyfrustrated: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
        End If
        Return res
      End Function

Dave O.                                                                  Sig-Logos32.png
Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 4 of 24 (591 Views)

Re: overrule is really confusing ....

08-20-2012 10:00 AM in reply to: chiefbraincloud

That was great-everything is working now  , Are you Tony? hehehehhe.

Thanks chief . The other thread screwed.

 

 

*Expert Elite*
chiefbraincloud
Posts: 750
Registered: ‎02-13-2008
Message 5 of 24 (537 Views)

Re: overrule is really confusing ....

09-06-2012 12:19 AM in reply to: JanetDavidson

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.

Dave O.                                                                  Sig-Logos32.png
Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 6 of 24 (510 Views)

Re: overrule is really confusing ....

09-06-2012 10:11 AM in reply to: JanetDavidson

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 .

Janet.

 

Valued Mentor
Posts: 370
Registered: ‎05-06-2012
Message 7 of 24 (493 Views)

Re: overrule is really confusing ....

09-06-2012 02:46 PM in reply to: JanetDavidson

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.

Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 8 of 24 (478 Views)

Re: overrule is really confusing ....

09-06-2012 09:07 PM in reply to: DiningPhilosopher

Hello, DP.

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.

Thanks Janet 

 

Valued Mentor
Posts: 370
Registered: ‎05-06-2012
Message 9 of 24 (455 Views)

Re: overrule is really confusing ....

09-07-2012 12:47 PM in reply to: JanetDavidson

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.

 

Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 10 of 24 (445 Views)

Re: overrule is really confusing ....

09-07-2012 01:20 PM in reply to: JanetDavidson

:womansad:

 

Thanks. I thought you are Tony.

Spoiler
:womansad:

 

 

 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 ?

Janet

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community