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.
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.
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 ?
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.
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.
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.
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
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).
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.
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
I still haven't finished modifying my code yet. I didn't get to work on it at all today.
Friend means "I can access this from anywhere inside the same assembly (.dll)"
Public means "I can access this from other assemblies."
Private means "I can only be accessed from within code in this level of code (Class, or Method depending on where it is declared)"
So if you declare things as Public, other assemblies could potentially call into your code. You should only declare things as Public when AutoCAD requires it (like with Command Methods), or when you want to access it from another assembly. Admittedly, that might be a low risk for you, as it is for me, and also admittedly, sometimes it is the desired behavior, like with my Cadtools .dll which I reference into all of my other projects. I just thought I should mention it, in this case in particular, because it would seem that you should not provide other programmers with the means to Explode your custom objects.
"Shared" is a whole different animal altogether, and it is a little difficult to explain. In the simplest terms I can come up with, the opposite of "Shared", ie. anything NOT declared as Shared in VB, is an "Instance" variable (or object), meaning each instance of the class would have it's own instance of the variable. If the variable or Object is declared as Shared, then there is only one instance of the variable that all instances of the class use. Overrules should be Instantiated for each drawing that they apply to, so IMHO, you should not have a Shared variable for your Overrule.
I don't think I explained that very well, but I hope it helps. When I finally finish putting my example together, it might help a little more. I think now, after writing this, I will expand my example to be a complete project, instead of just a few methods that belong in a Class.
Right now, I've got to hit the sack.
You could've been a teacher. It was good explanation. I understood it. I google it and could not understand those terms. ( Like Modifiers & initialized & .... )
but your explanation was clear.
Janet.
Can't find what you're looking for? Ask the community or share your knowledge.