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

Thread: Viewport layer states controled by LISP

  1. #1
    100 Club Kevin.Sturmer's Avatar
    Join Date
    2015-12
    Location
    Kalispell, MT
    Posts
    171
    Login to Give a bone
    0

    Default Viewport layer states controled by LISP

    I have been having the Dickens of a time trying to piece meal together this routine to no avail.

    For CAD2008, does anyone have an example of a LISP that would turn layers off/freeze them and turn on/thaw others only within a specific viewport without globally changing the layer states?

    One use is to have radio buttons which would set the floor plan layers on in one VP, another to set the ceiling layers in another VP on the same sheet.

    At present I can get it to globally toggle the layers... just can't get it down to only the VP level of control.

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,203
    Login to Give a bone
    0

    Default Re: Viewport layer states controled by LISP

    In your code, change your space to the desired viewport and adjust the vplayer there.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    100 Club Kevin.Sturmer's Avatar
    Join Date
    2015-12
    Location
    Kalispell, MT
    Posts
    171
    Login to Give a bone
    0

    Default Re: Viewport layer states controled by LISP

    Thanks for the fast reply.

    I'm sure that is really straight forward... but I am not quite following. How do I identify the specific viewport(s)?

  4. #4
    100 Club Kevin.Sturmer's Avatar
    Join Date
    2015-12
    Location
    Kalispell, MT
    Posts
    171
    Login to Give a bone
    0

    Default Re: Viewport layer states controled by LISP

    I reread Opie's reply this morning after some fresh coffee... things are much more clear now. Thanks again.

  5. #5
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,551
    Login to Give a bone
    0

    Default Re: Viewport layer states controled by LISP

    Quote Originally Posted by OIIIIIIIO View Post
    I reread Opie's reply this morning after some fresh coffee... things are much more clear now. Thanks again.
    Care to post an example of your final code for us lisp geeks to look at?

  6. #6
    I could stop if I wanted to CadDog's Avatar
    Join Date
    2005-06
    Location
    So Ca
    Posts
    439
    Login to Give a bone
    0

    Default Re: Viewport layer states controled by LISP

    Here is one I found...

    It is a good start and some one add a few more things if they like:

    Code:
    (defun C:vpfreeze (/ myvp mylay)
      (vl-load-com)
      (setq myvp (car (entsel "\nSelect viewport: ")))
      (setq myvp (vlax-ename->vla-object myvp))
      (setq mylay (getstring "\nEnter layer name: "))
      (vpfreeze myvp mylay)
    )
    
    ;; VPFREEZE
    ;; Freeze the layer in the viewport
    ;;
    ;; Arguments
    ;; vp : viewport (vla-object)
    ;; lay : layer name (string)
    
    (defun vpfreeze	(vp lay / typ val)
      (vla-getXdata vp "ACAD" 'typ 'val)
      (setq	typ (reverse
    	      (cons
    		1002
    		(cons 1002
    		      (cons 1003 (cddr (reverse (vlax-safearray->list typ))))
    		)
    	      )
    	    )
    	val (reverse
    	      (cons (vlax-make-variant "}")
    		    (cons (vlax-make-variant "}")
    			  (cons	(vlax-make-variant lay)
    				(cddr (reverse (vlax-safearray->list val)))
    			  )
    		    )
    	      )
    	    )
      )
      (vla-setXData
        vp
        (vlax-safearray-fill
          (vlax-make-safearray
    	vlax-vbInteger
    	(cons 0 (1- (length typ)))
          )
          typ
        )
        (vlax-safearray-fill
          (vlax-make-safearray
    	vlax-vbVariant
    	(cons 0 (1- (length val)))
          )
          val
        )
      )
      ;; this is needed to display the change
      (vla-display vp :vlax-false)
      (vla-display vp :vlax-true)
    )

  7. #7
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: Viewport layer states controled by LISP

    Hi,

    The code posted by CadDog can freeze a layer in PViewport by adding the layer to the viewport XDatas. But it seems to be impossible to thaw a layer in a PViewport using this way (removing from XDatas). So the only way using LISP seems to use the _VPLAYER command.
    You can see this thread.

  8. #8
    I could stop if I wanted to CadDog's Avatar
    Join Date
    2005-06
    Location
    So Ca
    Posts
    439
    Login to Give a bone
    0

    Default Re: Viewport layer states controled by LISP

    Quote Originally Posted by 'gile' View Post
    Hi,

    The code posted by CadDog can freeze a layer in PViewport by adding the layer to the viewport XDatas. But it seems to be impossible to thaw a layer in a PViewport using this way (removing from XDatas). So the only way using LISP seems to use the _VPLAYER command.
    You can see this thread.
    Thanks gile for that lead...

    I even join and will be checking back from time to time there also...

  9. #9
    Member
    Join Date
    2005-01
    Posts
    42
    Login to Give a bone
    0

    Default Re: Viewport layer states controled by LISP

    Hi-
    Here is a simple version of what I use in my office. All you need to do to update the routine is to add or delete the layer names from the list. (ex. "Layer1" = "A-ANNO-NOTE") Just keep the layer name in quotes. You can also use an asterisk as a wild card to look for xref layers or general groups of layers. The routine will freeze all layers in a view port and then thaw the layers you have listed in the selection set. You can select one or more view ports and the routine will cycle through all that you pick. Sorry I don't have any error code in there.

    Code:
    (defun c:vp-layers (/ sset num vprt laylist count)
    
    (setq laylist '(
    "0"
    "Layer1"
    "Layer2"
    "Layer3"
      )
    )
    
    (if (> (getvar "cvport") 1)(command "pspace"))
    
    (princ "\nSelect one or more view ports: ")
    
    (setq sset(ssget '((0 . "viewport"))))
    
    (setq num 0)
    (repeat (sslength sset)
    	(setq vprt(cdr(assoc 69 (entget(ssname sset num)))))
    
          (if (/= vprt 1)
    	(progn
    	  (command "mspace")
    	  (command "cvport" vprt)
    	  (command "vplayer" "f" "*" "c" "")
    
    	  (setq count 0)
    	  (foreach lay laylist
    		  (setq count (1+ count))
    		  (setq layers (append layers (list lay ",")))
    	     (if (>= (strlen (apply 'strcat layers)) 2000)
    	        (progn
    		  (command "vplayer" "t" (apply 'strcat layers) "c" "")
    		  (setq layers nil)
    	        )
    		     (if (= count (length laylist))
    		        (progn
    			  (command "vplayer" "t" (apply 'strcat layers) "c" "")
    			  (setq layers nil)
    		        )
    		     )
    	     )
    	  );end foreach
    	);end progn
          );end if
    	(setq num (1+ num))
    );end repeat
    
    (command "pspace")
    (command "zoom" "e" )
    
    (princ)
    
    );end defun

  10. #10
    Woo! Hoo! my 1st post
    Join Date
    2008-08
    Posts
    1
    Login to Give a bone
    0

    Default Re: Viewport layer states controled by LISP

    Guys, your routine is too elaborate,
    Here is the simpliest way to freeze layer in a particular viewport. Works great with any AutoCAD version up to 2008.

    This routine can be modified to do ANY other viewport layer state tasks if you know what uou need.
    Just cut and paste to your notepad and save it to your LISP routines directory with .LSP extension (this info for rookies)
    after APPLOAD, use VLF abbreviation to start routine.
    Keep it simple - this will work allways!



    Code:
    ;---------------------------------------------------------------------------------------
    ; To Freeze Layer of Picked Entity ONLY in current Viewport
    ;---------------------------------------------------------------------------------------
    (defun c:vlf ()
      (prompt
         "\nPick entity on the layer you want freeze in this Viewport: ")
      (setq name (cdr (assoc 8 (entget (car (entsel))))))
      (command "_vplayer" "f" name "" "")
      (princ)
    )
    Last edited by Opie; 2008-08-07 at 04:56 PM. Reason: [CODE] tags added, see Moderator Note

Page 1 of 2 12 LastLast

Similar Threads

  1. Viewport Layer States
    By Wish List System in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2012-07-12, 11:51 AM
  2. LISP to Capture viewport diplay states
    By Mike Y in forum AutoCAD Customization
    Replies: 1
    Last Post: 2009-02-03, 06:22 PM
  3. Layer states and LISP
    By burchd in forum AutoLISP
    Replies: 4
    Last Post: 2008-04-18, 04:22 PM
  4. Replies: 3
    Last Post: 2007-04-20, 03:01 PM
  5. Copying layer states from one viewport to another
    By wolfgrrlone in forum AutoCAD General
    Replies: 1
    Last Post: 2006-02-15, 10:57 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
  •