.NET

.NET

Reply
Distinguished Contributor
JanetDavidson
Posts: 141
Registered: ‎08-23-2011
Message 1 of 12 (256 Views)

Overruled block using Explode method don't generate overruled entities.

256 Views, 11 Replies
07-20-2012 07:58 AM

Hello there.

I need help again.

Say I have a block which contains  just a line inside. I overruled that block  to show a  circle. I have this overruled  explode class, so whenever user at command pormpt  explode that entity it would be exploded as a circle.

My problem is when I explode the block within code ( Myblockref.Eplode(dbobjects) ) . it will bring the line.

How to fix this ? Any Help?

Thanks in Advance

Janet.

 

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 2 of 12 (249 Views)

Re: Overruled block using Explode method don't generate overruled entities.

07-20-2012 10:13 AM in reply to: JanetDavidson

I'm assuming that this is a test excercise that you will use for a different purpose later, otherwise you could just Overrule the Line and turn it into a circle, instead of creating a block to Overrule.

 

It sounds to me like the Tranform Overrule is not registered properly.  Have you tried putting a breakpoint in the explode method?  Does it get hit?

 

Other than that I would need to see some code to tell what is happening.

Dave O.                                                                  Sig-Logos32.png
Distinguished Contributor
JanetDavidson
Posts: 141
Registered: ‎08-23-2011
Message 3 of 12 (244 Views)

Re: Overruled block using Explode method don't generate overruled entities.

07-20-2012 11:37 AM in reply to: chiefbraincloud

Hello again Chief .

Yes you are right the  block is more complicated than a circel / line.

When explode the block thru command line ( Explode command )  it gets hit but when  I do it thru code from another class it never gets hit.

I will try to make it a simple code ( Like the line and circle ) and post it here . This weekend I will do it. Thanks for looking.

I have a feeling transform overrule is just responsive to command line. Am I stupid ?

 

 

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 4 of 12 (236 Views)

Re: Overruled block using Explode method don't generate overruled entities.

07-20-2012 12:15 PM in reply to: JanetDavidson

You may be right about that.  I don't think I ever tried to Explode my overruled blocks using .NET.  A quick search reveals that I have not.

 

It shouldn't be that big a deal, though, if you set your code up like I have.  I have a GetEntSet Method with a Byref DbObectCollection Argument, which adds the necessary entities to the collection.  It is called by both my WorldDraw Overrule, and my Explode Overrule.  Then, if I needed to explode one of my overruled entities from .NET code, I could just call  my GetEntset Method, passing an empty DbObjectCollection, instead of calling the built in Explode method.

 

For what it is worth, the code I'm talking about above is actually Overruling the Line Class with an XData marker.  The only reason I have an overrule on the BlockReference Class is because of a particular block that my program creates which is a 3D block and always scaled Non-uniformly.  AutoCAD will not Explode Non-Uniformly scaled blocks, so I had to put the Overrule in to allow the users to Explode it.  I'm not doing a DrawOverrule on any blocks.

 

I guess the point is, no matter how complicated the geometry is that you need to draw, you can still overrule line, or Polyline, or even DbPoint, and tell it to draw whatever you want, so what you should do is Overrule the AutoCAD object that most closely resembles the type of behavior you would like your Overruled Object to present.

 

Appologies if you have already realized that, and chose BlockReference as the most appropriate object.

Dave O.                                                                  Sig-Logos32.png
Distinguished Contributor
JanetDavidson
Posts: 141
Registered: ‎08-23-2011
Message 5 of 12 (227 Views)

Re: Overruled block using Explode method don't generate overruled entities.

07-20-2012 01:42 PM in reply to: chiefbraincloud

Thanks Chief

 I  am a female and don't understand these Pro stuff you mentioned here, How easy would it be to show me in more detail please.  Janet.

 


  if you set your code up like I have.  I have a GetEntSet Method with a Byref DbObectCollection Argument, which adds the necessary entities to the collection.  It is called by both my WorldDraw Overrule, and my Explode Overrule.  Then, if I needed to explode one of my overruled entities from .NET code, I could just call  my GetEntset Method, passing an empty DbObjectCollection, instead of calling the built in Explode method.

 

 

 

*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 6 of 12 (215 Views)

Re: Overruled block using Explode method don't generate overruled entities.

07-20-2012 10:39 PM in reply to: JanetDavidson

Don't sell yourself short... being a woman has nothing to do with it.  And, the bits of code I'm talking about are less complicated than Overrules in general.  Using Overrules in the ACAD API is something I would consider to be advanced, or at least upper level Intermediate, which is where I consider myself to be.

 

It's late here, and I'm going to the Mile High Nationals tomorrow, (you can google it if you don't know what that is), so I won't be able to get back to this until late Sunday or maybe Monday.  If you still want to throw together some code showing your approach this weekend, that might make it easier for me to tailor my response to your code, otherwise, I'll throw something together showing my approach, but either way, don't expect to see anything until late Sunday, or maybe Monday.

Dave O.                                                                  Sig-Logos32.png
Distinguished Contributor
JanetDavidson
Posts: 141
Registered: ‎08-23-2011
Message 7 of 12 (200 Views)

Re: Overruled block using Explode method don't generate overruled entities.

07-22-2012 08:14 AM in reply to: chiefbraincloud

Hello . Here you go, this is  the code I have in  simple form. Please teach me how could I get the objects from another class/sub  from below class . I tried to change 

OverridesSub explode(ByVal e AsEntity, ByVal DBobjs AsDBObjectCollection)

to

OverridesSub explode(ByVal e AsEntity, ByRef DBobjs AsDBObjectCollection)

doesn't work.

Thanks again for help.Janet

 

Public Class test1
    Public Shared BlockExplodeOverrule As Block_XdataTransformOverrule
    Public Shared Sub StartMyExplodeOverrule()
        If BlockExplodeOverrule Is Nothing Then
            BlockExplodeOverrule = New Block_XdataTransformOverrule
            ObjectOverrule.AddOverrule(RXClass.GetClass(GetType(BlockReference)), BlockExplodeOverrule, True)
        End If
    End Sub
    Public Class Block_XdataTransformOverrule
        Inherits TransformOverrule
        Public Overrides Sub explode(ByVal e As Entity, ByVal DBobjs As DBObjectCollection)
            Dim myBlock As BlockReference = TryCast(e, BlockReference)
            If Not myBlock.Database Is Nothing Then

                Dim ListEnts As New List(Of Entity)
                Dim acDBObjColl As DBObjectCollection = New DBObjectCollection()
                TryCast(myBlock.Clone, BlockReference).Explode(acDBObjColl)
                Dim myline As New Line

                Dim mydbobj As DBObject = acDBObjColl(0)
                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)
                    DBobjs.Add(ListEnts(0))
                End If
                DBobjs.Add(ListEnts(0))
                Return
            End If
            MyBase.Explode(e, DBobjs)
        End Sub
    End Class
End Class

 





*Expert Elite*
chiefbraincloud
Posts: 753
Registered: ‎02-13-2008
Message 8 of 12 (175 Views)

Re: Overruled block using Explode method don't generate overruled entities.

07-24-2012 11:25 PM in reply to: JanetDavidson

I appologize for not getting back yesterday, I've been unexpectadly busy at work the last couple of days (and still).

 

First, in regards to your ByRef/Byval delima (which actually took me a while to see the difference in what you had posted), as I understand it, an argument of Reference type is always passed ByRef, even if declared ByVal.  That is something I am personally confused about at this point.

 

Second, As your code is written, with the Public Shared BlockExplodeOverrule, the simplest way to do what I was suggesting is to explicitly call BlockExplodeOverrule.Explode from your code that needs to explode the block.  (And for the record, I would at the very least change that to be Friend Shared, so that it can not be exploited)

 

Third, I am positive there are really good reasons NOT to have a Shared Overrule.  (I'm not even going to get into the fact that your code Overrules all BlockReferences, I assume that is because you are cutting too much out of your code for me to see how you are Overruling just those blocks you want)

 

I did get started on modifying my code for posting, but I didn't finish.  I was too busy preparing for, and attending, a meeting about my current project.  I will keep working on it (shouldn't take too much longer, when I get the time).

Dave O.                                                                  Sig-Logos32.png
Distinguished Contributor
JanetDavidson
Posts: 141
Registered: ‎08-23-2011
Message 9 of 12 (166 Views)

Re: Overruled block using Explode method don't generate overruled entities.

07-25-2012 08:41 PM in reply to: chiefbraincloud

Thanks chief for getting back to me. I knew you are busy as you mentioned it before.

Yes, as you guessed I cut  codes to make it simple for your review, actually there are some Xdata attached.

As for friend shared or public shared, I have no idea what is the difference .

Take your time and thanks for it.

 

Janet.

 

Valued Mentor
jeff
Posts: 338
Registered: ‎05-12-2009
Message 10 of 12 (158 Views)

Re: Overruled block using Explode method don't generate overruled entities.

07-25-2012 11:41 PM in reply to: chiefbraincloud

chiefbraincloud wrote: 

 

First, in regards to your ByRef/Byval delima (which actually took me a while to see the difference in what you had posted), as I understand it, an argument of Reference type is always passed ByRef, even if declared ByVal.  That is something I am personally confused about at this point.

 

 


I am way too tired to even type this but will give better explanation with code examples tomorrow.

 

That is a common misconception that is commonly stated, and accepted by many.

Sorry but just to tired to to go in detail so it will make sense but will do tomorrow.

 

But quickly and might help you figure it out ,

If that were true then would set argument passed in to null

   

     Sub foo(ByVal value As ReferenceType)

       value = Nothing

     End Sub

 

Just have to explain value vs reference types and what is stored in variables.

Got to get some sleep

 

This should sum it though 

Value Types and Reference Types

Parameter passing

 

 

 

 

You can also find your answers @ TheSwamp
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.