PDA

View Full Version : Viewport layer states controled by LISP


OIIIIIIIO
2008-07-11, 07:42 PM
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.

Opie
2008-07-11, 08:15 PM
In your code, change your space to the desired viewport and adjust the vplayer there.

OIIIIIIIO
2008-07-11, 09:51 PM
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)?

OIIIIIIIO
2008-07-14, 05:26 PM
I reread Opie's reply this morning after some fresh coffee... things are much more clear now. Thanks again.

tedg
2008-07-14, 05:31 PM
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?

CadDog
2008-07-14, 11:55 PM
Here is one I found...

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


(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)
)

'gile'
2008-07-15, 12:20 PM
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 (http://www.theswamp.org/index.php?topic=22264.0).

CadDog
2008-07-15, 07:39 PM
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 (http://www.theswamp.org/index.php?topic=22264.0).

Thanks gile for that lead...

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

jsowinski
2008-07-15, 09:27 PM
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.

(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

agoretoy
2008-08-07, 05:57 PM
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!



;---------------------------------------------------------------------------------------
; 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)
)

Moderator Note:
Please use [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code)

Opie
2008-08-07, 06:59 PM
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.


Why not just use the layfrz command in newer versions?

OIIIIIIIO
2008-08-13, 02:05 AM
The intent of the routine is not to manually freeze layers by selecting various objects within a VP. It is to open a viewport and press one button and all the layers freeze or thaw based on the 'type' of plan choosen - regardless as to the number of xrefs and their degree of nesting.

If you're working on a plan with 20 nested XREFs, it is still a simple click off one button to freeze/thaw the layers as needed.

irneb
2008-08-13, 08:37 AM
You mean something that simply applies a Layer State's VPFreeze to the current Viewport? But using something like WildCards to match e.g. "*Layer1" to "Layer1", "XRef1|Layer1", "XRef2|Layer1", etc. Something like my Wish: http://forums.augi.com/showthread.php?t=81923

And then combining with this Wish: http://forums.augi.com/showthread.php?t=81155 So you can change the State and have all the VP's you've set to it updated automatically.

OIIIIIIIO
2008-08-19, 12:27 AM
I got it to open the selected VP, set the choosen freeze/thaw states based on a selected plan type, followed by closing the VP... all with 2 mouse clicks.

1 -> choose the plan type
2 -> choose the VP

That's it. There are always layers which fall outside the norm, but it catches +98% of them in our use.

These are pre-defined states. If/when they need to change I will need to change the LISP - not the user. This is more work for me (if/when it happens) but it does help encourage the use of our CAD standards at the same time.

mazmier
2008-11-17, 03:51 PM
Hi:

I am in the same boat as yourself. I want to click once to select which plan type I want a particular viewporrt to view as. I really know nothing about LSP and I tend to do a lot of my customizations with scripts.

After much thought I figure the best way for me is to run a script file that starts the VPlayer command where I would freeze and/or thaw appropriate leayers and then either bring in or switches to (I'm not sure which would be right) LSP to allow the operator to select the viewport(s). A combo script /LSP thing.

Can anybody help me with the LSP portion of this?

Thanks.

Mimi

mazmier
2008-11-17, 04:15 PM
Come to think of it...the whole thing can be done with script files, the last thing being the selection of the viewport which the operator would enter thus ending the script. You would have to have one script per plan type.

I don't think LSP is needed.

I would have one scipt file that thaws or freezes all the layer in the viewport, where the operator makes the selection thus ending the script. So you would first use this script to prepare the viewport for 'plan typing'. This one script would work for all situations. I would then run the plan type script which then thaws or freezes the layers I wish to have visible (by use of the vplayer command).

Hope this makes sense.

I'm off to set it up for myself right now.

mazmier
2008-11-17, 04:28 PM
Works like a charm....

irneb
2008-11-17, 04:46 PM
If you're using AC 2008 or later. You could set-up a Layer State per viewport type. Then if you have Dashboard open, you could select a State from the drop-down without having to go through Layer Manager or Layer States Manager: 2 click operation.

mazmier
2008-11-17, 06:09 PM
I've created a custom pull down menu . The operator selects the plan type form this menu and then clicks on the desired viewports and that's it.

I'll check out your suggestion, thanks.

Mimi