Author Topic: Block walk, help needed in testing  (Read 7233 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Block walk, help needed in testing
« on: September 22, 2009, 06:15:43 PM »
This is another attempt at figuring out what the person on the Ad Ng wants, but I think I have it figured out, but there is one issue that I don't really understand, as I don't delete any object in the code.  Below is most of the message I posted over there.  The code is supposed to mimic laywalk, but with blocks.  It did it on my test drawing.  It's slow at the beginning because it is gathering all the info to run the other part of the code, but once the initial setup is done it is pretty quick.  Then putting the drawing back the way it was is a little slow also.   :-D  That was even funny to me when typing it.  Oh well..... what can you do.  Let me know what you think.

In the middle of testing right now, as it seems to delete some objects when it shouldn't and I can't figure out why, but it seems to do what you want besides that, so if you test it, don't use it on a drawing you want to save. I think it has something to do with hatch patterns, and their boundaries, but that is just a guess right now. Here is the code, and the dcl file is attached, which is the same as the previous dcl file, just using a different dcl from there.

Edit:  Update code.  Works with nested blocks, xrefs and dynamic blocks.  Little slow at beginning and ending, since I have to regen ( update ) each object instead using the Regen method, but it works better this way, as it won't create new blocks for dynamic ones.  As usual, let me know how it works for you.  I might even keep/use this one myself.   :-)

Code: [Select]
(vl-load-com)
(defun c:BlockWalk (/ *error* VisList ActDoc LayList NestInsList OldNum cLay tempList BlkList MainName XdataInfo tempName NestWithInList NestList InsList tempVisList )
   
    (defun *error* (msg)
   
        (foreach i VisList
            (vla-put-Visible (car i) (cdr i))
        )
        (vlax-for lo (vla-get-Layouts ActDoc)
            (vlax-for i (vla-get-Block lo)
                (vla-Update i)
            )
        )
        (foreach i LayList
            (vla-put-LayerOn (car i) (cadr i))
            (if (/= (vla-get-Name (car i)) cLay)
                (vla-put-Freeze (car i) (caddr i))
            )
            (vla-put-Lock (car i) (cadddr i))
        )
        (foreach i NestInsList
            (vla-put-Visible i :vlax-true)
        )
        (if msg (vl-bt))
    )
    ;--------------------------------------------------------------------
    (defun GetLayInfo ( doc / ObjList )
       
        (vlax-for obj (vla-get-Layers doc)
            (setq ObjList
                (cons
                    (list
                        obj
                        (vla-get-LayerOn obj)
                        (vla-get-Freeze obj)
                        (vla-get-Lock obj)
                    )
                    ObjList
                )
            )
            (vla-put-LayerOn obj :vlax-true)
            (if (/= (vla-get-Name obj) cLay)
                (vla-put-Freeze obj :vlax-false)
            )
            (vla-put-Lock obj :vlax-false)
        )
        ObjList
    )
    ;-----------------------------------------------------------------------
    (defun SelectBlock ( Listof  / DiaLoad )
       
        (setq DiaLoad (load_dialog "MyDialogs.dcl"))
        (if (new_dialog "MyPropsList" DiaLOad)
            (progn
                (start_list "PropsListbox2" 3)
                (mapcar 'add_list Listof)
                (end_list)
                (action_tile "PropsListbox2"
                    "(if (= $reason 1)
                        (progn
                            (mode_tile \"PropsListbox2\" 1)
                            (UpdateDrawing (atoi (get_tile \"PropsListbox2\")))
                            (mode_tile \"PropsListbox2\" 0)
                            (mode_tile \"PropsListbox2\" 2)
                        )
                    )"
                )     
                (action_tile "cancel" "(done_dialog 0)")
                (start_dialog)
            )
        )
    )
    ;-------------------------------------------------------------
    (defun UpdateDrawing ( num / tempList )
       
        (if OldNum
            (progn
                (setq tempList (nth OldNum BlkList))
                (foreach i (cdr tempList)
                    (vla-put-Visible i :vlax-false)
                )
                (if (setq tempList (assoc (car tempList) InsList))
                    (foreach i (cdr tempList)
                        (foreach att (append (vlax-invoke i 'GetAttributes) (vlax-invoke i 'GetConstantAttributes))
                            (vla-put-Visible att :vlax-false)
                        )
                        (vla-Update i)
                    )
                )
            )
        )
        (foreach i NestInsList
            (vla-put-Visible i :vlax-false)
        )
        (setq NestInsList nil)
        (setq tempList (nth num BlkList))
        (foreach i (cdr tempList)
            (vla-put-Visible i :vlax-true)
        )
        (if (setq tempList (assoc (car tempList) InsList))
            (foreach i (cdr tempList)
                (foreach att (append (vlax-invoke i 'GetAttributes) (vlax-invoke i 'GetConstantAttributes))
                    (vla-put-Visible att :vlax-true)
                )
                (vla-Update i)
            )
        )
        (MakeBlockVisible (car tempList))
        (setq OldNum num)
    )
    ;------------------------------------------------------------------------
    (defun MyGetXData (Obj DataName / CodeType DataType)
        ; Retrive XData for an object
       
        (vla-GetXData
            Obj
            (if DataName
                DataName
                ""
            )
            'CodeType
            'DataType
        )
        (if (and CodeType DataType)
            (mapcar
                '(lambda (a b)
                    (cons a (variant-value b))
                )
                (safearray-value CodeType)
                (safearray-value DataType)
            )
        )
    )
    ;------------------------------------------------------------------------
    (defun MakeInsertsVisible ( name )
       
        (foreach i (cdr (assoc name InsList))
            (vla-put-Visible i :vlax-true)
            (vla-Update i)
            (setq NestInsList (cons i NestInsList))
        )
        (foreach i (cdr (assoc name NestWithInList))
            (MakeInsertsVisible i)
        )
    )
    ;---------------------------------------------------------------------
    (defun MakeBlockVisible ( name )
       
        (foreach i (cdr (assoc name BlkList))
            (vla-put-Visible i :vlax-true)
            (vla-Update i)
            (setq NestInsList (cons i NestInsList))
        )
        (MakeInsertsVisible name)
        (foreach i (cdr (assoc name NestList))
            (MakeBlockVisible i)
            (MakeInsertsVisible i)
        )
    )
    ;---------------------------------------------------------------------
    (setq cLay (getvar 'CLayer))
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (setq LayList (GetLayInfo ActDoc))
    (vlax-for blk (vla-get-Blocks ActDoc)
        (cond
            ((equal (vla-get-IsLayout blk) :vlax-true)
            )
            ((not (wcmatch (vla-get-Name blk) "`*D*"))
                (setq tempVisList nil)
                (setq BlkList
                    (cons
                        (cons
                            (setq MainName
                                (if (setq XdataInfo (MyGetXData blk "AcDbBlockRepBTag"))
                                    (strcat (vla-get-Name (vla-HandleToObject ActDoc (cdr (assoc 1005 XdataInfo)))) " _-_ ( " (vla-get-Name blk) " )")
                                    (vla-get-Name blk)
                                )
                            )
                            (progn
                                (vlax-for i blk
                                    (setq VisList (cons (cons i (vla-get-Visible i)) VisList))
                                    (if (equal (vla-get-Visible i) :vlax-true)
                                        (setq tempVisList (cons i tempVisList))
                                    )
                                    (if (= (vla-get-ObjectName i) "AcDbBlockReference")
                                        (progn
                                            (vla-put-Visible i :vlax-true)
                                            (setq tempName
                                                (if
                                                    (and
                                                        (vlax-property-available-p i 'EffectiveName)
                                                        (/= (vla-get-EffectiveName i) (vla-get-Name i))
                                                    )
                                                    (strcat (vla-get-EffectiveName i) " _-_ ( " (vla-get-Name i) " )")
                                                    (vla-get-Name i)
                                                )
                                            )
                                            (if (setq tempList (assoc tempName NestWithInList))
                                                (if (not (member MainName tempList))
                                                    (setq NestWithInList (subst (cons tempName (cons MainName (cdr tempList))) tempList NestWithInList))
                                                )
                                                (setq NestWithInList (cons (list tempName MainName) NestWithInList))
                                            )
                                            (setq NestList
                                                (if (setq tempList (assoc MainName NestList))
                                                    (subst (cons MainName (cons tempName (cdr NestList))) tempList NestList)
                                                    (cons (list MainName tempName) NestList)
                                                )
                                            )
                                            (setq InsList
                                                (if (setq tempList (assoc tempName InsList))
                                                    (subst (cons tempName (cons i (cdr tempList))) tempLIst InsList)
                                                    (cons (list tempName i) InsList)
                                                )
                                            )
                                            (foreach att (append (vlax-invoke i 'GetAttributes) (vlax-invoke i 'GetConstantAttributes))
                                                (setq VisList (cons (cons att (vla-get-Visible att)) VisList))
                                                (vla-put-Visible att :vlax-false)
                                            )
                                        )
                                        (vla-put-Visible i :vlax-false)
                                    )
                                )
                                tempVisList
                            )
                        )
                        BlkList
                    )
                )
            )
        )
    )
    (vlax-for lo (vla-get-Layouts ActDoc)
        (vlax-for i (vla-get-Block lo)
            (setq VisList (cons (cons i (vla-get-Visible i)) VisList))
            (if (= (vla-get-ObjectName i) "AcDbBlockReference")
                (progn
                    (vla-put-Visible i :vlax-true)
                    (setq tempName
                        (if
                            (and
                                (vlax-property-available-p i 'EffectiveName)
                                (/= (vla-get-EffectiveName i) (vla-get-Name i))
                            )
                            (strcat (vla-get-EffectiveName i) " _-_ ( " (vla-get-Name i) " )")
                            (vla-get-Name i)
                        )
                    )
                    (setq InsList
                        (if (setq tempList (assoc tempName InsList))
                            (subst (cons tempName (cons i (cdr tempList))) tempLIst InsList)
                            (cons (list tempName i) InsList)
                        )
                    )
                    (foreach att (append (vlax-invoke i 'GetAttributes) (vlax-invoke i 'GetConstantAttributes))
                        (setq VisList (cons (cons att (vla-get-Visible att)) VisList))
                        (vla-put-Visible att :vlax-false)
                    )
                )
                (vla-put-Visible i :vlax-false)
            )
            (vla-Update i)
        )
    )
    (setq BlkList
        (vl-sort
            (vl-remove-if-not
                (function
                    (lambda ( x )
                        (assoc (car x) InsList)
                    )
                )
                BlkList
            )
            (function
                (lambda ( a b )
                    (< (strcase (car a)) (strcase (car b)))
                )
            )
        )
    )
    (SelectBlock (mapcar (function car) BlkList))
    (*error* nil)
    (princ)
)
« Last Edit: September 25, 2009, 02:08:03 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Block walk, help needed in testing
« Reply #1 on: September 22, 2009, 06:42:08 PM »
Tim

Works here...
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #2 on: September 22, 2009, 06:48:35 PM »
Tim

Works here...

After you ran it, did you see anything print to the command line?  If something got erased I have it print to the command line to show it.  Thanks for testing Gary.

Edit:  That is weird.  I just tried it on the drawing I was getting the errors on, and it didn't error this time.  I'll leave it as test version until it runs good for awhile.  Thanks again Gary.
« Last Edit: September 22, 2009, 06:51:48 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

kevinpo

  • Guest
Re: Block walk, help needed in testing
« Reply #3 on: September 23, 2009, 08:30:08 AM »
Very Nice.  I've always thought this would be a great idea.
I also think a Text Style walk would be good too. Actually it could be done with any entity type.

Kevin

kevinpo

  • Guest
Re: Block walk, help needed in testing
« Reply #4 on: September 23, 2009, 08:35:09 AM »
How about incorporating it with OpenDCL to create a modeless dialog so you can pan and zoom around. Also maybe a multiple select capability.

great work.

mushrat

  • Guest
Re: Block walk, help needed in testing
« Reply #5 on: September 23, 2009, 09:53:08 AM »
Works here. No erasures.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Block walk, help needed in testing
« Reply #6 on: September 23, 2009, 10:28:53 AM »
Tim

Works here...

After you ran it, did you see anything print to the command line?  If something got erased I have it print to the command line to show it.  Thanks for testing Gary.

Edit:  That is weird.  I just tried it on the drawing I was getting the errors on, and it didn't error this time.  I'll leave it as test version until it runs good for awhile.  Thanks again Gary.


No print at the command line, except for regenerating model. Works fine.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Marco Jacinto

  • Newt
  • Posts: 47
Re: Block walk, help needed in testing
« Reply #7 on: September 23, 2009, 10:32:46 AM »
Nice routine, works with no problem here.

It should be nice if it works with dynamic blocks also.

Saludos y gracias

Marco Jacinto

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #8 on: September 23, 2009, 11:11:19 AM »
Thanks for testing everyone.  Glad it seems to be working.  Maybe it was just my test drawing when I was coding that had the issue.

Kevin - I don't use object/opendcl, so I wouldn't know what to do, but if someone wants to take the reigns on that, it shouldn't be too hard, as you can see the dcl part of the code is pretty simple.

Macro - I can look into that, but I don't use them, so I don't have a good drawing to test by, but if I get some time I can see what I can do.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Block walk, help needed in testing
« Reply #9 on: September 23, 2009, 11:14:28 AM »
Tim,

Quick question regarding the DCL you have used.

I realise that $value is a string containing the settings of the active DCL tile, but what is $reason?

Cheers,

Lee

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Block walk, help needed in testing
« Reply #10 on: September 23, 2009, 11:24:37 AM »
Help file
Quote
Callback Reasons
The callback reason, returned in the $reason variable, specifies why the action occurred. Its value is set for any kind of action, but you need to inspect it only when the action is associated with an edit_box, list_box, image_button, or slider tile. The following table shows the possible values:

Callback reason codes

Code   Description
1   This is the value for most action tiles. The user has selected the tile (possibly by pressing ENTER, if the tile is the default and the platform recognizes accelerator keys).
2   Edit boxes: The user has exited the edit box, but has not made a final selection.
3   Sliders: The user has changed the value of the slider by dragging the indicator but has not made a final selection.
4   List boxes and image buttons: This callback reason always follows a code 1. It usually means "commit to the previous selection." It should never undo the previous selection; this confuses and annoys the user.
Code 1 is described fully in the table. The following text describes the codes 2, 3, and 4 in greater detail.

Code 2—Edit Boxes

The user has exited the edit box—by pressing the TAB key or by choosing a different tile—but has not made a final selection. If this is the reason for an edit box callback, your application should not update the value of the associated variable, but should check the validity of the value in the edit box.

Code 3—Sliders

The user has changed the value of the slider by dragging the indicator (or an equivalent action), but has not made a final selection. If this is the reason for a slider callback, your application should not update the value of the associated variable but should update the text that displays the slider's status. For more information, see "Sliders." For code examples, see "Handling Sliders."

Code 4—List Boxes

The user has double-clicked on the list box. You can define the meaning of a double-click in your application. If the main purpose of the dialog box is to select a list item, a double-click should make a selection and then exit the dialog box. (In this case, the is_default attribute of the list_box tile should be true.) If the list box is not the primary tile in the dialog box, then a double-click should be treated as equivalent to making a selection (code 1).
List boxes that allow the user to select multiple items
(multiple_select = true) cannot support double-clicking.

Code 4—Image Buttons

The user has double-clicked on the image button. You can define the meaning of a double-click in your application. In many cases it is appropriate for a single-click to select the button, but in others it is better for a single-click (or a keyboard action) to highlight the button, and then have the ENTER key or a double-click select it.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Block walk, help needed in testing
« Reply #11 on: September 23, 2009, 11:32:09 AM »
Thanks Alan, an interesting read  :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #12 on: September 23, 2009, 05:26:45 PM »
Dynamic blocks don't seem to work correctly.  Since the objects visibility is controlled by the dynamicness of the block, it seems to be causing a problem.  I have a bunch of blocks that I inserted.  I then copied one, and changed the visibility of it, then copied that some more.  I ran the program ( quick change to show the difference of the dynamic blocks ), and it shows the two different blocks in the drawing.  When I select the one that is the changed visibility one from the list, only the first one I copied shows up.  When looking at the other blocks, after the command, only the attributes show up, and they are each a different block now.  I can change the visibility back to what they are supposed to be, but that is just a work around, and seems to point out that something is wrong.

So I guess I'm saying I would not use this code on drawings with dynamic blocks, where they blocks views have been changed.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Block walk, help needed in testing
« Reply #13 on: September 23, 2009, 06:04:19 PM »
I know how you feel Tim - I have personally never used Dynamic blocks and am completely lost when it comes to manipulating them with LISP....  :ugly:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #14 on: September 23, 2009, 06:15:00 PM »
I think I know another way to do it, but will see if I want to go that route.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

kevinpo

  • Guest
Re: Block walk, help needed in testing
« Reply #15 on: September 24, 2009, 11:17:57 AM »
I took your advise and went ahead and came up with an OpenDCL version.

However I had to make the local functions global and had to rename the *error* function to another name so it could be executed after hitting the Close button.

The only thing I can't figure out now is when you hit escape to get out of it I can't get the visibility for everything to come back.

Maybe you guys could figure it out.

I have attached a ZIP file with everything needed to make it run. No need to install anything else.
Just unzip into folder and add path.

Kevin


kevinpo

  • Guest
Re: Block walk, help needed in testing
« Reply #16 on: September 24, 2009, 11:22:18 AM »
Sorry, new to this..
the OpenDCL version uses a modeless dialog which lets you pan and zoom around to look a the blocks.

Also, type BW to run.


Kevin

kevinpo

  • Guest
Re: Block walk, help needed in testing
« Reply #17 on: September 24, 2009, 11:40:33 AM »
Just thought of something else, Not sure if it's possible.

What about locking the layers and having the Fade set at 80% (real dark) and showing the blocks?
This would give you the visual reference for showing the blocks.

Not sure this could be done because you're changing the visibility of the entities and not the layer and for the fact that other objects can exist on the same layer as the block.
Hmmm??

Could this be done?

Kevin

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #18 on: September 24, 2009, 11:46:54 AM »
Just thought of something else, Not sure if it's possible.

What about locking the layers and having the Fade set at 80% (real dark) and showing the blocks?
This would give you the visual reference for showing the blocks.

Not sure this could be done because you're changing the visibility of the entities and not the layer and for the fact that other objects can exist on the same layer as the block.
Hmmm??

Could this be done?

Kevin

The new version that I'm working on was going to use layers, so that may be possible with that one, but with that I couldn't get it to work with xrefs, so that ability may be lost.  I'm still coding, but when it's ready enough to post I will.  Then we can see about the shading of locked layers fading to the back.

I don't use ODCL, but I would assume that there is an on exit/close, or something like that, so I would put the code there to show everything again.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

kevinpo

  • Guest
Re: Block walk, help needed in testing
« Reply #19 on: September 24, 2009, 12:10:03 PM »
Perhaps making the blocks Blink.

K

Crank

  • Water Moccasin
  • Posts: 1503
Re: Block walk, help needed in testing
« Reply #20 on: September 24, 2009, 12:46:52 PM »
Just thought of something else, Not sure if it's possible.

What about locking the layers and having the Fade set at 80% (real dark) and showing the blocks?
This would give you the visual reference for showing the blocks.

Not sure this could be done because you're changing the visibility of the entities and not the layer and for the fact that other objects can exist on the same layer as the block.
Hmmm??

Could this be done?

Kevin

Not with layers, but you could use refedit/refclose for this.
Vault Professional 2023     +     AEC Collection

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #21 on: September 24, 2009, 02:09:08 PM »
Well I think this idea is a bust.  It will not work with Dynamic block.  I tested in '06 and '09.  It will redefine each dynamic block definition again.  So lets say you have one dy block, dyblock.  It has a couple of visibility states, and when you change the state it creates an anonymous definition per state.  So you copy that three times, so there is now two blocks, dyblock & *U1.  After you run the code you will have four block definition, dyblock, *U1, *U2 & *U3.  Not cool.  At least with only changing the layer, they still look correct, but they still get renamed, so you don't really get a true representation of the block being isolated.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #22 on: September 24, 2009, 02:12:46 PM »
Just in case someone wants the code for isolating by layer instead of object.  Same dialog as before.

Code: [Select]
(defun c:BlockWalk (/ *error* GetLayInfo SelectBlock UpdateDrawing OldNum cLay ActDoc LayList tempList BlkList VisList )
   
    (defun *error* (msg)
       
        (foreach i VisList
            (if (vlax-erased-p (car i))
                (print i)
                (vla-put-Layer (car i) (cdr i))
            )
        )
        (foreach i LayList
            (vla-put-LayerOn (car i) (cadr i))
            (if (/= (vla-get-Name (car i)) cLay)
                (vla-put-Freeze (car i) (caddr i))
            )
            (vla-put-Lock (car i) (cadddr i))
        )
        (if OffLayName
            (vla-Delete (vla-Item (vla-get-Layers ActDoc) OffLayName))
        )
        (if OnLayName
            (vla-Delete (vla-Item (vla-get-Layers ActDoc) OnLayName))
        )
        (if msg (vl-bt))
        (vla-Regen ActDoc acAllViewports)
    )
    ;---------------------------------------------
    (defun GetLayInfo ( doc / ObjList )
       
        (vlax-for obj (vla-get-Layers doc)
            (setq ObjList
                (cons
                    (list
                        obj
                        (vla-get-LayerOn obj)
                        (vla-get-Freeze obj)
                        (vla-get-Lock obj)
                    )
                    ObjList
                )
            )
            (vla-put-LayerOn obj :vlax-false)
            (if (/= (vla-get-Name obj) cLay)
                (vla-put-Freeze obj :vlax-false)
            )
            (vla-put-Lock obj :vlax-false)
        )
        ObjList
    )
    ;-----------------------------------------------------------------------
    (defun SelectBlock ( Listof  / DiaLoad )
       
        (setq DiaLoad (load_dialog "MyDialogs.dcl"))
        (if (new_dialog "MyPropsList" DiaLOad)
            (progn
                (start_list "PropsListbox2" 3)
                (mapcar 'add_list Listof)
                (end_list)
                (action_tile "PropsListbox2"
                    "(if (= $reason 1)
                        (progn
                            (mode_tile \"PropsListbox2\" 1)
                            (UpdateDrawing (atoi (get_tile \"PropsListbox2\")))
                            (mode_tile \"PropsListbox2\" 0)
                            (mode_tile \"PropsListbox2\" 2)
                        )
                    )"
                )     
                (action_tile "cancel" "(done_dialog 0)")
                (start_dialog)
            )
        )
    )
    ;-------------------------------------------------------------
    (defun UpdateDrawing ( num )
        (if OldNum
            (foreach i (cdr (nth OldNum BlkList))
                (vla-put-Layer i OffLayName)
            )
        )
        (foreach i (cdr (nth num BlkList))
            (vla-put-Layer i OnLayName)
        )
        (setq OldNum num)
        (vla-Regen ActDoc acAllViewports)
    )
    ;------------------------------------------------------------------------
    (defun MyGetXData (Obj DataName / CodeType DataType)
        ; Retrive XData for an object
       
        (vla-GetXData
            Obj
            (if DataName
                DataName
                ""
            )
            'CodeType
            'DataType
        )
        (if (and CodeType DataType)
            (mapcar
                '(lambda (a b)
                    (cons a (variant-value b))
                )
                (safearray-value CodeType)
                (safearray-value DataType)
            )
        )
    )
    ;------------------------------------------------------------------------
    (setq cLay (getvar 'CLayer))
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (setq LayList (GetLayInfo ActDoc))
    (setq OffLayName "BlockWalk-templayer-Off")
    (setq OffLayer (vla-Add (vla-get-Layers ActDoc) OffLayName))
    (vla-put-LayerOn OffLayer :vlax-false)
    (setq OnLayName "BlockWalk-templayer-On")
    (setq OnLayer (vla-Add (vla-get-Layers ActDoc) OnLayName))
    (vlax-for obj (vla-get-Blocks ActDoc)
        (if
            (and
                (equal (vla-get-IsLayout obj) :vlax-false)
                (equal (vla-get-IsXref obj) :vlax-false)
                (not (wcmatch (vla-get-Name obj) "`*D*,*|*"))
            )
            (progn
                (setq tempList nil)
                (setq tempBlkList
                    (cons
                        (if (setq XdataInfo (MyGetXData obj "AcDbBlockRepBTag"))
                            (strcat (vla-get-Name (vla-HandleToObject ActDoc (cdr (assoc 1005 XdataInfo)))) "_-_( " (vla-get-Name obj) " )")
                            (vla-get-Name obj)
                        )
                        (vlax-for i obj
                            (setq VisList (cons (cons i (vla-get-Layer i)) VisList))
                            (vla-put-Layer i "0")
                            (setq tempList (cons i tempList))
                        )
                    )
                )
                (if (setq tempList (assoc (car tempBlkList) BlkList))
                    (setq BlkList (subst (append tempList (cdr tempBlkList)) tempList BlkList))
                    (setq BlkList (cons tempBlkList BlkList))
                )
            )
        )
    )
    (setq BlkList
        (vl-sort
            BlkList
            (function
                (lambda ( a b )
                    (< (car a) (car b))
                )
            )
        )
    )
    (vla-Regen ActDoc acAllViewports)
    (SelectBlock (mapcar (function car) BlkList))
    (*error* nil)
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Marco Jacinto

  • Newt
  • Posts: 47
Re: Block walk, help needed in testing
« Reply #23 on: September 24, 2009, 05:39:21 PM »
T. Willey why instead of turning off the objects inside the blockdef, try turning off the references, with this, I think the problem with the DynBLocks won't arise, won't be as fast as the one you have, but will work.

Something like this:

Code: [Select]
(Defun c:IsoBk (/ ActDoc bk BkName)
  (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (setq bk (vlax-ename->vla-object
     (car (entsel "\n Select block to Isolate: "))
   )
  )
  (setq BkName (vla-get-EffectiveName bk))
  (vlax-for obj (vla-get-ModelSpace actDoc)
    (if (and (vlax-property-available-p obj 'EffectiveName)
     (= (vla-get-EffectiveName obj) BkName)
)
      (vla-put-Visible obj :vlax-true)
      (vla-put-Visible obj :vlax-false)
    )
  )
  (princ)
)

Saludos

Marco Jacinto

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #24 on: September 24, 2009, 06:23:24 PM »
Marco,

  That way you won't see any nested blocks.  I think I have the answer, but the code is a lot slower because of it.  If someone can figure out a quick way to regen all the layouts, without using the Regen method, then the problem is solved.  I did a couple of quick codes, and this seems to be the issue.  I did one just like you did Marco, and it didn't error.  I'll post the new one soon, but I will need help on speeding up the regen portion of the code.

Here is the quick test of your idea I used.
Code: [Select]
(defun c:Test (/ tempName InsList VisList OldNum)
   
    (defun SelectBlock ( Listof  / DiaLoad )
       
        (setq DiaLoad (load_dialog "MyDialogs.dcl"))
        (if (new_dialog "MyPropsList" DiaLOad)
            (progn
                (start_list "PropsListbox2" 3)
                (mapcar 'add_list Listof)
                (end_list)
                (action_tile "PropsListbox2"
                    "(if (= $reason 1)
                        (progn
                            (mode_tile \"PropsListbox2\" 1)
                            (UpdateDrawing (atoi (get_tile \"PropsListbox2\")))
                            (mode_tile \"PropsListbox2\" 0)
                            (mode_tile \"PropsListbox2\" 2)
                        )
                    )"
                )     
                (action_tile "cancel" "(done_dialog 0)")
                (start_dialog)
            )
        )
    )
    ;-------------------------------------------------------------
    (defun UpdateDrawing ( num )
        (if OldNum
            (foreach i (cdr (nth OldNum InsList))
                (vla-put-Visible i :vlax-false)
                (vla-Update i)
            )
        )
        (foreach i (cdr (nth num InsList))
            (vla-put-Visible i :vlax-true)
            (vla-Update i)
        )
        (setq OldNum num)
        ;(vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acAllViewports)
    )
    ;------------------------------------------------------------------------
    (vlax-for lo (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
        (vlax-for obj (vla-get-Block lo)
            (setq VisList (cons (cons obj (vla-get-Visible obj)) VisList))
            (vla-put-Visible obj :vlax-false)
            (vla-Update obj)
            (if (= (vla-get-ObjectName obj) "AcDbBlockReference")
                (progn
                    (setq tempName
                        (if (= (vla-get-EffectiveName obj) (vla-get-Name obj))
                            (vla-get-Name obj)
                            (strcat (vla-get-EffectiveName obj) " _-_ ( " (vla-get-Name obj) " )")
                        )
                    )
                    (setq InsList
                        (if (setq tempList (assoc tempName InsList))
                            (subst (cons tempName (cons obj (cdr tempList))) tempList InsList)
                            (cons (list tempName obj) InsList)
                        )
                    )
                )
            )
        )
    )
    (SelectBlock (mapcar (function car) InsList))
    (foreach i VisList (vla-put-Visible (car i) (cdr i)))
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #25 on: September 25, 2009, 02:04:02 PM »
Updated code in the first post.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

kevinpo

  • Guest
Re: Block walk, help needed in testing
« Reply #26 on: September 25, 2009, 03:48:55 PM »
For some reason the dialog doesn't come up on the latest code and you were right it got a lot slower.

I'm thinking about making one for viewing entities with Xdata attached to them and show the regapp name in the dialog.

Kevin

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Block walk, help needed in testing
« Reply #27 on: September 25, 2009, 03:51:57 PM »
I didn't change any of the dialog code, so that shouldn't happen.  Is the dialog file in the search path?  Can't really think of any other reason why that would happen.  I'm thinking of doing it in C#.  I haven't done anything in awhile, and I think it could be good, and a good exercise.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.