TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: sourdough on June 09, 2005, 04:10:34 PM
-
this is a post in discussion groups
Re: Can't save layerstate
I found if I don't use the acLsAll mask and use instead the mask below it works.
(setq what (+ acLsAll, acLsColor, acLsFrozen, acLsLineType, acLsLineWeight, acLsLocked, acLsNewViewport, acLsNone, acLsOn, acLsPlot, acLsPlotStyle))
I hacked this acLsAll worth 65535 and the sum of all other masks is 511
with that I just keep adding till I got all states to be on and that was this:
Try this formula (1+ (* acLsAll 2)) or simply 131071. Below is a visual explaination of all this: the name of the mask, the decimal value and the binary value.
acLsNone 0 00000000000000000
acLsOn 1 00000000000000001
acLsFrozen 2 00000000000000010
acLsLocked 4 00000000000000100
acLsPlot 8 00000000000001000
acLsNewViewport 16 00000000000010000
acLsColor 32 00000000000100000
acLsLineType 64 00000000001000000
acLsLineWeight 128 00000000010000000
acLsPlotStyle 256 00000000100000000
acLsAll 65535 01111111111111111
acLsAll + 1 10000000000000000
(+ 1 (* acLsAll 2)) 11111111111111111
For example, having a value of 41 means 1 + 8 + 32 so it represents the sum of acLsOn + acLsPlot + acLsColor.
(setq what (1+ (* acLsAll 2)))
This should work, but doesn't.... won't show the layerstate in the
acad layermanager layerstate dialog box.. but this one does.
(setq what (+ 66047 acLsnone acLson acLsnewviewport acLslineweight acLslocked acLslinetype acLson acLsColor acLsFrozen acLsPlot acLsPlotStyle))
or
(setq what (+ 66559))
used like this: where SaveLayerState is the function call
name is the Layerstate name
what is the Mask
(SaveLayerStateName name what)
This is the error:
(SaveLayerStateName name acLsall)
also
The will save a layerstate but won't report it in the acad layermanager layerstates dialog box.... I hope this helps
I also apologize for the code left in earlier posts... I didn't find this error till
just about 4 days ago, and Bam... now I have to suck it up. I hope
that these posts will make up for the learning curve.
Thanks to the Swamp and the people here who share.
I'm working in 2005-2006 and ldt civil3d
Mike in Alaska
this was a pain to find this acad error
I'm a fan of using tablayout name to store the layerstate
and use a command line instead of the acad Layermanager
;;; Organized and tested some programming by Michael Perry
;;; doggarn@nc.rr.com Anchorage Alaska
;;; Help by
;;; Save the LayerState
;;; By Serge Camire, Cad-Novation, http://www.cadnovation.com, 2005/06/07
;;; Usage : (SaveLayerStateName "the_name" what)
(defun c:sss ( / name what )
(setq what (+ 66559))
(setq name (getvar "ctab"))
(c:ssd)
(SaveLayerStateName name what)
(setvar "cmdecho" 0)
(princ (strcat "\nLayState Saved = " name " \n"))
(GRAPHSCR)
(princ)
)
(defun SaveLayerStateName (
;; Choose Mask from (you can sum them up or use acLsAll) :
;; acLsAll, acLsColor, acLsFrozen, acLsLineType, acLsLineWeight, acLsLocked,
;; acLsNewViewport, acLsNone, acLsOn, acLsPlot, acLsPlotStyle
LayerStateName Mask
/ acadapp acadver docs oLSM oLSMDatabase thisDatabase thisDrawing
)
(setq acadver (itoa (atoi (getvar "acadver"))))
(setq acadapp (vlax-get-acad-object))
(setq docs (vla-get-Documents acadapp))
(setq thisDrawing (vla-get-ActiveDocument acadapp))
(setq thisDatabase (vla-get-Database thisDrawing))
(setq oLSM (vla-GetInterfaceObject acadapp (strcat "AutoCAD.AcadLayerStateManager." acadver)))
(setq oLSMDatabase (vla-SetDatabase oLSM ThisDatabase))
(vla-SetDataBase oLSM thisDatabase)
(vl-catch-all-apply 'vla-save (list oLSM LayerStateName Mask))
;(vla-Regen thisDrawing acAllViewports)
(princ)
)
;;; DeleteLayerStateName
(defun DeleteLayerStateName (
LayerStateName
/ acadapp acadver docs oLSM oLSMDatabase thisDatabase thisDrawing
)
(setq acadver (itoa (atoi (getvar "acadver"))))
(setq acadapp (vlax-get-acad-object))
(setq docs (vla-get-Documents acadapp))
(setq thisDrawing (vla-get-ActiveDocument acadapp))
(setq thisDatabase (vla-get-Database thisDrawing))
(setq oLSM (vla-GetInterfaceObject acadapp (strcat "AutoCAD.AcadLayerStateManager." acadver)))
(setq oLSMDatabase (vla-SetDatabase oLSM ThisDatabase))
(vla-SetDataBase oLSM thisDatabase)
(vl-catch-all-apply 'vla-delete (list oLSM LayerStateName))
;(vla-Regen thisDrawing acAllViewports)
(princ)
)
;;; Restore TabLayout Name Layer State*********************************** restore *********************************
(defun c:ssr (/ layr layrs name )
(setvar "cmdecho" 0)(GRAPHSCR)
(setq layr (strcase (getvar "ctab")))
(setq layrs (listSavedLayerstates))
(setq name (getvar "ctab"))
(if layrs (setq layrs (mapcar 'strcase layrs)))
(if (not (member layr layrs))
(progn
(princ (strcat "\n No LayState = " name " \n"))
)
)
(RestoreLayerStateName name)
(princ)
)
;;; listSavedLayerstates
;;; Returns a list of all layer states
;;; by Serge Camiré, www.cadnovation.com
;;;
;;; Since layer 0 is always involved in a drawing, thus in any subsequent saved layer state,
;;; we scan this layer.
;;;
;;; Receive:
;;; no parameters
;;; Returns
;;; LIST or nil
(defun listSavedLayerstates (
/ return
)
(cond
((not (setq return (entget (cdr (assoc 330 (entget (tblobjname "layer" "0"))))))) (setq return nil))
((not (setq return (cdr (assoc 360 return)))) (setq return nil))
((not (setq return (member (cons 3 "ACAD_LAYERSTATES") (entget return)))) (setq return nil))
(t
(setq return (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 3 (car x))) (entget (cdadr return)))))
)
)
return
)