Author Topic: Block walk, help needed in testing  (Read 7306 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: 12923
  • 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: 12923
  • 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: 12923
  • 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.