Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

  1. #1
    Member
    Join Date
    2015-12
    Posts
    22
    Login to Give a bone
    0

    Default In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs...

    Hello everyone!

    We use the same dynamic blocks in multiple layout tabs in our title block template drawings. The code below, in Visual LISP, is for only 1 of the dynamic blocks. I pick the same dynamic block in each layout tab to change the state.

    What I would like to be able to do is after changing all the dynamic blocks in the 1st layout tab, have the same dynamic blocks in the other tabs automatically change to match the 1st layout tab. Incidentally, the visibility parameter used in the code has 3 choices, I only used 2 here. Trying to figuring out a how to do a 3rd was not going well, so I stopped. I hope all this info made sense.

    Hopefully someone will see this as a challenge.

    I have attached a template drawing that contains the title block we use.

    Here is the code I assembled after doing some searching, and with a couple of very minor edits, got it to work on one layout tab at a time:

    Code:
    (defun c:Test (/ layoutname layt layt_lst x y blk obj x1 y1 val)
      ;;;by hmsilva (https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-plot-layout-tabs-in-order/m-p/5630472)
      (vl-load-com)
      (vlax-for layt (vla-get-layouts
    		   (vla-get-ActiveDocument (vlax-get-acad-object))
    		 )
        (if	(> (vla-get-TabOrder layt) 0)
          (setq layt_lst
    	     (cons (cons (vla-get-TabOrder layt) (vla-get-Name layt))
    		   layt_lst
    	     )
          )
        )
      )
      (setq layt_lst (vl-sort layt_lst '(lambda (x1 y1) (< (car x1) (car y1)))))
      (foreach layt	layt_lst
        (setq layoutname (cdr layt))	;end by hmsilva
        (setvar "ctab" layoutname)
          	;;------------------------------------------------------------;;
      	;;	Author: Tharwat Al Choufi - Date: 09.Apr.2022		;;
      	;;	website: https://autolispprograms.wordpress.com		;;
      	;;------------------------------------------------------------;;
        ;https://forums.augi.com/showthread.php?176439-Switch-Visibility-State-in-Dynamic-Block
      	(and (setq blk
                  	(car
                    	(entsel
                      	"\nSelect Dynamic block to review visibility state's items : "
                    	)
                  	)
           	)
           	(or (and (= (cdr (assoc 0 (entget blk))) "INSERT")
                    	(= (vla-get-EffectiveName
                         	(setq obj (vlax-ename->vla-object blk))
                       	)
                       	"titleblock"
                    	)
               	)
               	(alert "Invalid object or not the block name 'titleblock'")
           	)
           	(vl-some '(lambda (x)
                       	(and (= (vla-get-propertyname x) "Visibility1")
                            	(setq val (vlax-get x 'Value))
                            	(or (vlax-put x
                                          	'Value
                                          	(if (= val "SUPPRESSION SYSTEM")
                                           	 "AS-BUILT"
                                           	 "SUPPRESSION SYSTEM"
                                          	)
                                	)
                                	t
                            	)
                       	)
                     	)
                    	(vlax-invoke obj 'getdynamicBlockproperties)
           	)	     
      	)
            );end by Tharwat Al Choufi
      	(setvar "ctab" "SH 1")
      	(princ)
    	) (vl-load-com)
    Also, I don't understand Visual LISP at all, yet.

    Which leads to a final question. What physical book would be the best to learn Visual LISP from? I've found one but wanted to see if there was any better before spending the money on it. It's the "AutoCAD Expert's Visual LISP: Release 2019 Edition" by Reinaldo N. Togores.

    Thank you for taking a look!
    Last edited by Drafter_Joe; 2024-12-06 at 03:33 PM.

  2. #2
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    571
    Login to Give a bone
    0

    Default Re: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

    Reinaldo has 4 books and they are very good buy on Kindle very cheap and can copy code to notepad.

    Re set visibilty I use Lee-mac's Dynamic block code, which includes using (LM:SetVisibilityState obj visibilty), you can look through the layouts and ssget "**U*" blocks which are dynamic blocks, you then check effective name matches yours, then use (LM:SetVisibilityState obj visibilty) the visibilty is read from the block you have picked.

    The code you provided is almost there, it just needs rearranging, pick block get effective name and current visibilty, the do a ssget of the dynamic blocks and find the matching ones then update the visibity.

    This is equal to like 15 lines of code. 4-15 There is no need to sort tab order as your changing any blocks you find.
    Code:
    (foreach layt (layoutlist)
    Get a copy of Lee-mac dynamic block functions very useful. https://lee-mac.com/dynamicblockfunctions.html

    You can have a look at this also.
    Code:
    (defun insdyne (blkname / pt obj lst ans)
    (if (not LM:setdynpropvalue )(load "Lee-mac Dynamic block get-put"))
    (if (not AH:Butts)(load "Multi Radio buttons.lsp"))
    (setq obj (vlax-ename->vla-object (car (entsel "\nPick a dynamic block "))))
    (setq visval (LM:getvisibilityparametername obj))
    (setq lst (LM:getdynpropallowedvalues obj visval))
    (setq lst (cons "Please choose" lst))
    (if (not AH:Butts)(load "Multi Radio buttons.lsp"))
    (if (not AHbut)(setq AHbut 1))
    (setq ans (ah:butts 1 "v"  lst))
    (LM:SetVisibilityState obj ans)
    (princ)
    )
    I saved Lee's functions into one file as above.
    Attached Files Attached Files

  3. #3
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,134
    Login to Give a bone
    0

    Default Re: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

    This function will change the visibility states of all dynamic blocks of same effective name to match selected dynamic block.

    You could also change them using the properties dialog.

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard copyright 2024 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Comand line function list
    ;___________________________________________________________________________________________________________|
    
    ;* C:VM
    ;* Command Line Function to change visibility states of all matching dynamic blocks
    
    ;* C:VisibilityMatch
    ;* Command Line Function to change visibility states of all matching dynamic blocks
    
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List
    ;___________________________________________________________________________________________________________|
    
    ;* (DynamicBlockVisibilityPut strEffectiveName strVisibilityName)
    ;* Function to change visibility states of all dynamic blocks with matching effectivename
    
    ;* (ErrorTrap symFunction)
    ;* Function to trap errors
    
    ;* (VisibilityObject objBlockReference)
    ;* Function to get the visibility dynamic block property of a block
    
    ;$ End Header
    
    ;___________________________________________________________________________________________________________|
    ; 
    ; Command Line Function to change visibility states of all matching dynamic blocks
    ;___________________________________________________________________________________________________________|
    
    (defun C:VM ()(C:VisibilityMatch))
    (defun C:VisibilityMatch (/ entSelection 
                                objBlockReference  
                                objVisibility 
                                ssSelection 
                                strEffectiveName 
                                strVisibilityName
                                strVisibilityValue
                             )
     (if (and (princ "\nSelect Dynamic Block: ")
              (setq ssSelection        (ssget ":S:E" (list (cons 0 "insert"))))
              (setq entSelection       (ssname ssSelection 0))
              (setq objBlockReference  (vlax-ename->vla-object entSelection))
              (setq strEffectiveName   (vlax-get objBlockReference  "EffectiveName"))
              (setq strVisibilityName  "Visibility1")
              (setq objVisibility      (VisibilityObject objBlockReference strVisibilityName))
              (setq strVisibilityValue (vlax-get objVisibility "Value"))
         )
      (DynamicBlockVisibilityPut strEffectiveName strVisibilityValue)
      (princ "\nError Selecting Dynamic Block: ")
     )
    )
    
    
    
    ;___________________________________________________________________________________________________________|
    ; 
    ; Function to change visibility states of all dynamic blocks with matching effectivename
    ;___________________________________________________________________________________________________________|
    
    (defun DynamicBlockVisibilityPut (strEffectiveName strVisibilityValue / 
                                      entSelection  
                                      intCount
                                      objBlockReference 
                                      objVisibility 
                                      ssSelections)
     (if (setq ssSelections (ssget "X" (list (cons 0 "insert"))))
      (repeat (setq intCount (sslength ssSelections))
       (setq intCount (1- intCount))
       (and (setq entSelection       (ssname ssSelections intCount))
            (entget entSelection)
            (setq objBlockReference  (vlax-ename->vla-object entSelection))
            (= (vlax-get objBlockReference "Effectivename") strEffectiveName)
            (setq objVisibility (VisibilityObject objBlockReference strVisibilityName))
            (errortrap '(vlax-put objVisibility "Value" strVisibilityValue))
       )
      )  
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ; 
    ; Function to trap errors
    ;___________________________________________________________________________________________________________|
    
    (defun ErrorTrap (symFunction / objError result)
     (if (not
          (vl-catch-all-error-p
           (setq objError (vl-catch-all-apply
                          '(lambda (X)(set X (eval symFunction)))
                           (list 'result)))))
      (if result result 'T)
     )
    )
    
    ;___________________________________________________________________________________________________________|
    ; 
    ; Function to get the visibility dynamic block property of a block
    ;___________________________________________________________________________________________________________|
    
    (defun VisibilityObject (objBlockReference strVisibilityName / lstDynamicPropertyObjects lstOfSublists)
     (if (and (= (vlax-get objBlockReference "IsDynamicBlock") -1)
              (setq lstDynamicPropertyObjects (vlax-invoke objBlockReference "GetDynamicBlockProperties"))
              (setq lstOfSublists (mapcar '(lambda (X)(list (vla-get-propertyname X) X)) lstDynamicPropertyObjects))
         )
      (cadr (assoc strVisibilityName lstOfSublists))
     )
    )
    
    (princ "!")
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2024-12-13 at 03:15 AM.
    AutomateCAD

  4. #4
    Member
    Join Date
    2015-12
    Posts
    22
    Login to Give a bone
    0

    Default Re: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

    Hi BIG AL,

    Thank you for your response, much appreciated! The kindle version makes more sense with being able to copy/paste code to notepad, I hadn't considered that. Great tip! I also appreciate the code you provided and the file. Works fine. It's a great start! Thank you!!

  5. #5
    Member
    Join Date
    2015-12
    Posts
    22
    Login to Give a bone
    0

    Default Re: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

    Hi Peter! Thank you for your response also! I've tried your code but it errors out right after clicking on a dynamic block saying "\nError Selecting Dynamic Block: ". I watched the variables and "strVisibilityValue" stays at "nil" value. Any ideas on that?

    I also noticed the title block drawing I tried to attach never attached. I'll try that again.

    *edit*

    I didn't get attached .dwg file to show up. Will find out what I'm missing and try again.

  6. #6
    Member
    Join Date
    2015-12
    Posts
    22
    Login to Give a bone
    0

    Default Re: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

    Uh huh, it was too large a file. Purged much and it worked.
    Attached Files Attached Files

  7. #7
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,134
    Login to Give a bone
    0

    Default Re: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

    Your visibility state is called "Visibility1" my code used "Visibility"

    I revised my post below to allow for other visibility names like "Visibility1" for you.

    I tried it on your drawing and it worked for me.

    P=
    Last edited by peter; 2024-12-13 at 03:17 AM.
    AutomateCAD

  8. #8
    Member
    Join Date
    2015-12
    Posts
    22
    Login to Give a bone
    0

    Default Re: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

    Of course, I didn't look at the code close enough to catch that. Fantastic! It works just as expected now! Thank you, Peter!! Curious, is the same thing possible with just AutoLISP code?? I ask because I don't know Visual LISP, yet. I understand AutoLISP better. I hope I'm using the proper LISP wording?

    Can it be automated? There are two more dynamic blocks with visibility parameters. What coding changes would be necessary so that after all the visibilities are changed this program is run and changes the rest of the blocks like it already does?

    Joe

  9. #9
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,745
    Login to Give a bone
    0

    Default Re: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

    Quote Originally Posted by Drafter_Joe View Post
    <snip>

    ... I don't know Visual LISP, yet. I understand AutoLISP better. I hope I'm using the proper LISP wording?

    <snip>
    Everyone starts somewhere; this book helped me when I first started with Visual LISP, and the Author is simply a great human being (we've had email conversations, many moons ago):

    https://www.amazon.com/Visual-LISP-D.../dp/B004I43BFK


    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 5860, Xeon W7-2495X, 128GB RAM, Dual PCIe 4.0 M.2 SSD (RAID 0), 20GB NVIDIA RTX 4000 ADA

  10. #10
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,134
    Login to Give a bone
    0

    Default Re: In Need of Better LISP Code to Change Visibility States in Muliple Layout Tabs + Help Using the GATTE Command...

    Quote Originally Posted by Drafter_Joe View Post
    Of course, I didn't look at the code close enough to catch that. Fantastic! It works just as expected now! Thank you, Peter!! Curious, is the same thing possible with just AutoLISP code?? I ask because I don't know Visual LISP, yet. I understand AutoLISP better. I hope I'm using the proper LISP wording?

    Can it be automated? There are two more dynamic blocks with visibility parameters. What coding changes would be necessary so that after all the visibilities are changed this program is run and changes the rest of the blocks like it already does?

    Joe
    Almost everything can be automated.

    Although with automation, the code needs to be more need specific.

    Just like Visibility versus Visibility1 requires a hard code change.

    So for your case I would have the routine search for dynamic blocks in the current layout.

    Filter them to see which have visibility parameters, keep them as a list.

    Read through the list and apply the visibility state to all similar blocks in the entire drawing.

    As far as Visual LISP lets start a thread and discuss... It is really not that difficult to learn to code VL.
    AutomateCAD

Page 1 of 2 12 LastLast

Similar Threads

  1. Custom Sheet Data Edit Muliple
    By Revit MEP DR in forum AutoCAD Sheet Set Manager
    Replies: 6
    Last Post: 2022-11-03, 12:36 PM
  2. Layout tabs names change when layout renamed in SSM
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2013-01-20, 05:07 AM
  3. Gatte Command
    By kyler in forum AMEP General
    Replies: 1
    Last Post: 2011-11-26, 04:57 AM
  4. Zoom and GATTE command
    By andrew.handley782323 in forum AutoCAD Customization
    Replies: 1
    Last Post: 2010-01-24, 10:01 AM
  5. Gatte command not working with Dynamic Blocks
    By Mlabell in forum AutoCAD General
    Replies: 8
    Last Post: 2007-02-21, 01:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •