.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Overrule a specific subentity in block and not showing the Base.

47 REPLIES 47
SOLVED
Reply
Message 1 of 48
JanetDavidson
10255 Views, 47 Replies

Overrule a specific subentity in block and not showing the Base.

Hello,

Facing a new problem. Planning to overrule some of subentities in a block. Let's make it simple . All lines and attributes in block should be circles and original block should not be seen. I came up with below code.

The code reacts differently if  I remove

MyBase.WorldDraw(drawable, Wd)

and my goal is not to show the real block. Just showing whatever is overruled.

Could somebody help me please

 

Thanks.

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

 

47 REPLIES 47
Message 2 of 48
Hallex
in reply to: JanetDavidson

Hell friend,

Try this out, just grabbed from docs example,

change accordingly to your subentity types

 

' (C) Copyright 2002-2009 by Autodesk, Inc. 
'
' Permission to use, copy, modify, and distribute this software in
' object code form for any purpose and without fee is hereby granted, 
' provided that the above copyright notice appears in all copies and 
' that both that copyright notice and the limited warranty and
' restricted rights notice below appear in all supporting 
' documentation.
'
' AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
' AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
' MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
' UNINTERRUPTED OR ERROR FREE.
'
' Use, duplication, or disclosure by the U.S. Government is subject to 
' restrictions set forth in FAR 52.227-19 (Commercial Computer
' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
' (Rights in Technical Data and Computer Software), as applicable.
'
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput

' This line is not mandatory, but improves loading performances
<Assembly: CommandClass(GetType(MyFirstOverrule_VB.MyCommands))> 

Namespace MyFirstOverrule_VB

    'This is our custom DrawableOverrule class.
    'In this case we're just overruling WorldDraw
    Public Class MyDrawOverrule
        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
            'Cast Drawable to Line so we can access its methods and properties
            Dim thisLine As Line = drawable
            'Draw some graphics primitives
            wd.Geometry.Circle(thisLine.StartPoint + 0.5 * thisLine.Delta, thisLine.Length / 2, thisLine.Normal)
            'In this case we don't want the line to draw itself, nor do we want ViewportDraw called
            ' Return True
            Return MyBase.WorldDraw(drawable, wd)
        End Function

    End Class



    Public Class myCommands

        'Shared member variable to store our Overrule instance
        Private Shared mDrawOverrule As MyDrawOverrule

        ' expired by Barbara Hun:
        ' http://adndevblog.typepad.com/autocad/2012/05/get-block-that-entities-are-included-in.html#tpe-actio...
        <CommandMethod("tg")> _
        Public Shared Sub getBlockNameFromItsSubentity()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim ed As Editor = doc.Editor

            Dim db As Database = doc.Database

            Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem

            Dim pno As New PromptNestedEntityOptions(vbLf & "Select a Line inside the Block: ")

            Dim nres As PromptNestedEntityResult = ed.GetNestedEntity(pno)

            If nres.Status <> PromptStatus.OK Then
                ed.WriteMessage(vbLf & "Entsel failed")
                Return
            End If

            Try
                Dim tr As Transaction = db.TransactionManager.StartTransaction()

                Using tr
                    Dim pickPt As Point3d = nres.PickedPoint.TransformBy(ucs)

                    ed.WriteMessage(vbLf & "Picked point is {0}", pickPt)

                    Dim selId As ObjectId = nres.ObjectId

                    Dim objIds As New List(Of ObjectId)(nres.GetContainers())

                    ' Reverse the "containers" list

                    ' Now append the selected entity

                    objIds.Add(selId)

                    objIds.Reverse()

                    ' Retrieve the sub-entity path for this entity

                    Dim subEnt As New SubentityId(SubentityType.Null, 0)

                    Dim path As New FullSubentityPath(objIds.ToArray(), subEnt)

                    ' Open the outermost container, relying on the open

                    ' transaction...

                    Dim pSubEnt As Entity = TryCast(tr.GetObject(objIds(0), OpenMode.ForRead, False), Entity)

                    ' Output the class name of the sub entity

                    ed.WriteMessage(vbLf & "The sub entity is of type {0}", pSubEnt.GetType().Name)
                    ''-----------------------------------------------------------------------------''
                    If TypeOf pSubEnt Is Line Then
                        If mDrawOverrule Is Nothing Then
                            mDrawOverrule = New MyDrawOverrule
                            ' Overrule.AddOverrule(RXObject.GetClass(GetType(Line)), mDrawOverrule, False)
                            Overrule.AddOverrule(RXObject.GetClass(GetType(Line)), mDrawOverrule, False)
                        End If

                        'Toggle Overruling on/off
                        Overrule.Overruling = Not Overrule.Overruling
                        'Regen is required to update changes on screen.
                        Application.DocumentManager.MdiActiveDocument.Editor.Regen()
                    End If
                    ''-----------------------------------------------------------------------------''
                    '' Commented code block:

                    ' Get the object id of the owner block

                    'Dim mainId As ObjectId = pSubEnt.OwnerId

                    'Dim pOwner As DBObject = TryCast(tr.GetObject(mainId, OpenMode.ForRead, False), DBObject)

                    '' Output the class name of the owner block


                    'ed.WriteMessage(vbLf & "The owner is of type {0}", pOwner.GetType().Name)

                    'Dim pBlkName As String = String.Empty

                    '' Output the information of the block definition

                    'Dim pBTR As BlockTableRecord = TryCast(pOwner, BlockTableRecord)

                    'If pBTR IsNot Nothing Then

                    '    pBlkName = pBTR.Name



                    '    ed.WriteMessage(vbLf & "Block Record name is {0}", pBlkName)
                    'End If
                    'Dim pBref As BlockReference = TryCast(pOwner, BlockReference)

                    'If pBref IsNot Nothing Then
                    '    pOwner = TryCast(tr.GetObject(pBref.BlockTableRecord, OpenMode.ForRead, False), BlockTableRecord)

                    '    If pBref.IsDynamicBlock Then
                    '        pBTR = TryCast(tr.GetObject(pBref.DynamicBlockTableRecord, OpenMode.ForRead, False), BlockTableRecord)

                    '        pBlkName = pBTR.Name
                    '    Else
                    '        pBlkName = pBref.Name
                    '    End If


                    '    ed.WriteMessage(vbLf & "Block Reference name is {0}", pBlkName)
                    'End If
                    tr.Commit()
                End Using
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                ed.WriteMessage((vbLf + ex.Message & vbLf) + ex.StackTrace)

            Finally
            End Try
        End Sub
    End Class

End Namespace

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 48
Hallex
in reply to: Hallex

Note in addition about your code above:

AttributeDefinition is part of BlockTablerecord (Block Definition)

it not belongs to BlockReference

 

~'J'~

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 48
JanetDavidson
in reply to: Hallex

Thanks Hallex for your effort to hep but  it is not what I asked

Message 5 of 48
Hallex
in reply to: JanetDavidson

Ok ignore my previous code,

try this one instead

 

    <CommandMethod("OST")> _
    Public Sub TestBlockTransient()
        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        
        Dim opt As New PromptEntityOptions(vbLf & "Select an attributed block instance: ")

        Dim res As PromptEntityResult = ed.GetEntity(opt)

        If res.Status <> PromptStatus.OK Then
            ed.WriteMessage(vbLf + "Nothing selected!")
            Return
        End If

        Try

            Using tr As Transaction = db.TransactionManager.StartTransaction

                Dim obj As DBObject = DirectCast(tr.GetObject(res.ObjectId, OpenMode.ForRead), DBObject)

                Dim bref As BlockReference = TryCast(obj, BlockReference)

                If bref Is Nothing Then

                    Return
               
                End If

                bref.UpgradeOpen()
                Dim expobjs As New DBObjectCollection
                bref.Explode(expobjs)
                bref.Visible = False

                For Each item As DBObject In expobjs
                    If TypeOf item Is AttributeDefinition Then
                        
                        Dim attdef As AttributeDefinition = TryCast(item, AttributeDefinition)

                        If attdef IsNot Nothing Then
                            If Not attdef.IsWriteEnabled Then attdef.UpgradeOpen()
                            attdef.ColorIndex = 1


                            Dim ints As New IntegerCollection
                            GraphicsInterface.TransientManager.CurrentTransientManager.AddTransient(TryCast(attdef, GraphicsInterface.Drawable), GraphicsInterface.TransientDrawingMode.DirectShortTerm, 0, ints)
                            attdef.Visible = False
                        End If
                    Else
                     
                    End If
                Next
         
                '  tr.Commit() 'don't commit it
            End Using
        Catch ex As Autodesk.AutoCAD.Runtime.Exception
            ed.WriteMessage(ex.StackTrace)
        Finally
            GraphicsInterface.TransientManager.CurrentTransientManager.Dispose()
        End Try

    End Sub

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 6 of 48

I am getting some pretty bizarre behavior here as well.

 

I did not have a DrawableOverrule operating on BlockReferences in my code, but I did have one that overruled lines with a certain XData.  (It was really silly code, written as a test case)

 

That code, taken from an example I got (I don't recall where), worked great, did not display the original line, but did properly display my alternate geometry.  Even while zooming or grip editing the line.

 

The code I have returns False from the WorldDraw override (without calling Mybase.WorldDraw) and I thought returning true might be the problem, so I just copied the code from that test overrule into a new class in my "Real" overrules that work on a blockreference, added the overrule to my collection, and tested it.

 

I have since looked up the worldraw method in the ARX help files, and the return value probably should be true, because according to the docs, returning false is telling the graphics system that it must call ViewportDraw to obtain the complete geometry.

 

For what it is worth, my line overrule works fine either way, and does not draw the original line.  It is the call to MyBase.WorldDraw which is supposed to draw the original, unoverruled object, so skipping that call should make it not draw the original block, which is how my original code is working when overruling a Line, but when I switch that code to overrule a Block, Returning false works fine, except it draws the original block (I believe that is happening in the ViewportDraw method).  Returning true doesn't draw the original block, but everything else goes wacky.

 

It is doing really wierd stuff.  Returning false from my WorldDraw override cause correct drawing of my Alternate geometry, along with the original block geometry (not like it works with Line).  Returning True causes it to NOT draw the original Block Geometry, but it also sort of goes berzerk as far as drawing my alternate geometry, occasionally even failing to draw other blocks it is not supposed to be overruling.

 

This is all very bizarre, and  Ihave not yet discovered a solution that works properly.  (except the one where it draws the original block geometry as well as my alternate geometry.)

 

I have now downloaded the DigSigStamp plugin of the month from Autodesk Labs, written by Stephen Preston, and his plugin is doing the same thing as mine (as in, the wierd behavior).

 

I think you picked a winner here.  I have no idea what is going on, but seeing as how code written by the man himself is doing the same thing as mine, I'm thinking there may be some kind of corruption in my AutoCAD install, or my drawing (created new scratch drawing, still does it), or just a bug in AutoCAD.

 

But none of that really makes sense to me, because it would mean that you have to have the same corruption as me, or that the bug has gone unnoticed by everyone else until now (running AutoCAD 2012).

 

My tests have now even gone beyond the bizarre, and running the DigSigStamp plugin is now causing regular geometry such as rectangles to disappear, and they can't be selected by crossing window, but I can select them by ctrl-A or Qselect, at which point I can see the grips but nothing else.  Then I drag one of the grips, and the geometry reappers (same with the overruled block).  Do a regen and it disappears again.

 

I'm stumped... I've tried every combination of thins I can think of, and if I return true and don't call MyBase.WorldDraw, evrything is wonky.  If I return False or if I call MyBase.WorldDraw, everything works fine, but the original block is drawn.  I have no idea why this is behaving any differently for a Block as opposed to a line.

Dave O.                                                                  Sig-Logos32.png
Message 7 of 48

Hi CBC,

 

Would you mind telling me what I need to do to reproduce the weird behaviour in DigSigStamp, so I can take a look.

 

(Not happy if I overlooked some crazy weird stuff Smiley Sad).

 

 

Cheers,

Stephen Preston
Autodesk Developer Network
Message 8 of 48

Hi Stephen,

Thanks for looking into problem.

Draw a circle , one line and one attribute .

Then make a block of these 3 objects. Try to overrule  the line in block . But we don't want to see the rest of  Base( which is Circle and Attribute). After code executed do a Regen or try to select the block or copy.

Hope I explained properly and this is what you asked for to help us .

Janet.

 

 

Message 9 of 48

Janet, you said:

"Try to overrule  the line in block"

 

That is not exactly what I have been trying to do, nor is it exactly what your example code is doing, and also it is not what you should be trying to do, based on my perception of your goal (I'm not trying to be contradictory, or argumentative.  I just want everything to be clear, since it seems you have identified, and brought to my attention, a potentially serious problem with applying a DrawOverrule to a BlockRefrence).  In fact I just changed the Subject Line of my reply to reflect that.

 

Your code, and my attempts, are overruling the Block itself (I can't really tell how you are constructing and applying the overrule, because you did not include that code, but I can tell from this line "Dim myBlock As BlockReference = CType(drawable, BlockReference)"  that you are applying it to the BlockReference, not the Line inside the block, and I believe that is as it should be.  If you just overrule the line inside the block, that will not give you the means to prevent the rest of the block geometry from showing.  (which is actually the only part of this exercise I can not seem to get to work as I think it should).

 

Please see my next post, which is primarily directed at Stephen, but has a couple of questions for you, too, at the end.  (I already composed it, and thankfully predicted that the forum was going to error out because it took so long to write, so I copied it to a text editor and I can just paste it back in.)

Dave O.                                                                  Sig-Logos32.png
Message 10 of 48

Janet, can you fill me in as to what your hardware setup is?
And could you also weigh in on whether my experience is similar to yours, or if you see something different? (see particularly the paragraph I highlighted in Blue)

 

Stephen,


I couldn't possibly believe that you had overlooked this problem, at this point.  For me, it is as plain as day and there has been only one test performed (out of ~50+, probably 45+ on my code, and 6 or 7 on yours) where it worked as expected (see next paragraph).  All I did was run the program as designed, using your sample blocks as the replacement blocks, and, at first, I used Janets sample block as the block to replace.  Then, (because Janets block seems scaled for Metric, and the Geometry is very far from the Origin when using Imperial units) I tried using my companies standard drawing stamp block as the block to replace.  Both tests (repeated several times) produced the same (or very similar) behavior as I was experiencing with my own code.

Possibly the wierdest thing that happened was that when I ran your code, inside the example drawing that is provided with the source code, in the demo directory (with my cohort standing over my shoulder watching, while I tried to demonstrate the problem), it seemed to work just fine, but if I created a brand new clean drawing, and inserted your drawing into it, just to use the blocks you had in there, it acted just like my stuff.  I did not think to try out My code inside your sample drawing, I'll try that tommorrow, too.

My code replaces the block geometry with some arcs and a polyline, instead of replacing one block with another block.  When I run your code, I see nothing at all until I do a Select All, and drag the grip, then the geometry shows up as it should.  And when I run my code, at first I see the arcs, but not the polyline.  The objects are unselectable, either by clicking with the cursor over one of the arcs I can see (which works when my overrule is acting on lines instead of Blocks), or by using a window or crossing over the area where the block should be (also the case when running your code).  But if I use Qselect to select the blocks by name, or Ctrl-A to select all, I see the grips, and if I drag one of the grips, the arcs and polyline (or your block) show up as they should.  Then If I select a different object and drag a grip, the object that was just showing correctly goes back to just showing some arcs.  If I do a regen or regenall, they disappear completely.  I have even had blocks which do contain my Xdata Filter, but are excluded from the overrule by blockname in the WorldDraw override, disappear, and I have had lines and polylines, which are not overruled AT ALL disappear, under seemingly random situations.  I can reproduce the behavior, but it seems to happen some of the time, but not all of the time.  (That is both with your code, and mine).  Also (quite minor compared to the overall problem) I noticed that even when the geometry is showing correctly, after dragging a grip, the objects are not highlighted, even though they are selected, and the grips are showing.  That is also something that works correctly when I overrule a Line instead of a Block.

My code has a few minor differences in the structure, compared to your DigSigStamp code, but ulimately does the same thing, and the important bits (the WorldDraw override) are the same, except I'm drawing simple geometry in place of the block instead of replacing one block with another.  I made no changes to the DigSigStamp code, but I did build the Source myself, and loaded that, in debug mode, instead of loading the .DLL that is pre-built in the download (one more thing I could test)

I am of the impression the problem lies in some sort of corruption (either Cad install, or drawing, like I mentioned above, but I'm leaning away from that now), or that there may be an issue with my video card or it's drivers.

I am on a WinXP 32 bit, Dell T3400 (Intel Dual Core 2.8? GHz, 4 GB RAM) with a NVidia QuadroFX 3700 video card (1 GB DDR3, I think, I am at home right now), and an 80 GB Hard drive stuffed to the max.  Stuffed to the point that I don't have room to install AutoCAD 2013 unless I uninstall one of my Revit versions, or one of my AutoCAD versions.

The machine is almost 4 years old now, and the video card has been a good card in the past, but I killed one of them (swapped another in from an identical machine, of the same age), then I had some driver issues with that one, and swapped to a different identical machine, of the same age.  So maybe I am having driver issues again, or maybe I am just hard on video cards, but I do have options to test this behavior on some older (actually really old) Gateways with GeForce cards or some newer Dells with  Win7 64 bit and (I can't remember the exact model, but I think it is an ATI card of comparable specs to the QuadroFX 3700, and on the Autodesk Approved list)

I plan on doing some more testing tomorrow on those different setups (and the couple of other ideas I had while writing this Novel) and see if I can still reproduce the problem, plus check on the latest drivers for my NVidea card, and see what that does (I know I updated them a few months ago).  NVidea also has an AutoCAD Performance Driver for that card, and I don't think I have it installed, so I'll try that, too.

Dave O.                                                                  Sig-Logos32.png
Message 11 of 48

A couple more things, for Janet:

 

My block that I am overruling contains some 3D Solid geometry (3 extruded regions), several lines, and exactly 4 invisible attributes.  I honestly can not believe that the contents of the block can have any bearing on the function of the overrule.

 

And also I have not tried copying the block, (I think I covered the problems I was seeing with Regen and Select).  What problem have you seen specific to copying the block?

 

For what it is worth, I opened your sample drawing, selected the block, and I don't see grips for your attributes.  I exploded things, to make sure it wasn't a nested block, and I checked properties of the exploded Attribute Definitions, and I can't come up with a valid reason for that.  Any insight?

Dave O.                                                                  Sig-Logos32.png
Message 12 of 48
jeff
in reply to: chiefbraincloud

My post screwed up and not much time but real quick I am getting a little confused.

 

Started a similar thread on subject http://www.theswamp.org/index.php?topic=42487.0

 

I could be completely wrong here bur,

 

A AttributeReference is created for each BlockReference so would be easier to just overrule AttributeReference. If you add Xdata to the AttributeDefinition then it will be cloned with the new AttributeReference and you can just have a DrawableOverriule for AttributeReference with a Xdata filter

 

When WorldDraw() is called on a BlockReference it uses the BlockReference to create a Transformation matrix and pushes it on Transform stack, then it calls Draw() on its BlockTableRecord which draws all the entities in definition, then pops the matrix off stack.

 

 

So if have a DrawableOverrule for BlockReferences and are overriding the WorldDraw() method

and you call base.WorldDraw()

you just told it to

1. Get the transformation, scale, rotation, etc... from the blockreference and send it to the graphics pipeline which will apply that to each entities model coordinates.

2. Call Draw() on the BlockTableRecord of the Reference which calls WorldDraw() on each entity in the BlockTableRecord, which will have the transformation matrix applied to it.

3. Remove the Transformation matrix from graphics pipeline.

 

More to it but in simple terms you can think a BlockReferences WorldDraw() just knows how to apply a transformation matrix to be applied for each entity in definition.

 

 

For returning true of false from WorldDraw(),

 

Basiclly what happens is

 

Drawable.SetAttributes()

 

If Drawable.WorldDraw() = False

 

For each Viewport

Drawable.ViewPortDraw

 

End If

 

Whatever you do WorldDraw is for every viewport.

 

If you return true ViewportDraw is not called but if false the ViewPortDraw is called for each Viewport.

Could show different geometry for TOP and BOTTOM view, etc... and whatever needs to be shared would be drawn in WorldDraw.

 

Different ways not sure which way is best but could have Xdata attached lines inside definition.

 

You could inside your BlockReference WorldDraw add a overrule for overruling entites in definition, then call the base.WorldDraw() then remove the Overrule and retuen true or false.

 

 

 

 

You can also find your answers @ TheSwamp
Message 13 of 48


 

And also I have not tried copying the block, (I think I covered the problems I was seeing with Regen and Select).  What problem have you seen specific to copying the block? The Copied Block Disappears

 

For what it is worth, I opened your sample drawing, selected the block, and I don't see grips for your attributes.  I exploded things, to make sure it wasn't a nested block, and I checked properties of the exploded Attribute Definitions, and I can't come up with a valid reason for that.  Any insight?  I didn't want user to see Attribute Grip.


 

Message 14 of 48

Here is the Spec:

HP - QuadCore - i 5 - 3 GigHz - Win 7 64 - Autocad 2012 64 -  8 GiG Ram - and NVidia nv300 .

 

My code and My block works findeif I leave  this line :

MyBase.WorldDraw(drawable, Wd)

But If I remove the line

MyBase.WorldDraw(drawable, Wd)

 

Then it will do exactly what you mentioned .

Janet.

 

Message 15 of 48

CBC: Quick question - When you have these display problems, are you using a 3D shademode? Do you see the same problems in 2D wireframe also?

 

I ask because 3D shademodes use a different graphics pipeline that caches graphics to optimize performance. There's extra work needed to support that when overruling a block reference, which (as I recall)  I didn't do in DigSigStamp.

 

 

Cheers,

Stephen Preston
Autodesk Developer Network
Message 16 of 48

I have not been in a shade mode, I have been using 2d Wireframe.  So far today, still no progress.  Updating Video driver did not help.  Testing my code in your example drawing did not help.  The NVidea AutoCAD Performance Driver indicates that it is for 2009, 2010, and 2011, no mention of 2012, so I don't think that is going to help.

 

I'm getting ready to try it out on some other machines now.

Dave O.                                                                  Sig-Logos32.png
Message 17 of 48

Janet,

 

(While I'm trying to reproduce the weirdness that CBC and you describe ... my DigSigStamp sample is working fine for me) ...

 

If I were selectively drawing the entities in a BlockTableRecord as you are doing, I wouldn't be exploding the BlockReference, calling WorldDraw on the resultant entities and then disposing all the entities. Instead, I'd iterate through the entities in the BlockTableRecord that the BlockReference represents, and call Geometry.Draw(entity) on each entity I wanted to display.

 

If you read the reference guide documentation for Geometry.Draw, you'll see that this is how a BlockReference actually draws itself. You can use Geometry.Draw() when you want to draw something that has a lifetime that spans at least the lifetime of the graphics cache (like the contents of a BlockTableRecord). Never use it with temporary entities you plan to dispose as soon as you've used them.

 

And if you want your overrule to work correctly in a 3D shademode, you have to also overrule at least ViewportDrawLogicalFlags as well. I believe my bonus sample for the My First AutoCAD Plugin tutorial demonstrates that (you can find that on www.autodesk.com/developautocad).

 

And of course, if the blocks you want to customize are your own, then it would probably be a lot simpler to use the dynamic blocks feature instead if they can achieve what you need. You're right that overrules are complicated - to overrule an entity, you have to know a lot of the concepts required to create a custom entity using ObjectARX. That's probably the most complicated API AutoCAD exposes.

 

HTH.

Cheers,

Stephen Preston
Autodesk Developer Network
Message 18 of 48

Stephen and Chief,

Thanks for your time to look into my  problem. 

Stephen

The blocks in real scenario  are dynamic blocks and more  complicated than the one I attached . I just  tried to present the  problem in an easy way so people bother to look into it. We don't need them to work in 3D Shades Mode ,  in our company, Thanks God. 

I tried hard to digest your DigSigStamp but it is complicated.

It would be nice of you  if you do all of us in this discussion group  a favor and

convert  my  code in a classic and proper way(Geometry .Draw ) to work with the block I attached.

I am pretty sure converting my simple code would be piece a cake for you.

I just need the line to be seen as a  circle , and everything else disappear.

Hope your skills and knowledge  help us to understand this overrule by simple samples like this rather than complicated

terminology in documents .

Cheers and Thanks

Janet.

 

 

Message 19 of 48


@StephenPreston wrote:

 

If you read the reference guide documentation for Geometry.Draw, you'll see that this is how a BlockReference actually draws itself. You can use Geometry.Draw() when you want to draw something that has a lifetime that spans at least the lifetime of the graphics cache (like the contents of a BlockTableRecord). Never use it with temporary entities you plan to dispose as soon as you've used them.

 


Hi. I don't seem to have any problem with drawing temporary entities and disposing them right away. Their graphics belong to the Drawable that's passed into the WorldDraw call, rather than to entities passed to Geometry.Draw().

 

For example, here's some code I was just toying with, that customizes the text of entities nested in blocks, notice that I clone the original text, modify it, and then dispose the clone after drawing it. I don't have any problems with this code.

 

   public class NestedTextDrawOverrule : NestedDrawableOverrule<DBText>
   {
      protected override bool WorldDraw( DBText text, WorldDraw wd )
      {
         BlockReference outerMost = this.OuterMostContainer;
         if( outerMost != null && text.Database != null )
         {
            using( DBText surrogate = (DBText) text.Clone() )
            {
               surrogate.TextString = outerMost.Name;
               surrogate.AdjustAlignment( text.Database );
               wd.Geometry.Draw( surrogate );
               return true;
            }
         }
         return base.WorldDraw( text, wd );
      }
   }

 

Message 20 of 48
jeff
in reply to: DiningPhilosopher

When I get a little time later will post code but I am having issues also.

You can also find your answers @ TheSwamp

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost