Found a problem with Saving Layerstates.. didn't update in the acadlayermanager layerstates list... so must be something coded wrong 6-6-05Produced a
SaveTabLayoutSuite for ways to Save
Layerstates per tablayout name and with each switch recall
Layerstate per that tab along with a Reactor LayoutSwitch
that recalls Ltscale/Psltscale per Model / Paperspace you can
redefine. Take some of the mystery out of Layerstates, and
if that isn't enough. How would you like to Update Layer Properties
in Selected TabLayouts/Layerstate Saves. I need testers.
Anytakers... if not at least if you do this type of autocad workflow
I hope you enjoy.
I didn't do all the coding, but I did do the Organizing of this, I do hope
that after looking at the workflow and you still don't see my vision.
I have a video (.wmv) I can send via email : doggarn@nc.rr.com
Mike in Alaska
Also found a goldmine at this site of Vlisp Commands you might not
have seen: by M.Puckett
http://www.crimsoneditor.com/english/board/CrazyWWWBoard.cgi?db=files&mode=read&num=1655&page=1&ftype=6&fval=&backdepth=1
;********************************* Command line Delete Tablayout Layerstate ************************
; delete Layerstates
; delete Layerstates
(defun c:dlays ( / acad doc layman state )
(vl-load-com)
(setq *acad* (vlax-get-acad-object);get the application
doc (vla-get-activedocument *acad*);get the current drawing
LayMan (vla-getinterfaceobject *acad* "AutoCAD.AcadLayerStateManager.16");get the LStateManager
)
;;; set database to the activedocument
(setq layrs (listSavedLayerstates))
(if layrs (setq layrs (mapcar 'strcase layrs)))
(setq state (getvar "ctab"))
(if (member state layrs)
(progn
(vla-setdatabase layman (vla-get-database doc))
(vla-delete layman state)
(listSavedLayerstates)
)
)
(princ)
)
;;; ***************************** Command line Restore Tablayout Layerstates **************
(defun c:ssr (/ layr layrs blayr)
(setvar "cmdecho" 0)(GRAPHSCR)
(setq layr "")(setq layrs "")(setq blayr "")(setq blayr (strcase "---TempLayerState---"))
(eacu_layoutSysVar:restoreVariables)
(setq layr (strcase (getvar "ctab")))
(setq layrs (listSavedLayerstates))
(if layrs (setq layrs (mapcar 'strcase layrs)))
(if (member blayr layrs)
(c:blayrs)
)
(if (member layr layrs)
(c:rstorls)
)
(princ (strcat "\nLayState Restored = " (getvar "ctab") " \n"))
(princ)
)
;************************ Command Line Save Tablayout Layerstates ***************************************
;; Create Current TabLayout Layer State per TabLayout Name delete and save at once
(defun c:sss ()
(c:sls)
(princ (strcat "\nLayState Current = " (getvar "ctab") " \n"))
(GRAPHSCR)
(princ)
)
;******************************* Command Line List Tablayout Layerstates **********************************
;;; List layer states
(defun c:ssl (/ nme lsList)
(princ"\n*** Layer State List ***")
(vlax-for x
(vla-item
(vla-GetExtensionDictionary
(vla-get-layers
(vlax-get-property
(vlax-get-acad-object)
'activedocument)
)
)
"ACAD_LAYERSTATES"
)
(princ(strcat "\n" (setq nme(vlax-get x 'name))))
(setq lsList (cons nme lsList))
)
(textscr)
(princ)
);end of defun
;***************************************** List Layerstates for internal func ***********************
;;; 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
)
;********************************************** Delete All Layer States ******************************************
;;; Delete all Layer states
(defun c:dls (/ nme lsList)
(setq ddd "")
(setq ddd (getstring "\nDo you want ERASE ALL LAYERSTATES (Y)<Y> ? "))
(if (= ddd "")
(progn
(setvar "cmdecho" 0)(graphscr)
(princ"\n*** Layer State List ***")
(vlax-for x
(vla-item
(vla-GetExtensionDictionary
(vla-get-layers
(vlax-get-property
(vlax-get-acad-object)
'activedocument)
)
)
"ACAD_LAYERSTATES"
)
(princ(strcat "\n Delete all LayerState :" (setq nme(vlax-get x 'name))))
(command "-layer" "state" "delete" (setq nme(vlax-get x 'name)) "" "")
(setq lsList (cons nme lsList))
)
)
)
(princ)
);end of defun
;********************************* Internal restore Layerstate *************************************
;
; restore Layerstates
(defun c:rstorls ( / acad doc layman state )
(vl-load-com)
(setq *acad* (vlax-get-acad-object);get the application
doc (vla-get-activedocument *acad*);get the current drawing
LayMan (vla-getinterfaceobject *acad* "AutoCAD.AcadLayerStateManager.16");get the LStateManager
)
;;; set database to the activedocument
(setq layr (strcase (getvar "ctab")))
(setq layrs (listSavedLayerstates))
(if layrs (setq layrs (mapcar 'strcase layrs)))
(setq state (getvar "ctab"))
(if (member state layrs)
(progn
(vla-setdatabase layman (vla-get-database doc))
(vla-restore layman state)
)
)
(princ)
)
; **************************** Internal Tablayout Layerstates ***************************************
(defun c:sls ( / acad doc layman state layrs)
(vl-load-com)
(setq *acad* (vlax-get-acad-object);get the application
doc (vla-get-activedocument *acad*);get the current drawing
LayMan (vla-getinterfaceobject *acad* "AutoCAD.AcadLayerStateManager.16");get the LStateManager
)
;;; set database to the activedocument
(setq layrs (listSavedLayerstates))
(if layrs (setq layrs (mapcar 'strcase layrs)))
(setq state (getvar "ctab"))
(if (member state layrs)
(progn
(vla-setdatabase layman (vla-get-database doc))
(vla-delete layman state)
(vla-save layman state acLsAll)
)
)
(if (not(member state layrs))
(progn
(vla-setdatabase layman (vla-get-database doc))
(vla-save layman state acLsAll)
)
)
(princ)
)
; ===============================================================
; Reactor Switch TabLayout and Recall Tablayout Layerstate
; and Reset Ltscale Psltscale for Model vs Papersapce Change as desired
(defun c:vr ()
(vl-load-com)
(setq thisdrawing
(vla-get-activedocument
(vlax-get-acad-object)))
(vla-Regen thisdrawing acAllViewports)
(princ)
);defun
; ===============================================================
;
; - Initialize ActiveX support
(vl-load-com)
(setq *acad* (vlax-get-acad-object);get the application
doc (vla-get-activedocument *acad*);get the current drawing
LayMan (vla-getinterfaceobject *acad* "AutoCAD.AcadLayerStateManager.16");get the LStateManager
)
; Return the list of names
;
; - Reactors ------------------------------------------------------------------
;
; - If not set, initialize DocManager-Reactor
(or Me:ReaDma
(setq Me:ReaDma (VLR-DocManager-Reactor
nil
'(
(:VLR-documentToBeDestroyed . MeDocToBeDestroyedCallbacks)
)
)
)
)
; - If not set, initialize Command-Reactor
(or Me:ReaCom
(setq Me:ReaCom (VLR-Command-Reactor
nil
'(
(:VLR-commandEnded . MeCommandEndedCallbacks)
)
)
)
)
;
; - Notifications -------------------------------------------------------------
;
; - CommandEnded notifications
(defun MeCommandEndedCallbacks (Rea Arg)
(MeDoCmdEndedStuff Arg)
(princ)
)
; - DocToBeDestroyed notifications
(defun MeDocToBeDestroyedCallbacks (Rea Arg)
(MeDoCloseStuff)
(princ)
)
;
; - Subs ----------------------------------------------------------------------
;
; - Command ended function
(defun MeDoCmdEndedStuff (Arg / CurCmd)
(setq CurCmd (strcase (car Arg)))
(cond
((wcmatch CurCmd "LAYOUT_CONTROL,TILEMODE")
(setq state (getvar "ctab"))
(vla-setdatabase layman (vla-get-database doc))
(vla-restore layman state)
(princ (strcat "\nLayState Current = " state " \n"))
(if (= (getvar "TILEMODE") 1)
(progn
(setvar "psltscale" 0);modelspace
(setq recall-ltscale (getvar "dimscale"))
(setq reset-ltscale (* 0.5 recall-ltscale)); Set ltscale in model space to half dimscale..
(setvar "ltscale" reset-ltscale)
)
(progn
(setvar "psltscale" 1);paperspace
(setvar "ltscale" 0.6); Set ltscale in paperspace
)
)
;(c:vr)
(princ)
)
;;; other command ended dependent functions
)
(princ)
)
; - Reactor cleanup function
(defun MeDoCloseStuff ( / VarLst)
(setq VarLst (MeGetReaVars))
(mapcar 'VLR-remove (mapcar 'eval VarLst))
(mapcar '(lambda (l) (set l nil)) VarLst)
(princ)
)
; - Collect global reactor variables
(defun MeGetReaVars ( / RetVal)
(foreach memb (atoms-family 1)
(if (wcmatch (strcase memb) "ME:REA*")
(setq RetVal (cons memb RetVal))
)
)
(mapcar 'read RetVal)
)
(princ)
Update LayerProperties... and more selective Other made the bulk
I just adapted it to my needs in Civil/Survey
UpdatLayerstate.lsp
(defun c:ULS (/ ActDoc layCol LayList DiaLOad LayDict LayStDict LayStList LayStObj RtnLayList
RtnOptions States2Update tmpLayList tmpList)
; Update layer states via dialog box.
; Works in A2K4.
; By Tim Willey 02/2005
; Thanks to Joe Burke and James Allen
; Updated to run with SSD.lsp copyright by Michael J. Perry Anchorage Alaska 6-1-05
; email : doggarn@nc.rr.com or doggarn@gci.net
; also to run with LayoutReactor.arx copyright CadNovations, Inc Ont. Canada
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq LayCol (vla-get-Layers ActDoc))
(vlax-for Lay LayCol
(setq LayList (cons Lay LayList))
)
(setq LayList (vl-sort LayList '(lambda (a b) (< (vla-get-Name a) (vla-get-Name b)))))
(setq LayDict (vla-GetExtensionDictionary LayCol))
(setq LayStDict (vl-catch-all-apply 'vla-Item (list LayDict "ACAD_LAYERSTATES")))
(if (vl-catch-all-error-p LayStDict)
(progn
(prompt "\n -------------No layer states to update!--------------")
(exit)
)
)
(vlax-for LaySt LayStDict
(setq LayStList (cons (vla-get-Name LaySt) LayStList))
)
(setq LayStObj (vla-GetInterfaceObject (vlax-get-Acad-Object) "AutoCAD.AcadLayerStateManager.16"))
(vla-SetDatabase LayStObj (vla-get-Database ActDoc))
(setq DiaLoad (load_dialog "UpdateLayerStates.dcl"))
(if (not (new_dialog "UpdLayStates" DiaLoad))
(exit)
)
(start_list "LayListBox" 3)
(mapcar '(lambda (x) (add_list (vla-get-Name x))) LayList)
(end_list)
(set_tile "SaveOn" "1")
(set_tile "OnRad" "1")
(action_tile "SaveOn" (strcat "(if (= $value \"0\") (mode_tile \"RadOn\" 1) (mode_tile \"RadOn\" 0))"))
(set_tile "SaveThaw" "1")
(set_tile "ThawRad" "1")
(action_tile "SaveThaw" (strcat "(if (= $value \"0\") (mode_tile \"RadThaw\" 1) (mode_tile \"RadThaw\" 0))"))
(mode_tile "RadLock" 1)
(set_tile "LockRad" "1")
(action_tile "SaveLock" (strcat "(if (= $value \"1\") (mode_tile \"RadLock\" 0) (mode_tile \"RadLock\" 1))"))
(mode_tile "RadPlot" 1)
(set_tile "PlotRad" "1")
(action_tile "SavePlot" (strcat "(if (= $value \"1\") (mode_tile \"RadPlot\" 0) (mode_tile \"RadPlot\" 1))"))
(mode_tile "RadVpFreeze" 1)
(set_tile "VpThawRad" "1")
(action_tile "SaveVpFreeze" (strcat "(if (= $value \"1\") (mode_tile \"RadVpFreeze\" 0) (mode_tile \"RadVpFreeze\" 1))"))
(action_tile "accept"
"(progn
(setq RtnLayList (get_tile \"LayListBox\"))
(setq RtnOptions (Accept-sub))
(done_dialog 1)
)"
)
(action_tile "cancel" "(done_dialog 0)")
(if (and (= (start_dialog) 1) (/= RtnLayList ""))
(progn
(setq RtnLayList (read (strcat "(" RtnLayList ")")))
(foreach Num RtnLayList
(setq tmpLayList (cons (nth Num LayList) tmpLayList))
)
(if (not (new_dialog "LayStateSelect" DiaLoad))
(exit)
)
(start_list "LayStates" 3)
(mapcar 'add_list LayStList)
(end_list)
(action_tile "accept"
"(progn
(setq States2Update (get_tile \"LayStates\"))
(done_dialog 1)
)"
)
(action_tile "cancel" "(done_dialog 0)")
(if (and (= (start_dialog) 1) (/= States2Update ""))
(progn
(setq States2Update (read (strcat "(" States2Update ")")))
(foreach Num States2Update
(setq tmpList (cons (nth Num LayStList) tmpList))
)
(setq States2Update tmpList)
(vla-StartUndoMark ActDoc)
(vlax-invoke LayStObj 'Save "---TempLayerState---" acLsAll)
(foreach State States2Update
(setvar "ctab" State)(setvar "users5" (getvar "ctab"))(c:ssd)
(foreach Lay tmpLayList
(vla-put-ViewportDefault Lay (car (car RtnOptions)))
(vla-put-PlotTable Lay (cadr (car RtnOptions)))
(vla-put-Lock Lay (caddr (car RtnOptions)))
(vla-put-Freeze Lay (cadddr (car RtnOptions)))
(vla-put-LayerOn Lay (last (car RtnOptions)))
)
(vlax-invoke LayStObj 'Save State (cdr RtnOptions))
(c:sss)
)
(vla-Restore LayStObj "---TempLayerState---")
(vla-Delete LayStObj "---TempLayerState---");(c:ssr)
(vla-EndUndoMark ActDoc)
)
)
)
)
(princ)
)
;-----------------------------------------------------------------
(defun Accept-sub (/ RtnList)
(setq RtnNum 0)
(if (= (get_tile "SaveOn") "1")
(progn
(cond
((= (get_tile "RadOn") "OnRad")
(setq RtnList (cons :vlax-true RtnList))
)
((= (get_tile "RadOn") "OffRad")
(setq RtnList (cons :vlax-false RtnList))
)
)
(setq RtnNum (+ RtnNum 1))
)
(setq RtnList (cons :vlax-false RtnList))
)
(if (= (get_tile "SaveThaw") "1")
(progn
(cond
((= (get_tile "RadThaw") "ThawRad")
(setq RtnList (cons :vlax-false RtnList))
)
((= (get_tile "RadThaw") "FreezeRad")
(setq RtnList (cons :vlax-true RtnList))
)
)
(setq RtnNum (+ RtnNum 2))
)
(setq RtnList (cons :vlax-false RtnList))
)
(if (= (get_tile "SaveLock") "1")
(progn
(cond
((= (get_tile "RadLock") "LockRad")
(setq RtnList (cons :vlax-true RtnList))
)
((= (get_tile "RadLock") "UnLockRad")
(setq RtnList (cons :vlax-false RtnList))
)
)
(setq RtnNum (+ RtnNum 4))
)
(setq RtnList (cons :vlax-false RtnList))
)
(if (= (get_tile "SavePlot") "1")
(progn
(cond
((= (get_tile "RadPlot") "PlotRad")
(setq RtnList (cons :vlax-true RtnList))
)
((= (get_tile "RadPlot") "NoPlotRad")
(setq RtnList (cons :vlax-false RtnList))
)
)
(setq RtnNum (+ RtnNum 8))
)
(setq RtnList (cons :vlax-false RtnList))
)
(if (= (get_tile "SaveVpFreeze") "1")
(progn
(cond
((= (get_tile "RadVpFreeze") "VpFreezeRad")
(setq RtnList (cons :vlax-true RtnList))
)
((= (get_tile "RadVpFreeze") "VpThawRad")
(setq RtnList (cons :vlax-false RtnList))
)
)
(setq RtnNum (+ RtnNum 16))
)
(setq RtnList (cons :vlax-false RtnList))
)
(if (= (get_tile "SaveColor") "1")
(setq RtnNum (+ RtnNum 32))
)
(if (= (get_tile "SaveLT") "1")
(setq RtnNum (+ RtnNum 64))
)
(if (= (get_tile "SaveLW") "1")
(setq RtnNum (+ RtnNum 128))
)
(if (= (get_tile "SavePlotStyle") "1")
(setq RtnNum (+ RtnNum 256))
)
(cons RtnList RtnNum)
)
The DCL file for UpdatLayerState
UpdLayStates : dialog { label = "Select layer to update States with." ; width = 70 ; height = 50 ;
: row
{
: list_box
{
label = Layers ;
key = "LayListBox" ;
width = 65 ;
multiple_select = true ;
}
: column
{
: column
{ label = "On / Off status." ;
: toggle
{
label = "Save?" ;
key = "SaveOn" ;
}
: radio_row
{ key = "RadOn" ;
: radio_button
{
label = "On" ;
key = "OnRad" ;
}
: radio_button
{
label = "Off" ;
key = "OffRad" ;
}
}
}
: spacer {}
: column
{ label = "Thaw / Freeze status." ;
: toggle
{
label = "Save?" ;
key = "SaveThaw" ;
}
: radio_row
{ key = "RadThaw" ;
: radio_button
{
label = "Thaw" ;
key = "ThawRad" ;
}
: radio_button
{
label = "Freeze" ;
key = "FreezeRad" ;
}
}
}
: spacer {}
: column
{ label = "Lock / UnLock status." ;
: toggle
{
label = "Save?" ;
key = "SaveLock" ;
}
: radio_row
{ key = "RadLock" ;
: radio_button
{
label = "Lock" ;
key = "LockRad" ;
}
: radio_button
{
label = "UnLock" ;
key = "UnLockRad" ;
}
}
}
: spacer {}
: column
{ label = "Plot / No Plot status." ;
: toggle
{
label = "Save?" ;
key = "SavePlot" ;
}
: radio_row
{ key = "RadPlot" ;
: radio_button
{
label = "Plot" ;
key = "PlotRad" ;
}
: radio_button
{
label = "No Plot" ;
key = "NoPlotRad" ;
}
}
}
: spacer {}
: column
{ label = "New VP Freeze status." ;
: toggle
{
label = "Save?" ;
key = "SaveVpFreeze" ;
}
: radio_row
{ key = "RadVpFreeze" ;
: radio_button
{
label = "Yes" ;
key = "VpFreezeRad" ;
}
: radio_button
{
label = "No" ;
key = "VpThawRad" ;
}
}
}
: spacer {}
: column
{ label = "Save properties." ;
: toggle
{
label = "Color" ;
key = "SaveColor" ;
}
: toggle
{
label = "Linetype" ;
key = "SaveLT" ;
}
: toggle
{
label = "Lineweight" ;
key = "SaveLW" ;
}
: toggle
{
label = "Plot Style" ;
key = "SavePlotStyle" ;
}
}
}
}
: row
{
: spacer
{
width = 1 ;
}
: button
{
label = "OK";
is_default = true;
allow_accept = true;
key = "accept";
width = 8;
fixed_width = true;
}
: button
{
label = "Cancel";
is_cancel = true;
key = "cancel";
width = 8;
fixed_width = true;
}
: spacer
{
width = 1 ;
}
}
}
///--- End first dialog ---///
LayStateSelect : dialog { label = "Layer States." ; width = 50 ; height = 50 ;
: list_box
{
label = "Select layer states to update." ;
key = "LayStates" ;
multiple_select = true ;
height = 25 ;
}
: row
{
: spacer
{
width = 1 ;
}
: button
{
label = "OK";
is_default = true;
allow_accept = true;
key = "accept";
width = 8;
fixed_width = true;
}
: button
{
label = "Cancel";
is_cancel = true;
key = "cancel";
width = 8;
fixed_width = true;
}
: spacer
{
width = 1 ;
}
}
}