;------------------------------------------------------------------------------- ; Program Name: Blk_Lib.lsp [Block Library R17] ; Created By: Terry Miller (Email: terrycadd@yahoo.com) ; (URL: http://web2.airmail.net/terrycad) ; Date Created: 1-1-00 ; Function: Loads Block Library functions to insert blocks and adds blocks ; to Block Libraries. ; Note: Blk_Lib requires functions inside of GetIcon.lsp. ;------------------------------------------------------------------------------- ; Quick Block Library Installation Steps: ; 1. Copy Blk_Lib.lsp and Blk_Lib.dcl to a folder in your AutoCAD's search path. ; 2. Start AutoCAD and at the Command line type (load "Blk_Lib.lsp") to load ; Block Library. ; 3. Then on the command line type (setq *Blk_Lib* t) so as to bypass the Block ; Library Instructions. ; 4. You can run Block Library by typing SBL for "Select Block Library" or ; type BLMENU for the "Block Library Menu". ; Note: You can automate steps (2) and (3) by adding them to your AcadDoc.lsp ; file to load Block Library. ;------------------------------------------------------------------------------- ; Revision History ; Rev By Date Description ;------------------------------------------------------------------------------- ; 1 TM 1-1-00 Initial version. ; 2 TM 2-1-00 Added c:Sel_Lib, Select Block Library. ; 3 TM 3-1-00 Revised c:InBlocks and c:All_Blk_Lib functions. ; 4 TM 4-1-00 Created and added GetIcon.lsp Get functions. ; 5 TM 5-1-00 Revised code for AutoCAD 2000 compatibility. ; 6 TM 12-1-00 Revised GetIcon.lsp to allow up to 4 lines and to allow ; choosing different icons. ; 7 TM 1-1-01 Included Blk_Lib as the main command function and added ; more icons to GetIcon.lsp. ; 8 TM 10-1-03 Added c:LIB, shortcut for c:Library, for a user version ; of Select Block Library. Included insertion dot as the ; default for slides. Allow user to control block rotation. ; 9 TM 10-20-03 Added Slide_Script function to be used with Select Block ; Library to add folders of drawings to Block Libraries. ; Added c:Mat, shortcut for c:Match, the Match Slides Game. ; 10 TM 5-20-04 Added GetDwgsList function to check if drawing environment ; is a Single Document Interface before running scripts. ; 11 TM 12-20-04 Revised code for AutoCAD 2005 compatibility. Redesigned ; the dialogs with slide images, and increased the width ; for block names to allow more room for longer block names. ; 12 TM 3-20-05 Detached GetIcon.lsp functions into a separate file. ; 13 TM 9-20-05 Revised some of the dialog control functions and reworded ; some of the dialog messages. ; 14 TM 7-20-06 Revised code for AutoCAD 2007 compatibility. ; 15 TM 11-30-07 Added runapp function for DOS applications. ; 16 TM 2-1-08 Revised INBL, shortcut for c:InBlocks function, to insert ; blocks from a folder of drawings into a blank drawing to ; manage and add blocks to Block Libraries. ; 17 TM 2-20-08 Added ADL, shortcut for c:Add_Dwgs function, to add a ; folder of drawings to a library without inserting them ; into a drawing. ;------------------------------------------------------------------------------- ; Note: Block Library saves a backup of your drawing as C:\Custom\Blk_Lib.dwg ; before it creates slides and wblocks. If the program is interrupted or ; canceled open C:\Custom\Blk_Lib.dwg as a backup. ;------------------------------------------------------------------------------- ; Overview of Main Functions ;------------------------------------------------------------------------------- ; c:ALLBL and c:All_Blk_Lib [All Blocks to Library] - Select Library to add all ; blocks in drawing. ; ; All_Blk_Lib [All Blocks to Library] - Adds all blocks in drawing to Library. ; Example: (All_Blk_Lib "Notes" "C:\\Custom\\Notes\\Notes.def" nil) ; Returns: Creates or appends a Notes Library DefFile definition file in the ; C:\Custom\Notes folder for displaying slides and inserts blocks from the ; same folder by default. ; ; c:BLIB - Call the function Blk_Lib with default arguments. ; ; c:Blk_Lib [Block Library] - Main command function that calls c:Sel_Lib ; [Select Block Library] ; ; Blk_Lib [Block Library] - Inserts blocks from Library or calls the function ; Blk_Mgr. ; Example: (Blk_Lib "Electronic Symbols" "C:\\Custom\\Elec_Sym\\Elec_Sym.def" ; "C:\\Custom\\Elec_Blk\\Elec_Blk.def") ; Returns: Creates or reads an Electronics Symbols Library DefFile definition ; file in the C:\Custom\Elec_Sym folder for displaying slides and inserts ; blocks from the C:\Custom\Elec_Blk folder. ; ; c:BLM and c:Blk_Mgr - Call the function Blk_Mgr with default arguments. ; ; Blk_Mgr [Block Library Manager] - Adds blocks to the Library or calls the ; function Edit_Lib if no blocks found in drawing to add. ; Example: (Blk_Mgr "Notes" "C:\\Custom\\Notes\\Notes.def" ; "C:\\Custom\\Notes\\Notes.def") ; Returns: Adds a block to the C:\Custom\Notes folder or calls the function ; Edit_Lib if no blocks found in drawing to add. ; ; c:BLMENU and c:Blk_Menu [Block Library Menu] - Select a Block Library Command ; from the Block Library Menu. ; ; c:DB and c:Dwg_Blks [Drawing Blocks] - View and select drawing blocks. ; ; c:EDBL and c:Edit_Lib - Call the function Edit_Lib with default arguments. ; ; Edit_Lib [Edit Block Library] - Rearranges or deletes lines of block insertion ; data in the DefFile. ; Example: (Edit_Lib "Notes" "C:\\Custom\\Notes\\Notes.def") ; Returns: Rearrange or delete lines of block insertion data for the Notes ; Library in the C:\Custom\Notes\Notes.def DefFile. ; ; c:INBL and c:InBlocks [Insert Blocks] - Insert blocks from selected folder. ; ; c:LIB and c:Library. [Select Block Library for Users] ; ; c:SBL and c:Sel_Lib [Select Block Library] - Selects a Block Library to use ; or adds or edits library definitions. ; ; c:UL and c:User_Lib - Call the function User_Lib with default arguments. ; ; User_Lib [User Library] - Inserts blocks from Library with only user options. ; Example: (User_Lib "Weld Symbols" "C:\\Custom\\Weld_Sym\\Weld_Sym.def" nil) ; Returns: Reads a Weld Symbols Library DefFile definition file in the ; C:\Custom\Weld_Sym folder for displaying slides and inserts blocks from ; the same folder by default. ; ; c:ADL and c:Add_Dwgs [Add Drawings to Library] - Adds a folder of drawings ; to a library without inserting them into a drawing. ;------------------------------------------------------------------------------- ; Shortcuts to Commands and Functions ;------------------------------------------------------------------------------- ; c:ALLBL - Shortcut for c:All_Blk_Lib. [All Blocks to Library] ;------------------------------------------------------------------------------- (defun c:ALLBL () (c:All_Blk_Lib)) ;------------------------------------------------------------------------------- ; c:BLIB - Shortcut that calls function Blk_Lib with default arguments. ;------------------------------------------------------------------------------- (defun c:BLIB () (Blk_Lib nil nil nil)) ;------------------------------------------------------------------------------- ; c:BLK_LIB - Shortcut for c:Sel_Lib. [Select Block Library] ;------------------------------------------------------------------------------- (defun c:BLK_LIB () (c:Sel_Lib)) ;------------------------------------------------------------------------------- ; c:BLM - Shortcut for c:Blk_Mgr. [Block Library Manager] ;------------------------------------------------------------------------------- (defun c:BLM () (Blk_Mgr nil nil nil)) ;------------------------------------------------------------------------------- ; c:BLMENU - Shortcut for c:Blk_Menu. [Block Library Menu] ;------------------------------------------------------------------------------- (defun c:BLMENU () (c:Blk_Menu) (princ)) ;------------------------------------------------------------------------------- ; c:DB - Shortcut for c:Dwg_Blks. [Drawing Blocks] ;------------------------------------------------------------------------------- (defun c:DB () (c:Dwg_Blks)) ;------------------------------------------------------------------------------- ; c:EDBL - Shortcut for c:Edit_Lib. [Edit Block Library] ;------------------------------------------------------------------------------- (defun c:EDBL () (Edit_Lib nil nil)) ;------------------------------------------------------------------------------- ; c:INBL - Shortcut for c:InBlocks. [Insert Blocks] ;------------------------------------------------------------------------------- (defun c:INBL () (c:InBlocks)) ;------------------------------------------------------------------------------- ; c:LIB - Shortcut for c:Library. [Select Block Library for Users] ;------------------------------------------------------------------------------- (defun c:LIB () (c:Library)) ;------------------------------------------------------------------------------- ; c:SBL - Shortcut for c:Sel_Lib. [Select Block Library] ;------------------------------------------------------------------------------- (defun c:SBL () (c:Sel_Lib)) ;------------------------------------------------------------------------------- ; c:UL - Shortcut for c:User_Lib. [User Library] ;------------------------------------------------------------------------------- (defun c:UL () (User_Lib nil nil nil)) ;------------------------------------------------------------------------------- ; c:ADL - Shortcut for c:Add_Dwgs. [Add Drawings to Library] ;------------------------------------------------------------------------------- (defun c:ADL () (c:Add_Dwgs)) ;------------------------------------------------------------------------------- ; Start of Block Library Commands and Functions ;------------------------------------------------------------------------------- ; c:All_Blk_Lib [All Blocks to Library] - Select Library to add all blocks in ; drawing. ;------------------------------------------------------------------------------- (defun c:All_Blk_Lib (/ BlockLib@ BlkList@ Option# Cnt# DatFile$ Dcl_Id% EOF Field# FileName% intLib# Item$ LibrarySub: LibTitle$ Mid$ nthLibrary$ Old_error PathDat$ Pick# Q$ Rep# SlideLib@ StartNo# TblList@ Text$ TitleLib@ );variables (setq Old_error *error* *error* *BL_error*) (setvar "ATTREQ" 0) (setvar "CMDECHO" 0) (setvar "REGENMODE" 1) ;----------------------------------------------------------------------------- ; c:All_Blk_Lib subfunctions = LibrarySub: ;----------------------------------------------------------------------------- ; LibrarySub: ;----------------------------------------------------------------------------- (defun LibrarySub: () (setq nthLibrary$ (get_tile "library") intLib# (atoi nthLibrary$) *Blk_Lib* (nth intLib# TitleLib@) );setq (set_tile "library" nthLibrary$) );defun LibrarySub: ;----------------------------------------------------------------------------- ; c:All_Blk_Lib - Start Main Function ;----------------------------------------------------------------------------- (setq LibTitle$ "All Blocks to") (setq PathDat$ "C:\\Custom\\Blk_Lib\\Sel_Lib.dat") (setq DatFile$ (cadr (GetPathFile PathDat$))) (princ (strcat "\n" LibTitle$ " Library "))(princ) (Custom_Dirs LibTitle$ PathDat$ nil) (if (= (GetYesNo "All Blocks to Library" "Do you need to add a new\nLibrary folder for Blocks?" "Folder") "Yes") (progn (GetOK "All Blocks to Library" (strcat "Add a new Library Definition and folder,\n" "and then re-run All Blocks to Library." );strcat "filefolder" );GetOK (c:Sel_Lib) (princ "\nAll Blocks to Library ") (exit) );progn );if ;----------------------------------------------------------------------------- ; Get BlkList@ ;----------------------------------------------------------------------------- (setq TblList@ (tblnext "block" t)) (while TblList@ (if (/= (substr (cdr (assoc 2 TblList@)) 1 1) "*") (setq BlkList@ (cons (cdr (assoc 2 TblList@)) BlkList@)) );if (setq TblList@ (tblnext "block")) );while (if BlkList@ (progn (if (equal BlkList@ *BlkList@) (setq BlkList@ *NewBlkList@) (progn (setq *BlkList@ BlkList@);Store global *BlkList@ variable (setq BlkList@ (acad_strlsort BlkList@)) (setq BlkList@ (BlkSlides BlkList@)) (setq *NewBlkList@ BlkList@);Store global *NewBlkList@ variable );progn );if (if (not BlkList@) (progn (princ "\nNo valid blocks found in drawing.")(princ) (GetOK "Block Library" (strcat "No valid blocks found in drawing for " LibTitle$ " Library.\n" "Create or insert blocks or open a drawing with blocks.") "AlertX" );GetOK (exit) );progn );if );progn (progn (princ "\nNo blocks found in drawing.")(princ) (GetOK "Block Library" (strcat "No valid blocks found in drawing for " LibTitle$ " Library.\n" "Create or insert blocks or open a drawing with blocks.") "AlertX" );GetOK (exit) );progn );if ;----------------------------------------------------------------------------- ; Get Lists from PathDat$ file. ;----------------------------------------------------------------------------- (if (findfile PathDat$) (setq FileName% (open PathDat$ "r")) (progn (GetOK (strcat LibTitle$ " Library") (strcat DatFile$ " file not found\n" "for " LibTitle$ " Library.") "AlertX" );GetOK (exit) );progn );if (setq Q$ "\"") (setq Rep# 0) (setq EOF nil) (setq Item$ "") (while (null EOF) (setq Text$ (read-line FileName%)) (if Text$ (if (= (substr Text$ 1 1) Q$) (progn (setq StartNo# 2) (setq Cnt# 1) (setq Field# 1) (while (and (<= Cnt# (strlen Text$)) (< Field# 3)) (setq Mid$ (substr Text$ Cnt# 3)) (if (= Mid$ "\",\"") (progn (setq Item$ (substr Text$ StartNo# (- Cnt# StartNo#)) );setq (cond ((= Field# 1) (if TitleLib@ (setq TitleLib@ (append TitleLib@ (list Item$))) (setq TitleLib@ (list Item$)) );if );Field# 1 ((= Field# 2) (if SlideLib@ (setq SlideLib@ (append SlideLib@ (list Item$))) (setq SlideLib@ (list Item$)) );if );Field# 2 (t (exit)) );cond (setq Field# (1+ Field#)) (setq StartNo# (+ Cnt# 3)) );progn );if (setq Cnt# (1+ Cnt#)) );while (setq Item$ (substr Text$ StartNo# (- (strlen Text$) StartNo#)) );setq (if BlockLib@ (setq BlockLib@ (append BlockLib@ (list Item$))) (setq BlockLib@ (list Item$)) );if );progn );if (setq EOF t) );if );while (close FileName%) ;----------------------------------------------------------------------------- ; Load DCL dialog: Library in Blk_Lib.dcl ;----------------------------------------------------------------------------- (if (and (= (type *Blk_Lib*) 'STR) (member *Blk_Lib* TitleLib@)) (setq intLib# (- (length TitleLib@) (length (member *Blk_Lib* TitleLib@))) nthLibrary$ (itoa intLib#) );setq (setq *Blk_Lib* "Block" nthLibrary$ "0" intLib# 0 );setq );if (princ "\nSelect an option: ")(princ) (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (while (/= Option# 1) (new_dialog "Library" Dcl_Id%) (set_tile "title" " All Blocks to Library") (start_list "library") (mapcar 'add_list TitleLib@) (end_list) (set_tile "library" nthLibrary$) (action_tile "library" "(LibrarySub:)") (action_tile "select" "(done_dialog 3)");select (action_tile "cancel" "(done_dialog 2)");cancel (setq Option# (start_dialog)) (if (= Option# 3);select (setq Pick# 3 Option# 1 );setq );if (if (= Option# 2);cancel (setq Option# 1) );if );while (unload_dialog Dcl_Id%) (if (= Pick# 3);select (All_Blk_Lib (nth intLib# TitleLib@) (nth intLib# SlideLib@) (nth intLib# BlockLib@) );All_Blk_Lib );if (setq *error* Old_error) (princ) );defun c:All_Blk_Lib ;------------------------------------------------------------------------------- ; All_Blk_Lib {All Blocks to Library] - Add all blocks in drawing to Library. ; Arguments: 3 ; LibTitle$ = Library title ; PathDef$ = Pathname and DefFile name for slides ; PathBlk$ = Pathname and DefFile name for blocks ; Returns: Adds all blocks in drawing to Library. ;------------------------------------------------------------------------------- (defun All_Blk_Lib (LibTitle$ PathDef$ PathBlk$ / Attribs$ BlkList@ BlkPath$ BlockData$ Color0# DefFile$ DefPath$ FileName% PathBlock$ Pt1@ Pt2@ Q$ RealBlk& Rep# Replace$ RevSS& SSDims& TblList@ UcsIcon# );variables ;----------------------------------------------------------------------------- ; Evaluate Arguments and get DefPath$ and DefFile$ variables. ;----------------------------------------------------------------------------- (if (null LibTitle$) (setq LibTitle$ "Block") );if (if (null PathDef$) (setq PathDef$ "C:\\Custom\\Blk_Lib\\Blk_Lib.def") );if (setq DefPath$ (car (GetPathFile PathDef$))) (setq DefFile$ (cadr (GetPathFile PathDef$))) (if (null PathBlk$) (setq PathBlk$ PathDef$) );if (setq BlkPath$ (car (GetPathFile PathBlk$))) (princ (strcat "\nAll Blocks to " LibTitle$ " Library "))(princ) (Custom_Dirs LibTitle$ PathDef$ PathBlk$) ;----------------------------------------------------------------------------- ; Get BlkList@ ;----------------------------------------------------------------------------- (setq TblList@ (tblnext "block" t)) (while TblList@ (if (/= (substr (cdr (assoc 2 TblList@)) 1 1) "*") (setq BlkList@ (cons (cdr (assoc 2 TblList@)) BlkList@)) );if (setq TblList@ (tblnext "block")) );while (if BlkList@ (progn (if (equal BlkList@ *BlkList@) (setq BlkList@ *NewBlkList@) (progn (setq *BlkList@ BlkList@);Store global *BlkList@ variable (setq BlkList@ (acad_strlsort BlkList@)) (setq BlkList@ (BlkSlides BlkList@)) (setq *NewBlkList@ BlkList@);Store global *NewBlkList@ variable );progn );if (if (not BlkList@) (progn (princ "\nNo valid blocks found in drawing.")(princ) (GetOK "All Blocks to Library" (strcat "No valid blocks found in drawing for " LibTitle$ " Library.\n" "Create or insert blocks or open a drawing with blocks.") "AlertX" );GetOK (exit) );progn );if );progn (progn (princ "\nNo blocks found in drawing.")(princ) (GetOK "All Blocks to Library" (strcat "No blocks found in drawing for " LibTitle$ " Library.\n" "Create or insert blocks or open a drawing with blocks.") "AlertX" );GetOK (exit) );progn );if (SaveDwgName);Save Drawing*.dwg as a different name (princ "\nAdding slides and blocks ")(princ) (setq Pt1@ (polar (getvar "VIEWCTR") (* pi 0.5)(/ (getvar "VIEWSIZE") 2.0))) (setq Pt2@ (polar Pt1@ (* pi 1.5) (getvar "VIEWSIZE"))) (command "UNDO" "BEGIN") (if (ssget "X") (command ".ERASE" (ssget "X") "") );if (command ".LAYER" "T" "*" "U" "*" "ON" "*" "") (command ".LAYER" "T" "0" "U" "0" "ON" "0" "S" "0" "") (setq Color0# (abs (cdr (assoc 62 (tblnext "layer" t))))) (command ".LAYER" "M" "0" "C" "7" "" "") (setq UcsIcon# (getvar "UCSICON")) (setvar "UCSICON" 0) (setq FileName% (open PathDef$ "a")) (foreach Block$ BlkList@ (command ".INSERT" Block$ "0,0" "" "" "") (command ".ZOOM" "E") (setq RealBlk& (ssget "L")) (if RealBlk& (progn (command ".EXPLODE" "L") (setq SSDims& (ssget "X" (list (cons 0 "DIMENSION")))) (if SSDims& (progn (command ".ERASE" (ssget "X") "") (command ".INSERT" Block$ "0,0" "" "" "") );progn );if (command ".DONUT" "0" "0.00000001" "0,0" "") (setq Ent1^ (entlast)) (command ".ZOOM" "E") (command ".DONUT" "0" (/ (getvar "VIEWSIZE") 25.0) "0,0" "") (command ".CHPROP" "L" "" "C" "6" "");Color choice optional (setq Ent2^ (entlast)) (command ".ZOOM" "0.95x") (command ".REGEN") (setq PathBlock$ (strcat BlkPath$ Block$ ".dwg")) (setq Replace$ "Yes") (if (findfile PathBlock$) (setq Replace$ (GetYesNoCancel "All Blocks to Library" (strcat PathBlock$ "\nexists. Do you want to replace it?") "Block") );setq );if (if (= Replace$ "Yes") (progn (command ".MSLIDE" (strcat DefPath$ Block$)) (entdel Ent1^)(entdel Ent2^) (if SSDims& (progn (if (findfile PathBlock$) (command ".WBLOCK" PathBlock$ "Y" Block$) (command ".WBLOCK" PathBlock$ Block$) );if (command ".ERASE" (ssget "X") "") );progn (progn (setq RevSS& (ReverseSS (ssget "X"))) (if (findfile PathBlock$) (command ".WBLOCK" PathBlock$ "Y" "" "0,0" RevSS& "") (command ".WBLOCK" PathBlock$ "" "0,0" RevSS& "") );if );progn );if (setq Q$ "\"") (if (= (cdr (assoc 70 (tblsearch "BLOCK" Block$))) 2) (setq Attribs$ "1") (setq Attribs$ "0") );if (setq BlockData$ (strcat Q$ Block$ Q$ "," ;Block Q$ "Current layer" Q$ "," ;Layer Q$ "User selects" Q$ "," ;Point Q$ "User selects" Q$ "," ;Scale Q$ "0" Q$ "," ;Explode Q$ Attribs$ Q$) ;Attribs );setq (write-line BlockData$ FileName%) );progn (command ".ERASE" (ssget "X") "") );if );progn (command ".ERASE" (ssget "X") "") );if (Whirl) (if (= Replace$ "Cancel") (progn (command ".ZOOM" "W" Pt1@ Pt2@) (command ".LAYER" "M" "0" "C" Color0# "" "") (close FileName%) (command "UNDO" "END") (command "U") (princ " ") (exit) );progn );if );foreach (command ".ZOOM" "W" Pt1@ Pt2@) (command ".LAYER" "M" "0" "C" Color0# "" "") (close FileName%) (command "UNDO" "END") (command "U") (setvar "UCSICON" UcsIcon#) (princ " ") (princ) );defun All_Blk_Lib ;------------------------------------------------------------------------------- ; *BL_error* [Block Library error handler] ;------------------------------------------------------------------------------- (defun *BL_error* (msg) (if (not (member msg (list "console break" "Function cancelled" "quit / exit abort"))) (alert msg) );if (setq *error* Old_error Old_error nil) (princ) );defun *BL_error* ;------------------------------------------------------------------------------- ; Blk_Lib [Block Library] - Inserts blocks from Library. ; Arguments: 3 ; LibTitle$ = Library title ; PathDef$ = Pathname and DefFile name for slides ; PathBlk$ = Pathname and DefFile name for blocks ; Returns: Inserts a block or calls function Blk_Mgr. ;------------------------------------------------------------------------------- (defun Blk_Lib (LibTitle$ PathDef$ PathBlk$ / Attribs$ AttribsList@ BlkList@ BlkPath$ Block$ BlockLen# Option# Cnt# DefFile$ DefPath$ Dcl_Id% EOF Explode$ ExplodeList@ Field# FileName% ImageName$ Item$ Layer$ LayerList@ Manager$ Mid$ No_Blks# No_Pages# Old_error Osmode PathBlock$ Pg_No# Pick Point@ PointList@ Q$ Ref# Rep# ScaleList@ Scale~ SlideRef$ StartNo# Text$ UserPoint@ UserScale~ );variables (setq Old_error *error* *error* *BL_error*) (setvar "ATTREQ" 0) (setvar "CMDECHO" 0) (setvar "REGENMODE" 1) ;----------------------------------------------------------------------------- ; Evaluate Arguments and get DefPath$ and DefFile$ variables. ;----------------------------------------------------------------------------- (if (null LibTitle$) (setq LibTitle$ "Block") );if (if (null PathDef$) (setq PathDef$ "C:\\Custom\\Blk_Lib\\Blk_Lib.def") );if (setq DefPath$ (car (GetPathFile PathDef$))) (setq DefFile$ (cadr (GetPathFile PathDef$))) (if (null PathBlk$) (setq PathBlk$ PathDef$) );if (setq BlkPath$ (car (GetPathFile PathBlk$))) (princ (strcat "\n" LibTitle$ " Library "))(princ) (Custom_Dirs LibTitle$ PathDef$ PathBlk$) ;----------------------------------------------------------------------------- ; Get Lists from PathDef$ file. ;----------------------------------------------------------------------------- (if (findfile PathDef$) (setq FileName% (open PathDef$ "r")) (progn (GetOK (strcat LibTitle$ " Library") (strcat DefFile$ " file not found\n" "for " LibTitle$ " Library.") "AlertX" );GetOK (exit) );progn );if (setq Q$ "\"") (setq Rep# 0) (setq EOF nil) (setq Item$ "") (while (null EOF) (setq Rep# (1+ Rep#)) (if (= Rep# 20) (progn (setq Rep# 0) (Whirl) );progn );if (setq Text$ (read-line FileName%)) (if Text$ (if (= (substr Text$ 1 1) Q$) (progn (setq StartNo# 2) (setq Cnt# 1) (setq Field# 1) (while (and (<= Cnt# (strlen Text$)) (< Field# 6)) (setq Mid$ (substr Text$ Cnt# 3)) (if (= Mid$ "\",\"") (progn (setq Item$ (substr Text$ StartNo# (- Cnt# StartNo#)) );setq (cond ((= Field# 1) (if BlkList@ (setq BlkList@ (append BlkList@ (list Item$))) (setq BlkList@ (list Item$)) );if );Field# 1 ((= Field# 2) (if LayerList@ (setq LayerList@ (append LayerList@ (list Item$))) (setq LayerList@ (list Item$)) );if );Field# 2 ((= Field# 3) (if PointList@ (setq PointList@ (append PointList@ (list Item$))) (setq PointList@ (list Item$)) );if );Field# 3 ((= Field# 4) (if ScaleList@ (setq ScaleList@ (append ScaleList@ (list Item$))) (setq ScaleList@ (list Item$)) );if );Field# 4 ((= Field# 5) (if ExplodeList@ (setq ExplodeList@ (append ExplodeList@ (list Item$))) (setq ExplodeList@ (list Item$)) );if );Field# 5 (t (exit)) );cond (setq Field# (1+ Field#)) (setq StartNo# (+ Cnt# 3)) );progn );if (setq Cnt# (1+ Cnt#)) );while (setq Item$ (substr Text$ StartNo# (- (strlen Text$) StartNo#)) );setq (if AttribsList@ (setq AttribsList@ (append AttribsList@ (list Item$))) (setq AttribsList@ (list Item$)) );if );progn );if (setq EOF t) );if );while (princ " ") (close FileName%) (setq No_Pages# (fix (/ (1- (length BlkList@)) 20.0)) Pg_No# 0 BlockLen# (length BlkList@) Option# 99 );setq ;----------------------------------------------------------------------------- ; Load DCL dialog: Blk_Lib in Blk_Lib.dcl ;----------------------------------------------------------------------------- (princ "\nSelect a block or option: ")(princ) (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (while (/= Option# 1) (new_dialog "Blk_Lib" Dcl_Id%) (set_tile "title" (strcat " " LibTitle$ " Library " (itoa (+ Pg_No# 1)) " of " (itoa (+ No_Pages# 1))) );set_tile (if (= Pg_No# No_Pages#) (mode_tile "next" 1) (mode_tile "next" 0) );if (if (= Pg_No# 0) (mode_tile "previous" 1) (mode_tile "previous" 0) );if (if (> BlockLen# 19) (setq No_Blks# 20) (setq No_Blks# BlockLen#) );if (action_tile "manager" "(done_dialog 5)") (action_tile "next" "(done_dialog 4)") (action_tile "previous" "(done_dialog 3)") (action_tile "cancel" "(done_dialog 2)") (setq Rep# 1) (repeat (fix No_Blks#) (action_tile (strcat "sld" (itoa Rep#)) "(setq SlideRef$ $key Pick t)") (setq ImageName$ (nth (+ (* Pg_No# 20) (- Rep# 1)) BlkList@)) (start_image (strcat "sld" (itoa Rep#))) (slide_image 0 0 (dimx_tile (strcat "sld" (itoa Rep#))) (dimy_tile (strcat "sld" (itoa Rep#))) (strcat DefPath$ ImageName$ ".sld") );slide_image (end_image) (set_tile (strcat "sld" (itoa Rep#) "text") ImageName$ );set_tile (setq Rep# (1+ Rep#)) );repeat (setq Option# (start_dialog)) (if (= Option# 5);manager (setq Option# 1 SlideRef$ nil Manager$ "Yes" );setq );if (if (= Option# 4);next (setq Pg_No# (1+ Pg_No#) BlockLen# (- BlockLen# 20) SlideRef$ nil );setq );if (if (= Option# 3);previous (setq Pg_No# (- Pg_No# 1) BlockLen# (+ BlockLen# 20) SlideRef$ nil );setq );if (if (= Option# 2);cancel (setq Option# 1 SlideRef$ nil );setq );if );while (unload_dialog Dcl_Id%) (if (and SlideRef$ Pick) (progn (setq Ref# (- (+ (* Pg_No# 20) (atoi (substr SlideRef$ 4))) 1)) (setq Block$ (nth Ref# BlkList@) Layer$ (nth Ref# LayerList@) Point@ (nth Ref# PointList@) Scale~ (nth Ref# ScaleList@) Explode$ (nth Ref# ExplodeList@) Attribs$ (nth Ref# AttribsList@) );setq (setq PathBlock$ (strcat BlkPath$ Block$ ".dwg")) (if (or (= Block$ " ") (not (findfile PathBlock$))) (progn (if (/= Block$ " ") (GetOK (strcat LibTitle$ " Library") (strcat PathBlock$ "\nblock not found.") "AlertX" );GetOK );if (exit) );progn );if (if (= Point@ "Lower left limits") (setq Point@ (getvar "LIMMIN")) );if (if (= Point@ "Lower right limits") (setq Point@ (list (car (getvar "LIMMAX")) (cadr (getvar "LIMMIN")))) );if (if (= Point@ "Upper left limits") (setq Point@ (list (car (getvar "LIMMIN")) (cadr (getvar "LIMMAX")))) );if (if (= Point@ "Upper right limits") (setq Point@ (getvar "LIMMAX")) );if (if (and (= Point@ "User selects") (/= Scale~ "User selects")) (progn (while (null UserPoint@) (setq UserPoint@ (getpoint (strcat "\nInsertion point for " Block$ " block: ")) );setq );while (setq Point@ UserPoint@) );progn );if (if (/= Point@ "User selects") (progn (if (= (type Point@) 'STR) (setq Point@ (RealList Point@)) );if (if (/= (type Point@) 'LIST) (progn (GetOK (strcat LibTitle$ " Library") (strcat "Invalid insertion point for " Block$ "\nblock in " DefFile$ " file.") "AlertX" );GetOK (exit) );progn );if );progn );if (if (= Scale~ "Dim scale") (if (= (getvar "DIMSCALE") 0) (progn (GetOK (strcat LibTitle$ " Library") "DIMSCALE value must be greater than 0." "AlertX" );GetOK (exit) );progn (setq Scale~ (getvar "DIMSCALE")) );if );if (if (and (= Scale~ "User selects") (/= Point@ "User selects")) (progn (while (or (null UserScale~) (< UserScale~ 0)) (setq UserScale~ (getreal (strcat "\nScale factor for " Block$ " block <1>: ") );getreal );setq (if (null UserScale~) (setq UserScale~ 1.0) );if (if (<= UserScale~ 0) (princ "\nScale factor must be greater than 0.")(princ) );if );while (setq Scale~ (rtosr UserScale~)) );progn );if (if (/= Scale~ "User selects") (progn (if (= (type Scale~) 'STR) (setq Scale~ (atof Scale~)) );if (if (<= Scale~ 0) (progn (GetOK (strcat LibTitle$ " Library") (strcat "Invalid scale factor for " Block$ "\nblock in " DefFile$ " file.") "AlertX" );GetOK (exit) );progn );if );progn );if (setq Osmode (getvar "OSMODE")) (setvar "OSMODE" 0);None (if (= Explode$ "1");Yes (progn (setq PathBlock$ (strcat "*" BlkPath$ Block$)) (if (and (= Point@ "User selects") (= Scale~ "User selects")) (command ".INSERT" PathBlock$) (command ".INSERT" PathBlock$ Point@ Scale~) );if );progn (progn (setq PathBlock$ (strcat BlkPath$ Block$)) (if (/= Layer$ "Current layer") (if (tblsearch "LAYER" Layer$) (command ".LAYER" "T" Layer$ "U" Layer$ "ON" Layer$ "S" Layer$ "") (command ".LAYER" "M" Layer$ "") );if );if (if (and (= Point@ "User selects") (= Scale~ "User selects")) (command ".INSERT" PathBlock$) (command ".INSERT" PathBlock$ Point@ Scale~ "") );if );progn );if (setvar "OSMODE" Osmode) );progn );if (if (= Manager$ "Yes") (Blk_Mgr LibTitle$ PathDef$ PathBlk$) );if (setq *error* Old_error) (princ) );defun Blk_Lib ;------------------------------------------------------------------------------- ; Blk_Lib_Msg [Block Library Message] - Installation Instructions ;------------------------------------------------------------------------------- (defun Blk_Lib_Msg (/ Dcl_Id%) ;----------------------------------------------------------------------------- ; Load DCL dialog: Blk_Lib_Msg in Blk_Lib.dcl ;----------------------------------------------------------------------------- (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (new_dialog "Blk_Lib_Msg" Dcl_Id%) (set_tile "msg1" "Note: Add the following line to the AutoLISP file that will be loading \"Blk_Lib.lsp\".") (set_tile "msg2" "(load \"Blk_Lib.lsp\") (setq *Blk_Lib* t)") (set_tile "msg3" "Block Library saves a backup of your drawing as C:\\Custom\\Blk_Lib.dwg before") (set_tile "msg4" "it creates slides and wblocks. If the program is interrupted or canceled, you may") (set_tile "msg5" "open C:\\Custom\\Blk_Lib.dwg as a backup.") (action_tile "accept" "(done_dialog)") (start_dialog) (unload_dialog Dcl_Id%) (exit) );defun Blk_Lib_Msg ;------------------------------------------------------------------------------- ; c:Blk_Mgr - Calls function Blk_Mgr with default arguments. ;------------------------------------------------------------------------------- (defun c:Blk_Mgr () (Blk_Mgr nil nil nil) (princ)) ;------------------------------------------------------------------------------- ; Blk_Mgr [Block Library Manager] - Manages blocks for Library. ; Arguments: 3 ; LibTitle$ = Library title ; PathDef$ = Pathname and DefFile name for slides ; PathBlk$ = Pathname and DefFile name for blocks ; Returns: Adds a block to Library or calls function Edit_Lib if no blocks found ; in drawing to add. ;------------------------------------------------------------------------------- (defun Blk_Mgr (LibTitle$ PathDef$ PathBlk$ / Attribs$ BlkList@ BlkPath$ Blk_Lib_def: Block$ BlockMgr: DefFile$ DefPath$ Dot$ EditLib$ Explode$ Layer$ MgrPoint~ MgrScale~ MslideList@ Mslide_Wblock: Old_error Point$ Replace$ Scale$ TblList@ );variables (setq Old_error *error* *error* *BL_error*) (setvar "ATTREQ" 0) (setvar "CMDECHO" 0) (setvar "REGENMODE" 1) ;----------------------------------------------------------------------------- ; Evaluate Arguments and get DefPath$ and DefFile$ variables. ;----------------------------------------------------------------------------- (if (null LibTitle$) (setq LibTitle$ "Block") );if (if (null PathDef$) (setq PathDef$ "C:\\Custom\\Blk_Lib\\Blk_Lib.def") );if (setq DefPath$ (car (GetPathFile PathDef$))) (setq DefFile$ (cadr (GetPathFile PathDef$))) (if (null PathBlk$) (setq PathBlk$ PathDef$) );if (setq BlkPath$ (car (GetPathFile PathBlk$))) (princ (strcat "\n" LibTitle$ " Library Manager "))(princ) (Custom_Dirs LibTitle$ PathDef$ PathBlk$) ;----------------------------------------------------------------------------- ; Blk_Mgr subfunctions = BlockMgr:, Mslide_Wblock:, Blk_Lib_def: ;----------------------------------------------------------------------------- ; BlockMgr: - Controls dialog Blk_Mgr to Manage blocks for Library. ;----------------------------------------------------------------------------- (defun BlockMgr: (/ AddLibSub: Attribs$ BlkList@ Block$ BlockSub: Option# Cnt# Dcl_Id% Dot$ DotSub: Explode$ ExplodeSub: LayList@ Layer$ LayerSub: MslideData@ MslideList@ NewList@ PntList@ Point$ PointSub: ScaList@ Scale$ ScaleSub: TblList@ ViewBlkSub: View_Blks: nthBlkList$ nthLayList$ nthPntList$ nthScaList$ );variables ;--------------------------------------------------------------------------- ; BlockMgr: subfunctions = BlockSub:, PointSub:, LayerSub:, ScaleSub:, ; ExplodeSub:, ViewBlkSub:, DotSub:, AddLibSub:, View_Blks: ;--------------------------------------------------------------------------- ; BlockSub: ;--------------------------------------------------------------------------- (defun BlockSub: () (setq nthBlkList$ (get_tile "block")) (set_tile "block" nthBlkList$) (setq Block$ (nth (atoi nthBlkList$) BlkList@)) (start_image "blocksld") (fill_image 0 0 (dimx_tile "blocksld") (dimy_tile "blocksld") 0) (end_image) (start_image "blocksld") (slide_image 0 0 (dimx_tile "blocksld") (dimy_tile "blocksld") (strcat "C:\\Custom\\Blk_Sld\\" Block$ ".sld") );slide_image (end_image) (if (= (cdr (assoc 70 (tblsearch "BLOCK" Block$))) 2) (setq Attribs$ "1") (setq Attribs$ "0") );if );defun BlockSub: ;--------------------------------------------------------------------------- ; PointSub: ;--------------------------------------------------------------------------- (defun PointSub: () (setq nthPntList$ (get_tile "point")) (set_tile "point" nthPntList$) (setq Point$ (nth (atoi nthPntList$) PntList@)) );defun PointSub: ;--------------------------------------------------------------------------- ; LayerSub: ;--------------------------------------------------------------------------- (defun LayerSub: () (setq nthLayList$ (get_tile "layer")) (set_tile "layer" nthLayList$) (setq Layer$ (nth (atoi nthLayList$) LayList@)) );defun LayerSub: ;--------------------------------------------------------------------------- ; ScaleSub: ;--------------------------------------------------------------------------- (defun ScaleSub: () (setq nthScaList$ (get_tile "scale")) (set_tile "scale" nthScaList$) (setq Scale$ (nth (atoi nthScaList$) ScaList@)) );defun ScaleSub: ;--------------------------------------------------------------------------- ; ExplodeSub: ;--------------------------------------------------------------------------- (defun ExplodeSub: () (if (= Explode$ "0") (setq Explode$ "1");yes (setq Explode$ "0");no );if );defun ExplodeSub: ;--------------------------------------------------------------------------- ; ViewBlkSub: ;--------------------------------------------------------------------------- (defun ViewBlkSub: (/ Ref#) (setq Ref# (View_Blks: BlkList@)) (princ (strcat "\n" LibTitle$ " Library Manager "))(princ) (princ "\nSelect an option: ")(princ) (if Ref# (setq Block$ (nth Ref# BlkList@) nthBlkList$ (itoa Ref#) );setq );if (if (= (cdr (assoc 70 (tblsearch "BLOCK" Block$))) 2) (setq Attribs$ "1") (setq Attribs$ "0") );if );defun ViewBlkSub: ;--------------------------------------------------------------------------- ; DotSub: ;--------------------------------------------------------------------------- (defun DotSub: () (if (= Dot$ "0") (setq Dot$ "1");yes (setq Dot$ "0");no );if );defun DotSub: ;--------------------------------------------------------------------------- ; AddLibSub: ;--------------------------------------------------------------------------- (defun AddLibSub: () (setq MslideData@ '(Block$ Layer$ Point$ Scale$ Explode$ Attribs$ Dot$) );setq (foreach Item MslideData@ (if MslideList@ (setq MslideList@ (append MslideList@ (list (eval Item)))) (setq MslideList@ (list (eval Item))) );if );foreach );defun AddLibSub: ;--------------------------------------------------------------------------- ; View_Blks: - Controls dialog Dwg_Blks to view blocks in drawing. ; Arguments: 1 ; BlkList@ = List of valid blocks in block table ; Returns: Nth Number of the block selected from BlkList@ or nil. ;--------------------------------------------------------------------------- (defun View_Blks: (BlkList@ / BlockLen# Option# Dcl_Id% ImageName$ No_Blks# No_Pages# Pg_No# Rep# SlideRef$ );variables (setq No_Pages# (fix (/ (1- (length BlkList@)) 20.0)) Pg_No# 0 BlockLen# (length BlkList@) Option# 99 );setq ;------------------------------------------------------------------------- ; Load DCL dialog: Dwg_Blks in Blk_Lib.dcl ;------------------------------------------------------------------------- (princ "\nView Blocks ") (princ "\nSelect a block or option: ")(princ) (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (while (/= Option# 1) (new_dialog "Dwg_Blks" Dcl_Id%) (if (= Pg_No# No_Pages#) (mode_tile "next" 1) (mode_tile "next" 0) );if (if (= Pg_No# 0) (mode_tile "previous" 1) (mode_tile "previous" 0) );if (if (> BlockLen# 19) (setq No_Blks# 20) (setq No_Blks# BlockLen#) );if (set_tile "title" (strcat " View Blocks " (itoa (+ Pg_No# 1)) " of " (itoa (+ No_Pages# 1))) );set_tile (action_tile "next" "(done_dialog 4)") (action_tile "previous" "(done_dialog 3)") (action_tile "cancel" "(done_dialog 2)") (setq Rep# 1) (repeat (fix No_Blks#) (action_tile (strcat "sld" (itoa Rep#)) "(setq SlideRef$ $key Pick t)" );action_tile (setq ImageName$ (nth (+ (* Pg_No# 20) (- Rep# 1)) BlkList@)) (start_image (strcat "sld" (itoa Rep#))) (slide_image 0 0 (dimx_tile (strcat "sld" (itoa Rep#))) (dimy_tile (strcat "sld" (itoa Rep#))) (strcat "C:\\Custom\\Blk_Sld\\" ImageName$ ".sld") );slide_image (end_image) (set_tile (strcat "sld" (itoa Rep#) "text") ImageName$ );set_tile (setq Rep# (1+ Rep#)) );repeat (setq Option# (start_dialog)) (if (= Option# 4);next (setq Pg_No# (1+ Pg_No#) BlockLen# (- BlockLen# 20) SlideRef$ nil );setq );if (if (= Option# 3);previous (setq Pg_No# (- Pg_No# 1) BlockLen# (+ BlockLen# 20) SlideRef$ nil );setq );if (if (= Option# 2);cancel (setq Option# 1 SlideRef$ nil );setq );if );while (unload_dialog Dcl_Id%) (if SlideRef$ (setq Ref# (- (+ (* Pg_No# 20) (atoi (substr SlideRef$ 4))) 1)) );if Ref# );defun View_Blks: ;--------------------------------------------------------------------------- ; BlockMgr: - Start Main Function ;--------------------------------------------------------------------------- ; Get BlkList@ ;--------------------------------------------------------------------------- (setq BlkList@ *NewBlkList@) ;--------------------------------------------------------------------------- ; Get LayList@ ;--------------------------------------------------------------------------- (setq TblList@ (tblnext "layer" t)) (while TblList@ (setq LayList@ (cons (cdr (assoc 2 TblList@)) LayList@) TblList@ (tblnext "layer") );setq );while (setq LayList@ (acad_strlsort LayList@)) (setq NewList@ (list "Current layer")) (setq Cnt# 0) (while (< Cnt# 100) (if (member (itoa Cnt#) LayList@) (if NewList@ (setq NewList@ (append NewList@ (list (itoa Cnt#)))) (setq NewList@ (list (itoa Cnt#))) );if );if (setq Cnt# (1+ Cnt#)) );while (foreach Item LayList@ (if (not (member Item NewList@)) (setq NewList@ (append NewList@ (list (Capitals Item)))) );if );foreach (setq LayList@ NewList@) ;--------------------------------------------------------------------------- ; Get PntList@ ;--------------------------------------------------------------------------- (setq PntList@ '( "User selects" "Specify point" "0,0" "Lower left limits" "Lower right limits" "Upper left limits" "Upper right limits" ) );setq ;--------------------------------------------------------------------------- ; Get ScaList@ ;--------------------------------------------------------------------------- (setq ScaList@ '( "User selects" "Specify scale" "Dim scale" "Full scale" ) );setq ;--------------------------------------------------------------------------- ; Initialize local variables. ;--------------------------------------------------------------------------- (if *Blk_Mgr@ (if (and (member (nth 0 *Blk_Mgr@) BlkList@)(member (nth 1 *Blk_Mgr@) LayList@)) (setq Block$ (nth 0 *Blk_Mgr@) nthBlkList$ (itoa (- (length BlkList@)(length (member Block$ BlkList@)))) Layer$ (nth 1 *Blk_Mgr@) nthLayList$ (itoa (- (length LayList@)(length (member Layer$ LayList@)))) Point$ (nth 2 *Blk_Mgr@) nthPntList$ (itoa (- (length PntList@)(length (member Point$ PntList@)))) Scale$ (nth 3 *Blk_Mgr@) nthScaList$ (itoa (- (length ScaList@)(length (member Scale$ ScaList@)))) Explode$ (nth 4 *Blk_Mgr@) Dot$ (nth 5 *Blk_Mgr@) );setq );if );if (if (not Block$) (setq Block$ (nth 0 BlkList@) nthBlkList$ "0" Layer$ (nth 0 LayList@) nthLayList$ "0" Point$ (nth 0 PntList@) nthPntList$ "0" Scale$ (nth 0 ScaList@) nthScaList$ "0" Explode$ "0" Dot$ "1" );setq );if (if (= (cdr (assoc 70 (tblsearch "BLOCK" Block$))) 2) (setq Attribs$ "1") (setq Attribs$ "0") );if ;--------------------------------------------------------------------------- ; Load DCL dialog: Blk_Mgr in Blk_Lib.dcl ;--------------------------------------------------------------------------- (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (setq Option# 99) (while (/= Option# 1) (new_dialog "Blk_Mgr" Dcl_Id%) (set_tile "title" (strcat " " LibTitle$ " Library Manager")) (start_list "block")(mapcar 'add_list BlkList@)(end_list) (set_tile "block" nthBlkList$) (start_list "point")(mapcar 'add_list PntList@)(end_list) (set_tile "point" nthPntList$) (start_list "layer")(mapcar 'add_list LayList@)(end_list) (set_tile "layer" nthLayList$) (start_list "scale")(mapcar 'add_list ScaList@)(end_list) (set_tile "scale" nthScaList$) (set_tile "explode" Explode$) (set_tile "dot" Dot$) (start_image "blocksld") (slide_image 0 0 (dimx_tile "blocksld") (dimy_tile "blocksld") (strcat "C:\\Custom\\Blk_Sld\\" Block$ ".sld") );slide_image (end_image) (action_tile "block" "(BlockSub:)") (action_tile "point" "(PointSub:)") (action_tile "layer" "(LayerSub:)") (action_tile "scale" "(ScaleSub:)") (action_tile "explode" "(ExplodeSub:)") (action_tile "viewblk" "(done_dialog 5)") (action_tile "dot" "(DotSub:)") (action_tile "addlib" "(done_dialog 4)") (action_tile "editlib" "(done_dialog 3)") (action_tile "cancel" "(done_dialog 2)") (setq Option# (start_dialog)) (setq *Blk_Mgr@ (list Block$ Layer$ Point$ Scale$ Explode$ Dot$)) (if (= Option# 5);viewblk (progn (ViewBlkSub:) (setq Option# 99) );progn );if (if (= Option# 4);addlib (progn (AddLibSub:) (setq Option# 1) );progn );if (if (= Option# 3);editlib (setq Option# 1 MslideList@ nil EditLib$ "Yes" );setq );if (if (= Option# 2);cancel (setq Option# 1 MslideList@ nil );setq );if );while (unload_dialog Dcl_Id%) MslideList@ );defun BlockMgr: ;----------------------------------------------------------------------------- ; Mslide_Wblock: - Create slide and wblock. ; Arguments: 2 ; Block$ = Block name to wblock ; Dot$ = Flag to include insertion Dot with slide, "0" or "1". ; Returns: Creates slide and wblock. ;----------------------------------------------------------------------------- (defun Mslide_Wblock: (Block$ Dot$ / Color0# Ent1^ Ent2^ PathBlock$ Pt1@ Pt2@ RealBlk& Rep# RevSS& SSDims& UcsIcon# );variables (SaveDwgName);Save Drawing*.dwg as a different name (setq Pt1@ (polar (getvar "VIEWCTR") (* pi 0.5)(/ (getvar "VIEWSIZE") 2.0))) (setq Pt2@ (polar Pt1@ (* pi 1.5) (getvar "VIEWSIZE"))) (command "UNDO" "BEGIN") (if (ssget "X") (command ".ERASE" (ssget "X") "") );if (command ".LAYER" "T" "*" "U" "*" "ON" "*" "") (command ".LAYER" "T" "0" "U" "0" "ON" "0" "S" "0" "") (setq Color0# (abs (cdr (assoc 62 (tblnext "layer" t))))) (command ".LAYER" "M" "0" "C" "7" "" "") (command ".INSERT" Block$ "0,0" "" "" "") (command ".ZOOM" "E") (setq UcsIcon# (getvar "UCSICON")) (setvar "UCSICON" 0) (setq RealBlk& (ssget "L")) (if RealBlk& (progn (command ".EXPLODE" "L") (setq SSDims& (ssget "X" (list (cons 0 "DIMENSION")))) (if SSDims& (progn (command ".ERASE" (ssget "X") "") (command ".INSERT" Block$ "0,0" "" "" "") );progn );if (if (= Dot$ "1") (progn (command ".DONUT" "0" "0.00000001" "0,0" "") (setq Ent1^ (entlast)) );progn );if (command ".ZOOM" "E") (if (= Dot$ "1") (progn (command ".DONUT" "0" (/ (getvar "VIEWSIZE") 25.0) "0,0" "") (command ".CHPROP" "L" "" "C" "6" "");Color choice optional (setq Ent2^ (entlast)) );progn );if (command ".ZOOM" "0.95x") (command ".REGEN") (command ".MSLIDE" (strcat DefPath$ Block$)) (if (= Dot$ "1") (progn (entdel Ent1^)(entdel Ent2^) );progn );if (setq PathBlock$ (strcat BlkPath$ Block$ ".dwg")) (if SSDims& (progn (if (findfile PathBlock$) (command ".WBLOCK" PathBlock$ "Y" Block$) (command ".WBLOCK" PathBlock$ Block$) );if (command ".ERASE" (ssget "X") "") );progn (progn (setq RevSS& (ReverseSS (ssget "X"))) (if (findfile PathBlock$) (command ".WBLOCK" PathBlock$ "Y" "" "0,0" RevSS& "") (command ".WBLOCK" PathBlock$ "" "0,0" RevSS& "") );if );progn );if );progn (command ".ERASE" (ssget "X") "") );if (command "UNDO" "END") (command "U") (command ".ZOOM" "W" Pt1@ Pt2@) (command ".LAYER" "M" "0" "C" Color0# "" "") (setvar "UCSICON" UcsIcon#) );defun Mslide_Wblock: ;----------------------------------------------------------------------------- ; Blk_Lib_def: - Append PathDef$ file with block insertion data. ; Arguments: 1 ; MslideList@ = List of Block$, Layer$, Point$, Scale$, Explode$, Attribs$ ; Returns: Appends PathDef$ file with new block insertion data. ;----------------------------------------------------------------------------- (defun Blk_Lib_def: (MslideList@ / BlkList$ FileName% Q$) (setq Q$ "\"") (setq BlkList$ (strcat Q$(nth 0 MslideList@)Q$ "," ;Block$ Q$(nth 1 MslideList@)Q$ "," ;Layer$ Q$(nth 2 MslideList@)Q$ "," ;Point$ Q$(nth 3 MslideList@)Q$ "," ;Scale$ Q$(nth 4 MslideList@)Q$ "," ;Explode$ Q$(nth 5 MslideList@)Q$) ;Attribs$ );setq (setq FileName% (open PathDef$ "a")) (write-line BlkList$ FileName%) (close FileName%) );defun Blk_Lib_def: ;----------------------------------------------------------------------------- ; Blk_Mgr - Start Main Function ;----------------------------------------------------------------------------- ; Get BlkList@ ;----------------------------------------------------------------------------- (setq TblList@ (tblnext "block" t)) (while TblList@ (if (/= (substr (cdr (assoc 2 TblList@)) 1 1) "*") (setq BlkList@ (cons (cdr (assoc 2 TblList@)) BlkList@)) );if (setq TblList@ (tblnext "block")) );while (if BlkList@ (progn (if (equal BlkList@ *BlkList@) (setq BlkList@ *NewBlkList@) (progn (setq *BlkList@ BlkList@);Store global *BlkList@ variable (setq BlkList@ (acad_strlsort BlkList@)) (setq BlkList@ (BlkSlides BlkList@)) (setq *NewBlkList@ BlkList@);Store global *NewBlkList@ variable );progn );if (if BlkList@ (progn (princ "\nSelect an option: ")(princ) (setq MslideList@ (BlockMgr:)) );progn (setq EditLib$ (GetYesNo (strcat LibTitle$ " Library Manager") (strcat "No valid blocks found in drawing for Library\n" "Manager. Do you want to edit the Library?") "Quest") );setq );if );progn (setq EditLib$ (GetYesNo (strcat LibTitle$ " Library Manager") (strcat "No blocks found in drawing for Library\n" "Manager. Do you want to edit the Library?") "Quest") );setq );if (if (and MslideList@ BlkList@) (progn (setq Block$ (nth 0 MslideList@) Layer$ (nth 1 MslideList@) Point$ (nth 2 MslideList@) Scale$ (nth 3 MslideList@) Explode$ (nth 4 MslideList@) Attribs$ (nth 5 MslideList@) Dot$ (nth 6 MslideList@) );setq (if (= Point$ "Specify point") (progn (while (null MgrPoint~) (setq MgrPoint~ (getpoint (strcat "\nInsertion point for " Block$ " block: ")) );setq );while (setq Point$ (strcat (rtosr (car MgrPoint~)) " " (rtosr (cadr MgrPoint~))) );setq );progn );if (if (= Point$ "0,0") (setq Point$ "0 0") );if (if (= Scale$ "Specify scale") (progn (while (or (null MgrScale~) (< MgrScale~ 0)) (setq MgrScale~ (getreal (strcat "\nScale factor for " Block$ " block <1>: ") );getreal );setq (if (null MgrScale~) (setq MgrScale~ 1.0) );if (if (<= MgrScale~ 0) (princ "\nScale factor must be greater than 0.")(princ) );if );while (setq Scale$ (rtosr MgrScale~)) );progn );if (if (= Scale$ "Full scale") (setq Scale$ "1.0") );if (setq MslideList@ (list (eval Block$) (eval Layer$) (eval Point$) (eval Scale$) (eval Explode$) (eval Attribs$)) );setq (setq PathBlock$ (strcat DefPath$ Block$ ".dwg")) (if (findfile PathBlock$) (setq Replace$ (GetYesNo (strcat LibTitle$ " Library Manager") (strcat PathBlock$ "\nexists. Do you want to replace it?") "Block") );setq );if (if (/= Replace$ "No") (progn (Mslide_Wblock: Block$ Dot$) (Blk_Lib_def: MslideList@) (Blk_Mgr LibTitle$ PathDef$ PathBlk$) );progn );if );progn );if (if (= EditLib$ "Yes") (Edit_Lib LibTitle$ PathDef$) );if (setq *error* Old_error) (princ) );defun Blk_Mgr ;------------------------------------------------------------------------------- ; c:Blk_Menu [Block Library Menu] ;------------------------------------------------------------------------------- (defun c:Blk_Menu (/ Cmd$ Dcl_Id% GetShortCut: Old_error ShortCutCmd$) ;----------------------------------------------------------------------------- ; c:Blk_Menu subfunction = GetShortCut: ;----------------------------------------------------------------------------- ; GetShortCut: ;----------------------------------------------------------------------------- (defun GetShortCut: (/ Char$ Cnt# TabFlag) (setq ShortCutCmd$ (nth (atoi (get_tile "CommandList")) CommandList@)) (if (/= (substr ShortCutCmd$ 1 1) " ") (progn (setq Cnt# 1 Cmd$ "") (while (<= Cnt# (strlen ShortCutCmd$)) (setq Char$ (substr ShortCutCmd$ Cnt# 1)) (if (= Char$ "\t")(setq TabFlag t)) (if (not TabFlag) (setq Cmd$ (strcat Cmd$ Char$)) );if (setq Cnt# (1+ Cnt#)) );while (if (/= Cmd$ "") (setq ShortCutCmd$ (strcat "(c:" Cmd$ ")")) (setq ShortCutCmd$ nil) );if );progn (setq ShortCutCmd$ nil) );if );defun GetShortCut: ;----------------------------------------------------------------------------- ; c:Blk_Menu - Start Main Function ;----------------------------------------------------------------------------- (setq Old_error *error* *error* *BL_error*) ;----------------------------------------------------------------------------- ; Load DCL dialog: Blk_Menu in Blk_Lib.dcl ;----------------------------------------------------------------------------- (princ "\nBlock Library Menu") (princ "\nSelect a Block Library Menu Command or option: ")(princ) (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (new_dialog "Blk_Menu" Dcl_Id%) (setq CommandList@ (list "ALLBL\tAll_Blk_Lib\tAll Blocks to Library" "BLM\tBlk_Mgr\tBlock Library Manager" "BLMENU\tBlk_Menu\tBlock Library Menu" "DB\tDwg_Blks\tDrawing Blocks" "EDBL\tEdit_Lib\tEdit Block Library" "INBL\tInBlocks\tInsert Blocks from folder" "LIB\tLibrary\tUser Block Library" "SBL\tSel_Lib\tSelect Block Library" "ADL\tAdd_Dwgs\tAdd Drawings to Library" );list );setq (start_list "CommandList") (mapcar 'add_list CommandList@) (end_list) (action_tile "CommandList" "(GetShortCut:)(done_dialog)") (action_tile "cancel" "(done_dialog)") (start_dialog) (unload_dialog Dcl_Id%) (if ShortCutCmd$ (progn (princ "\nCommand: ")(princ Cmd$) (eval (read ShortCutCmd$)) );progn );if (setq *error* Old_error) (princ) );defun c:Blk_Menu ;------------------------------------------------------------------------------- ; BlkSlides - Creates slides of all blocks in drawing. ;------------------------------------------------------------------------------- (defun BlkSlides (BlkList@ / Block$ Color0# NewBlkList@ PathSld$ Pt1@ Pt2@ RealBlk& UcsIcon# );variables (SaveDwgName);Save Drawing*.dwg as a different name (princ "\nUpdating slides ")(princ) (runapp "DEL C:\\Custom\\Blk_Sld\\*.sld" nil);Delete old temp slides (setq Pt1@ (polar (getvar "VIEWCTR") (* pi 0.5)(/ (getvar "VIEWSIZE") 2.0))) (setq Pt2@ (polar Pt1@ (* pi 1.5) (getvar "VIEWSIZE"))) (command "UNDO" "BEGIN") (if (ssget "X") (command ".ERASE" (ssget "X") "") );if (command ".LAYER" "T" "*" "U" "*" "ON" "*" "") (command ".LAYER" "T" "0" "U" "0" "ON" "0" "S" "0" "") (setq Color0# (abs (cdr (assoc 62 (tblnext "layer" t))))) (command ".LAYER" "M" "0" "C" "7" "" "") (setq UcsIcon# (getvar "UCSICON")) (setvar "UCSICON" 0) (foreach Block$ BlkList@ (setq PathSld$ (strcat "C:\\Custom\\Blk_Sld\\" Block$)) (command ".INSERT" Block$ "0,0" "" "" "") (command ".ZOOM" "E") (setq RealBlk& (ssget "L")) (if RealBlk& (progn (command ".EXPLODE" "L") (command ".DONUT" "0" "0.00000001" "0,0" "") (command ".ZOOM" "E") (command ".DONUT" "0" (/ (getvar "VIEWSIZE") 25.0) "0,0" "") (command ".CHPROP" "L" "" "C" "6" "");Color choice optional (command ".ZOOM" "0.95x") (command ".REGEN") (command ".MSLIDE" PathSld$) (command ".ERASE" (ssget "X") "") (if NewBlkList@ (setq NewBlkList@ (append NewBlkList@ (list Block$))) (setq NewBlkList@ (list Block$)) );if );progn (command ".ERASE" (ssget "X") "") );if (Whirl) );foreach (command ".ZOOM" "W" Pt1@ Pt2@) (command ".LAYER" "M" "0" "C" Color0# "" "") (command "UNDO" "END") (command "U") (setvar "UCSICON" UcsIcon#) (princ " ") NewBlkList@ );defun BlkSlides ;------------------------------------------------------------------------------- ; Custom_Dirs - Creates PathDef$, PathBlk$ and C:\Custom\Blk_Sld folders for ; storing slides and blocks. ; Arguments: 3 ; LibTitle$ = Library title ; PathDef$ = Pathname and DefFile name for slides ; PathBlk$ = Pathname and DefFile name for blocks ; Returns: Creates folders for DefFiles, slides and blocks for Library. ;------------------------------------------------------------------------------- (defun Custom_Dirs (LibTitle$ PathDef$ PathBlk$ / BlkFile$ Cnt# DefFile$ Echo1$ Echo2$ Echo3$ Echo4$ FileName% MadeIt NewDir$ Path1$ Path2$ Path3$ Path4$ Path5$ PathFile$ Q$ Text$ WriteText$ );variables (if (not (findfile "C:\\Custom\\Blk_Temp.bat")) (vl-mkdir "C:\\Custom") );if (if (not *Blk_Lib*);Check for global *Blk_Lib* variable (Blk_Lib_Msg);Installation Instructions );if ;----------------------------------------------------------------------------- ; Evaluate Arguments and get DefFile$ variable. ;----------------------------------------------------------------------------- (if (null LibTitle$) (setq LibTitle$ "Block") );if (if (null PathDef$) (setq PathDef$ "C:\\Custom\\Blk_Lib\\Blk_Lib.def") );if (if (null PathBlk$) (setq PathBlk$ PathDef$) );if (setq Q$ "\"" Text$ (strcat ";" (String$ 79 "-")) );setq ;----------------------------------------------------------------------------- ; Create C:\Custom\Blk_Temp.bat file to create new folders and files. ;----------------------------------------------------------------------------- (setq FileName% (open "C:\\Custom\\Blk_Temp.bat" "w")) (write-line ":---- Blk_Temp.bat ----" FileName%) (write-line "@ECHO OFF" FileName%) (write-line "C:" FileName%) (if (and (/= PathDef$ "C:\\Custom\\Blk_Lib\\Blk_Lib.def") (/= PathDef$ "C:\\Custom\\Blk_Lib\\Sel_Lib.dat") (/= PathDef$ "C:\\Custom\\Blk_Sld\\Blk_Sld.def") );and (progn (if (not (findfile PathDef$)) (progn (setq Path1$ (strcat PathDef$ "\n")) (setq DefFile$ (cadr (GetPathFile PathDef$))) (setq Echo1$ (strcat "ECHO " Text$ " > " Q$ PathDef$ Q$)) (setq Echo2$ (strcat "ECHO ; " DefFile$ " >> " Q$ PathDef$ Q$)) (setq Echo3$ (strcat "ECHO " Text$ ">> " Q$ PathDef$ Q$)) (setq Cnt# 1) (while (< Cnt# (strlen PathDef$)) (if (and (= (substr PathDef$ Cnt# 1) (chr 92)) (/= Cnt# 3)) (progn (setq NewDir$ (strcat Q$ (substr PathDef$ 1 (- Cnt# 1)) Q$)) (vl-mkdir (strcat Q$ (substr PathDef$ 1 (- Cnt# 1)) Q$)) );progn );if (setq Cnt# (1+ Cnt#)) );while (write-line Echo1$ FileName%) (write-line Echo2$ FileName%) (write-line Echo3$ FileName%) (setq MadeIt t) );progn );if (if (/= PathBlk$ PathDef$) (if (not (findfile PathBlk$)) (progn (setq Path2$ (strcat PathBlk$ "\n")) (setq BlkFile$ (cadr (GetPathFile PathBlk$))) (setq Echo1$ (strcat "ECHO " Text$ " > " Q$ PathBlk$ Q$)) (setq Echo2$ (strcat "ECHO ; " BlkFile$ " >> " Q$ PathBlk$ Q$)) (setq Echo3$ (strcat "ECHO " Text$ ">> " Q$ PathBlk$ Q$)) (setq Cnt# 1) (while (< Cnt# (strlen PathBlk$)) (if (and (= (substr PathBlk$ Cnt# 1) (chr 92)) (/= Cnt# 3)) (progn (setq NewDir$ (strcat Q$ (substr PathBlk$ 1 (- Cnt# 1)) Q$)) (vl-mkdir (strcat Q$ (substr PathBlk$ 1 (- Cnt# 1)) Q$)) );progn );if (setq Cnt# (1+ Cnt#)) );while (write-line Echo1$ FileName%) (write-line Echo2$ FileName%) (write-line Echo3$ FileName%) (setq MadeIt t) );progn );if );if );progn );if (setq PathFile$ "C:\\Custom\\Blk_Lib\\Blk_Lib.def") (if (not (findfile PathFile$)) (progn (vl-mkdir "C:\\Custom\\Blk_Lib") (setq Path4$ (strcat PathFile$ "\n")) (setq Echo1$ (strcat "ECHO " Text$ " > " PathFile$)) (setq Echo2$ (strcat "ECHO ; Blk_Lib.def >> " PathFile$)) (setq Echo3$ (strcat "ECHO " Text$ ">> " PathFile$)) (write-line Echo1$ FileName%) (write-line Echo2$ FileName%) (write-line Echo3$ FileName%) (setq MadeIt t) );progn );if (setq PathFile$ "C:\\Custom\\Blk_Lib\\Sel_Lib.dat") (if (not (findfile PathFile$)) (progn (vl-mkdir "C:\\Custom\\Blk_Lib") (setq Path5$ (strcat PathFile$ "\n")) (setq Echo1$ (strcat "ECHO " Text$ " > " PathFile$)) (setq Echo2$ (strcat "ECHO ; Sel_Lib.dat >> " PathFile$)) (setq Echo3$ (strcat "ECHO " Text$ ">> " PathFile$)) (setq WriteText$ (strcat Q$ "Block" Q$ "," Q$ "C:\\Custom\\Blk_Lib\\Blk_Lib.def" Q$ "," Q$ "C:\\Custom\\Blk_Lib\\Blk_Lib.def" Q$) );setq (setq Echo4$ (strcat "ECHO " WriteText$ ">> " PathFile$)) (write-line Echo1$ FileName%) (write-line Echo2$ FileName%) (write-line Echo3$ FileName%) (write-line Echo4$ FileName%) (setq MadeIt t) );progn );if (setq PathFile$ "C:\\Custom\\Blk_Sld\\Blk_Sld.def") (if (not (findfile PathFile$)) (progn (vl-mkdir "C:\\Custom\\Blk_Sld") (setq Path3$ (strcat PathFile$ "\n")) (setq Echo1$ (strcat "ECHO " Text$ " > " PathFile$)) (setq Echo2$ (strcat "ECHO ; Blk_Sld.def >> " PathFile$)) (setq Echo3$ (strcat "ECHO " Text$ ">> " PathFile$)) (write-line Echo1$ FileName%) (write-line Echo2$ FileName%) (write-line Echo3$ FileName%) (setq MadeIt t) );progn );if (setq PathFile$ "C:\\Temp\\Temp.dcl") (if (not (findfile PathFile$)) (progn (vl-mkdir "C:\\Temp") (setq Echo1$ (strcat "ECHO // > " PathFile$)) (write-line Echo1$ FileName%) (setq MadeIt t) );progn );if (close FileName%) (if MadeIt (progn (runapp "C:\\Custom\\Blk_Temp.bat" nil) (setq LibTitle$ nil PathDef$ nil PathBlk$ nil) );progn );if );defun Custom_Dirs ;------------------------------------------------------------------------------- ; c:Dwg_Blks [Drawing Blocks] - View and select drawing blocks. ;------------------------------------------------------------------------------- (defun c:Dwg_Blks (/ Blk_Sld_def: BlkList@ Dwg_Blks: Old_error TblList@ );variables (setvar "ATTREQ" 0) (setvar "CMDECHO" 0) (setvar "REGENMODE" 1) ;----------------------------------------------------------------------------- ; c:Dwg_Blks subfunctions = Blk_Sld_def:, Dwg_Blks: ;----------------------------------------------------------------------------- ; Blk_Sld_def: - Create Blk_Sld.def file. ;----------------------------------------------------------------------------- (defun Blk_Sld_def: (BlkList@ / Attribs$ BlockData$ FileName% PathFile$ Q$ Text$ );variables (setq Text$ (strcat ";" (String$ 79 "-"))) (setq PathFile$ "C:\\Custom\\Blk_Sld\\Blk_Sld.def") (setq FileName% (open PathFile$ "w")) (write-line Text$ FileName%) (write-line "; Blk_Sld.def" FileName%) (write-line Text$ FileName%) (setq Q$ "\"") (foreach Block$ BlkList@ (if (= (cdr (assoc 70 (tblsearch "BLOCK" Block$))) 2) (setq Attribs$ "1") (setq Attribs$ "0") );if (setq BlockData$ (strcat Q$ Block$ Q$ "," ;Block Q$ "Current layer" Q$ "," ;Layer Q$ "User selects" Q$ "," ;Point Q$ "User selects" Q$ "," ;Scale Q$ "0" Q$ "," ;Explode Q$ Attribs$ Q$) ;Attribs );setq (write-line BlockData$ FileName%) );foreach (close FileName%) );defun Blk_Sld_def: ;----------------------------------------------------------------------------- ; Dwg_Blks: - Controls dialog Dwg_Blks.dcl to view select drawing blocks. ;----------------------------------------------------------------------------- (defun Dwg_Blks: (LibTitle$ DefFile$ / Attribs$ AttribsList@ BlkList@ Block$ BlockLen# Option# Cnt# Dcl_Id% EOF Explode$ ExplodeList@ Field# FileName% ImageName$ Item$ Layer$ LayerList@ Mid$ No_Blks# No_Pages# PathBlock$ PathFile$ Pg_No# Pick Point@ PointList@ Q$ Ref# Rep# ScaleList@ Scale~ SlideRef$ StartNo# Text$ UserPoint@ UserScale~ );variables ;--------------------------------------------------------------------------- ; Get Lists from DefFile$. ;--------------------------------------------------------------------------- (if (setq PathFile$ (findfile (strcat "C:\\Custom\\Blk_Sld\\" DefFile$))) (setq FileName% (open PathFile$ "r")) (progn (GetOK (strcat LibTitle$ " Library") (strcat DefFile$ " file not found.") "AlertX" );GetOK (exit) );progn );if (setq Q$ "\"") (setq EOF nil)(setq Item$ "") (while (null EOF) (setq Text$ (read-line FileName%)) (if Text$ (if (= (substr Text$ 1 1) Q$) (progn (setq StartNo# 2) (setq Cnt# 1) (setq Field# 1) (while (and (<= Cnt# (strlen Text$)) (< Field# 6)) (setq Mid$ (substr Text$ Cnt# 3)) (if (= Mid$ "\",\"") (progn (setq Item$ (substr Text$ StartNo# (- Cnt# StartNo#)) );setq (cond ((= Field# 1) (if BlkList@ (setq BlkList@ (append BlkList@ (list Item$))) (setq BlkList@ (list Item$)) );if );Field# 1 ((= Field# 2) (if LayerList@ (setq LayerList@ (append LayerList@ (list Item$))) (setq LayerList@ (list Item$)) );if );Field# 2 ((= Field# 3) (if PointList@ (setq PointList@ (append PointList@ (list Item$))) (setq PointList@ (list Item$)) );if );Field# 3 ((= Field# 4) (if ScaleList@ (setq ScaleList@ (append ScaleList@ (list Item$))) (setq ScaleList@ (list Item$)) );if );Field# 4 ((= Field# 5) (if ExplodeList@ (setq ExplodeList@ (append ExplodeList@ (list Item$))) (setq ExplodeList@ (list Item$)) );if );Field# 5 (t (exit)) );cond (setq Field# (1+ Field#)) (setq StartNo# (+ Cnt# 3)) );progn );if (setq Cnt# (1+ Cnt#)) );while (setq Item$ (substr Text$ StartNo# (- (strlen Text$) StartNo#)) );setq (if AttribsList@ (setq AttribsList@ (append AttribsList@ (list Item$))) (setq AttribsList@ (list Item$)) );if );progn );if (setq EOF t) );if );while (close FileName%) (setq No_Pages# (fix (/ (1- (length BlkList@)) 20.0)) Pg_No# 0 BlockLen# (length BlkList@) Option# 99 );setq ;--------------------------------------------------------------------------- ; Load DCL dialog: Dwg_Blks in Blk_Lib.dcl ;--------------------------------------------------------------------------- (princ "\nSelect a block or option: ")(princ) (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (while (/= Option# 1) (new_dialog "Dwg_Blks" Dcl_Id%) (if (= Pg_No# No_Pages#) (mode_tile "next" 1) (mode_tile "next" 0) );if (if (= Pg_No# 0) (mode_tile "previous" 1) (mode_tile "previous" 0) );if (if (> BlockLen# 19) (setq No_Blks# 20) (setq No_Blks# BlockLen#) );if (set_tile "title" (strcat " " LibTitle$ " " (itoa (+ Pg_No# 1)) " of " (itoa (+ No_Pages# 1))) );set_tile (action_tile "next" "(done_dialog 4)") (action_tile "previous" "(done_dialog 3)") (action_tile "cancel" "(done_dialog 2)") (setq Rep# 1) (repeat (fix No_Blks#) (action_tile (strcat "sld" (itoa Rep#)) "(setq SlideRef$ $key Pick t)") (setq ImageName$ (nth (+ (* Pg_No# 20) (- Rep# 1)) BlkList@)) (start_image (strcat "sld" (itoa Rep#))) (slide_image 0 0 (dimx_tile (strcat "sld" (itoa Rep#))) (dimy_tile (strcat "sld" (itoa Rep#))) (strcat "C:\\Custom\\Blk_Sld\\" ImageName$ ".sld") );slide_image (end_image) (set_tile (strcat "sld" (itoa Rep#) "text") ImageName$ );set_tile (setq Rep# (1+ Rep#)) );repeat (setq Option# (start_dialog)) (if (= Option# 4);next (setq Pg_No# (1+ Pg_No#) BlockLen# (- BlockLen# 20) SlideRef$ nil );setq );if (if (= Option# 3);previous (setq Pg_No# (- Pg_No# 1) BlockLen# (+ BlockLen# 20) SlideRef$ nil );setq );if (if (= Option# 2);cancel (setq Option# 1 SlideRef$ nil );setq );if );while (unload_dialog Dcl_Id%) (if (and SlideRef$ Pick) (progn (setq Ref# (- (+ (* Pg_No# 20) (atoi (substr SlideRef$ 4))) 1)) (setq Block$ (nth Ref# BlkList@) Layer$ (nth Ref# LayerList@) Point@ (nth Ref# PointList@) Scale~ (nth Ref# ScaleList@) Explode$ (nth Ref# ExplodeList@) Attribs$ (nth Ref# AttribsList@) );setq (if (= Block$ " ") (exit) );if (if (= Point@ "Lower left limits") (setq Point@ (getvar "LIMMIN")) );if (if (= Point@ "Lower right limits") (setq Point@ (list (car (getvar "LIMMAX")) (cadr (getvar "LIMMIN")))) );if (if (= Point@ "Upper left limits") (setq Point@ (list (car (getvar "LIMMIN")) (cadr (getvar "LIMMAX")))) );if (if (= Point@ "Upper right limits") (setq Point@ (getvar "LIMMAX")) );if (if (and (= Point@ "User selects") (/= Scale~ "User selects")) (progn (while (null UserPoint@) (setq UserPoint@ (getpoint (strcat "\nInsertion point for " Block$ " block: ")) );setq );while (setq Point@ UserPoint@) );progn );if (if (/= Point@ "User selects") (progn (if (= (type Point@) 'STR) (setq Point@ (RealList Point@)) );if (if (/= (type Point@) 'LIST) (progn (GetOK (strcat LibTitle$ " Library") (strcat "Invalid insertion point for " Block$ "\nblock in " DefFile$ " file.") "AlertX" );GetOK (exit) );progn );if );progn );if (if (= Scale~ "Dim scale") (if (= (getvar "DIMSCALE") 0) (progn (GetOK (strcat LibTitle$ " Library") "DIMSCALE value must be greater than 0." "AlertX" );GetOK (exit) );progn (setq Scale~ (getvar "DIMSCALE")) );if );if (if (and (= Scale~ "User selects") (/= Point@ "User selects")) (progn (while (or (null UserScale~) (< UserScale~ 0)) (setq UserScale~ (getreal (strcat "\nScale factor for " Block$ " block <1>: ") );getreal );setq (if (null UserScale~) (setq UserScale~ 1.0) );if (if (<= UserScale~ 0) (princ "\nScale factor must be greater than 0.")(princ) );if );while (setq Scale~ (rtosr UserScale~)) );progn );if (if (/= Scale~ "User selects") (progn (if (= (type Scale~) 'STR) (setq Scale~ (atof Scale~)) );if (if (<= Scale~ 0) (progn (GetOK (strcat LibTitle$ " Library") (strcat "Invalid scale factor for " Block$ "\nblock in " DefFile$ " file.") "AlertX" );GetOK (exit) );progn );if );progn );if (setq Osmode (getvar "OSMODE")) (setvar "OSMODE" 0);None (if (= Explode$ "1");Yes (progn (setq PathBlock$ (strcat "*" Block$)) (if (and (= Point@ "User selects") (= Scale~ "User selects")) (command ".INSERT" PathBlock$) (command ".INSERT" PathBlock$ Point@ Scale~) );if );progn (progn (setq PathBlock$ Block$) (if (/= Layer$ "Current layer") (if (tblsearch "LAYER" Layer$) (command ".LAYER" "T" Layer$ "U" Layer$ "ON" Layer$ "S" Layer$ "" );command (command ".LAYER" "M" Layer$ "") );if );if (if (and (= Point@ "User selects") (= Scale~ "User selects")) (command ".INSERT" PathBlock$) (command ".INSERT" PathBlock$ Point@ Scale~ "") );if );progn );if (setvar "OSMODE" Osmode) );progn );if (princ) );defun Dwg_Blks: ;----------------------------------------------------------------------------- ; c:Dwg_Blks - Start Main Function ;----------------------------------------------------------------------------- (setq Old_error *error* *error* *BL_error*) (SaveDwgName);Save Drawing*.dwg as a different name (princ "\nDrawing Blocks ")(princ) (Custom_Dirs "Drawing Blocks" nil nil) ;----------------------------------------------------------------------------- ; Get BlkList@ ;----------------------------------------------------------------------------- (setq TblList@ (tblnext "block" t)) (while TblList@ (if (/= (substr (cdr (assoc 2 TblList@)) 1 1) "*") (setq BlkList@ (cons (cdr (assoc 2 TblList@)) BlkList@)) );if (setq TblList@ (tblnext "block")) );while (if BlkList@ (progn (if (equal BlkList@ *BlkList@) (setq BlkList@ *NewBlkList@) (progn (setq *BlkList@ BlkList@);Store global *BlkList@ variable (setq BlkList@ (acad_strlsort BlkList@)) (setq BlkList@ (BlkSlides BlkList@)) (setq *NewBlkList@ BlkList@);Store global *NewBlkList@ variable );progn );if (if BlkList@ (progn (Blk_Sld_def: BlkList@) (Dwg_Blks: "Drawing Blocks" "Blk_Sld.def") );progn (GetOK "Drawing Blocks" "No valid blocks found in drawing." "AlertX") );if );progn (GetOK "Drawing Blocks" "No blocks found in drawing." "AlertX") );if (setq *error* Old_error) (princ) );defun c:Dwg_Blks ;------------------------------------------------------------------------------- ; c:Edit_Lib - Calls function Edit_Lib with default arguments. ;------------------------------------------------------------------------------- (defun c:Edit_Lib () (Edit_Lib nil nil)) ;------------------------------------------------------------------------------- ; Edit_Lib [Edit Block Library] - Rearrange or delete block insertion data. ; Arguments: 2 ; LibTitle$ = Library title ; PathDef$ = Pathname and DefFile name for slides ; Returns: Rearrange or delete lines of block insertion data in PathDef$ file. ;------------------------------------------------------------------------------- (defun Edit_Lib (LibTitle$ PathDef$ / AttribsList@ BlkList@ BlockLen# Option# Cnt# DefFile$ DefPath$ Dcl_Id% EOF ExplodeList@ Field# FileName% ImageName$ Item$ LayerList@ Mid$ MoveRef# No_Blks# No_Pages# Old_error Pg_No# PointList@ Q$ Ref# Rep# ScaleList@ SlideRef$ StartNo# Text$ Verify: WriteData@ );variables ;----------------------------------------------------------------------------- ; Verify: - Verifies options ;----------------------------------------------------------------------------- (defun Verify: (Option#) (if (= Option# 6);move (if SlideRef$ (progn (setq MoveRef# (- (+ (* Pg_No# 20) (atoi (substr SlideRef$ 4))) 1)) (setq SlideRef$ nil) );progn (GetOK (strcat "Edit " LibTitle$ " Library") (strcat "Select an image to move then select Move. Then" "\nselect a new image location and select Paste.") "Inform" );GetOK );if );if (if (= Option# 5);paste (if (and SlideRef$ MoveRef#) (progn (setq Ref# (- (+ (* Pg_No# 20) (atoi (substr SlideRef$ 4))) 1)) (if (/= Ref# MoveRef#) (progn (setq BlkList@ (Move_nth MoveRef# Ref# BlkList@) LayerList@ (Move_nth MoveRef# Ref# LayerList@) PointList@ (Move_nth MoveRef# Ref# PointList@) ScaleList@ (Move_nth MoveRef# Ref# ScaleList@) ExplodeList@ (Move_nth MoveRef# Ref# ExplodeList@) AttribsList@ (Move_nth MoveRef# Ref# AttribsList@) );setq (setq SlideRef$ nil MoveRef# nil );setq (done_dialog 5) );progn (progn (GetOK (strcat "Edit " LibTitle$ " Library") (strcat "The move and paste image" "\nlocations cannot be the same.") "AlertX" );GetOK (setq SlideRef$ nil MoveRef# nil );setq );progn );if );progn (progn (GetOK (strcat "Edit " LibTitle$ " Library") (strcat "Select an image to move then select Move. Then" "\nselect a new image location and select Paste.") "Inform" );GetOK (setq SlideRef$ nil MoveRef# nil );setq );progn );if );if (if (= Option# 4);delete (if SlideRef$ (if (= (GetYesNo (strcat "Edit " LibTitle$ " Library") (strcat "Are you sure you want to delete this" "\nimage definition in the " LibTitle$ " Library?") "Delete") "Yes") (progn (setq Ref# (- (+ (* Pg_No# 20) (atoi (substr SlideRef$ 4))) 1)) (setq BlkList@ (Delete_nth Ref# BlkList@) LayerList@ (Delete_nth Ref# LayerList@) PointList@ (Delete_nth Ref# PointList@) ScaleList@ (Delete_nth Ref# ScaleList@) ExplodeList@ (Delete_nth Ref# ExplodeList@) AttribsList@ (Delete_nth Ref# AttribsList@) No_Pages# (fix (/ (1- (length BlkList@)) 20.0)) BlockLen# (1- BlockLen#) SlideRef$ nil MoveRef# nil );setq (if (= BlockLen# 0) (setq Pg_No# No_Pages# BlockLen# (+ BlockLen# 20) );setq );if (done_dialog 4) );progn );if (GetOK (strcat "Edit " LibTitle$ " Library") "Select an image to delete then select Delete." "Inform" );GetOK );if );if );defun Verify: ;----------------------------------------------------------------------------- (setq Old_error *error* *error* *BL_error*) (setvar "CMDECHO" 0) (setvar "REGENMODE" 1) ;----------------------------------------------------------------------------- ; Evaluate Arguments and get DefPath$ and DefFile$ variables. ;----------------------------------------------------------------------------- (if (null LibTitle$) (setq LibTitle$ "Block") );if (if (null PathDef$) (setq PathDef$ "C:\\Custom\\Blk_Lib\\Blk_Lib.def") );if (setq DefPath$ (car (GetPathFile PathDef$))) (setq DefFile$ (cadr (GetPathFile PathDef$))) (princ (strcat "\nEdit " LibTitle$ " Library "))(princ) (Custom_Dirs LibTitle$ PathDef$ nil) ;----------------------------------------------------------------------------- ; Get Lists from PathDef$ file. ;----------------------------------------------------------------------------- (if (findfile PathDef$) (setq FileName% (open PathDef$ "r")) (progn (GetOK (strcat LibTitle$ " Library") (strcat DefFile$ " file not found\nfor " LibTitle$ " Library.") "AlertX" );GetOK (exit) );progn );if (setq Q$ "\"") (setq Rep# 0) (setq EOF nil) (setq Item$ "") (while (null EOF) (setq Rep# (1+ Rep#)) (if (= Rep# 20) (progn (setq Rep# 0) (Whirl) );progn );if (setq Text$ (read-line FileName%)) (if Text$ (if (= (substr Text$ 1 1) Q$) (progn (setq StartNo# 2) (setq Cnt# 1) (setq Field# 1) (while (and (<= Cnt# (strlen Text$)) (< Field# 6)) (setq Mid$ (substr Text$ Cnt# 3)) (if (= Mid$ "\",\"") (progn (setq Item$ (substr Text$ StartNo# (- Cnt# StartNo#)) );setq (cond ((= Field# 1) (if BlkList@ (setq BlkList@ (append BlkList@ (list Item$))) (setq BlkList@ (list Item$)) );if );Field# 1 ((= Field# 2) (if LayerList@ (setq LayerList@ (append LayerList@ (list Item$))) (setq LayerList@ (list Item$)) );if );Field# 2 ((= Field# 3) (if PointList@ (setq PointList@ (append PointList@ (list Item$))) (setq PointList@ (list Item$)) );if );Field# 3 ((= Field# 4) (if ScaleList@ (setq ScaleList@ (append ScaleList@ (list Item$))) (setq ScaleList@ (list Item$)) );if );Field# 4 ((= Field# 5) (if ExplodeList@ (setq ExplodeList@ (append ExplodeList@ (list Item$))) (setq ExplodeList@ (list Item$)) );if );Field# 5 (t (exit)) );cond (setq Field# (1+ Field#)) (setq StartNo# (+ Cnt# 3)) );progn );if (setq Cnt# (1+ Cnt#)) );while (setq Item$ (substr Text$ StartNo# (- (strlen Text$) StartNo#)) );setq (if AttribsList@ (setq AttribsList@ (append AttribsList@ (list Item$))) (setq AttribsList@ (list Item$)) );if );progn );if (setq EOF t) );if );while (princ " ") (close FileName%) (setq No_Pages# (fix (/ (1- (length BlkList@)) 20.0)) Pg_No# 0 BlockLen# (length BlkList@) Option# 99 );setq ;----------------------------------------------------------------------------- ; Load DCL dialog: Edit_Lib in Blk_Lib.dcl ;----------------------------------------------------------------------------- (princ "\nSelect a block or option: ")(princ) (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (while (> Option# 2) (new_dialog "Edit_Lib" Dcl_Id%) (if (= Pg_No# No_Pages#) (mode_tile "next" 1) (mode_tile "next" 0) );if (if (= Pg_No# 0) (mode_tile "previous" 1) (mode_tile "previous" 0) );if (if (> BlockLen# 19) (setq No_Blks# 20) (setq No_Blks# BlockLen#) );if (set_tile "title" (strcat " Edit " LibTitle$ " Library " (itoa (+ Pg_No# 1)) " of " (itoa (+ No_Pages# 1))) );set_tile (action_tile "previous" "(done_dialog 8)") (action_tile "next" "(done_dialog 7)") (action_tile "move" "(Verify: 6)") (action_tile "paste" "(Verify: 5)") (action_tile "delete" "(Verify: 4)") (action_tile "accept" "(done_dialog 3)") (action_tile "cancel" "(done_dialog 2)") (setq Rep# 1) (repeat (fix No_Blks#) (action_tile (strcat "sld" (itoa Rep#)) "(setq SlideRef$ $key)") (setq ImageName$ (nth (+ (* Pg_No# 20) (- Rep# 1)) BlkList@)) (start_image (strcat "sld" (itoa Rep#))) (slide_image 0 0 (dimx_tile (strcat "sld" (itoa Rep#))) (dimy_tile (strcat "sld" (itoa Rep#))) (strcat DefPath$ ImageName$ ".sld") );slide_image (end_image) (set_tile (strcat "sld" (itoa Rep#) "text") ImageName$ );set_tile (setq Rep# (1+ Rep#)) );repeat (setq Option# (start_dialog)) (if (= Option# 8);previous (setq Pg_No# (- Pg_No# 1) BlockLen# (+ BlockLen# 20) SlideRef$ nil );setq );if (if (= Option# 7);next (setq Pg_No# (1+ Pg_No#) BlockLen# (- BlockLen# 20) SlideRef$ nil );setq );if (if (= Option# 3);accept (progn (setq Text$ (strcat ";" (String$ 79 "-"))) (setq FileName% (open PathDef$ "w")) (write-line Text$ FileName%) (write-line (strcat "; " DefFile$) FileName%) (write-line Text$ FileName%) (setq Q$ "\"")(setq Rep# 0) (foreach Item BlkList@ (setq WriteData@ (strcat Q$(nth Rep# BlkList@)Q$ "," ;Block$ Q$(nth Rep# LayerList@)Q$ "," ;Layer$ Q$(nth Rep# PointList@)Q$ "," ;Point$ Q$(nth Rep# ScaleList@)Q$ "," ;Scale$ Q$(nth Rep# ExplodeList@)Q$ "," ;Explode$ Q$(nth Rep# AttribsList@)Q$) ;Attribs$ );setq (write-line WriteData@ FileName%) (setq Rep# (1+ Rep#)) );foreach (close FileName%) (setq Option# 1) );progn );if (if (= Option# 2);cancel (setq Option# 1) );if );while (unload_dialog Dcl_Id%) (setq *error* Old_error) (princ) );defun Edit_Lib ;------------------------------------------------------------------------------- ; c:InBlocks [Insert Blocks] - Insert blocks from selected folder. ; May be used with c:All_Blk_Lib to quickly add blocks to Libraries. ;------------------------------------------------------------------------------- (defun c:InBlocks (/ BlkName$ Block$ FolderDwgs@ InsertAll$ Old_error PathFilename$ Replace$ );variables (setq Old_error *error* *error* *BL_error*) (setvar "ATTREQ" 0) (setvar "CMDECHO" 0) (setvar "REGENMODE" 1) (princ "\nSelect a drawing in a folder to insert blocks for Library: ")(princ) (if (not *LastPath$) (setq *LastPath$ "") );if (if (setq PathFilename$ (getfiled " Select a drawing in a folder to insert blocks for Library" *LastPath$ "dwg" 2)) (progn (setq *LastPath$ (car (GetPathFile PathFilename$))) (setq InsertAll$ (GetYesNo "Insert Blocks" (strcat "Do you want to insert all blocks" "\nfrom the " (substr *LastPath$ 1 (- (strlen *LastPath$) 1)) " folder?") "Quest") );setq (if (= InsertAll$ "Yes") (progn (princ "\nInserting blocks ")(princ) (if (>= (atoi (getvar "ACADVER")) 15) (command "LAYOUT" "S" "Model") );if (setq FolderDwgs@ (vl-directory-files *LastPath$ "*.dwg" 1)) (foreach Block$ FolderDwgs@ (setq BlkName$ (substr Block$ 1 (- (strlen Block$) 4))) (if (not (member (strcase Block$) (list (strcase (getvar "DWGNAME")) "BLK_LIB.DWG"))) (progn (if (tblsearch "BLOCK" BlkName$) (setq Replace$ (GetYesNoCancel "Insert Blocks" (strcat "A Block named " BlkName$ " already exists" "\nin the drawing. Do you want to redefine it?") "Block") );setq (setq Replace$ "Yes") );if (if (= Replace$ "Yes") (command ".INSERT" (strcat *LastPath$ BlkName$) "0,0" "" "" "") );if (if (= Replace$ "Cancel") (progn (command "ZOOM" "E") (princ " ") (exit) );progn );if );progn );if (whirl) );foreach (command ".ZOOM" "E") (princ " ") );progn );if );progn );if (setq *error* Old_error) (princ) );defun c:InBlocks ;------------------------------------------------------------------------------- ; SaveDwgName - Saves drawing before backing it up as C:\Custom\Blk_Lib.dwg. ;------------------------------------------------------------------------------- (defun SaveDwgName (/ DwgName$) (if (>= (atoi (getvar "ACADVER")) 15) (if (/= (getvar "CTAB") "Model") (command "PSPACE") );if );if (if (= (getvar "DWGTITLED") 0) (progn (setq DwgName$ "C:\\Custom\\Blk_Lib.dwg") (if (findfile DwgName$) (command ".SAVEAS" "" DwgName$ "Y") (command ".SAVEAS" "" DwgName$) );if );progn (if (/= (getvar "DBMOD") 0) (command ".QSAVE") );if );if (setq DwgName$ (strcat (getvar "DWGPREFIX")(getvar "DWGNAME"))) (if (/= DwgName$ "C:\\Custom\\Blk_Lib.dwg") (if (findfile "C:\\Custom\\Blk_Lib.dwg");Backup copy of drawing (command ".SAVE" "C:\\Custom\\Blk_Lib.dwg" "Y") (command ".SAVE" "C:\\Custom\\Blk_Lib.dwg") );if );if (princ) );defun SaveDwgName ;------------------------------------------------------------------------------- ; c:Sel_Lib [Select Block Library] - Selects Block Library to use or adds or ; edits library definitions. ;------------------------------------------------------------------------------- (defun c:Sel_Lib (/ BlockLib@ Cnt# DatFile$ EOF Field# FileName% Item$ LibTitle$ Mid$ Old_error PathDat$ Q$ Rep# SlideLib@ StartNo# Text$ TitleLib@ );variables (setq Old_error *error* *error* *BL_error*) (setvar "CMDECHO" 0) (setvar "REGENMODE" 1) (setq LibTitle$ "Select Block") (setq PathDat$ "C:\\Custom\\Blk_Lib\\Sel_Lib.dat") (setq DatFile$ (cadr (GetPathFile PathDat$))) (princ (strcat "\n" LibTitle$ " Library "))(princ) (Custom_Dirs LibTitle$ PathDat$ nil) ;----------------------------------------------------------------------------- ; Get Lists from PathDat$ file. ;----------------------------------------------------------------------------- (if (findfile PathDat$) (setq FileName% (open PathDat$ "r")) (progn (GetOK (strcat LibTitle$ " Library") (strcat DatFile$ " file not found\nfor " LibTitle$ " Library.") "AlertX" );GetOK (exit) );progn );if (setq Q$ "\"") (setq Rep# 0) (setq EOF nil) (setq Item$ "") (while (null EOF) (setq Text$ (read-line FileName%)) (if Text$ (if (= (substr Text$ 1 1) Q$) (progn (setq StartNo# 2) (setq Cnt# 1) (setq Field# 1) (while (and (<= Cnt# (strlen Text$)) (< Field# 3)) (setq Mid$ (substr Text$ Cnt# 3)) (if (= Mid$ "\",\"") (progn (setq Item$ (substr Text$ StartNo# (- Cnt# StartNo#)) );setq (cond ((= Field# 1) (if TitleLib@ (setq TitleLib@ (append TitleLib@ (list Item$))) (setq TitleLib@ (list Item$)) );if );Field# 1 ((= Field# 2) (if SlideLib@ (setq SlideLib@ (append SlideLib@ (list Item$))) (setq SlideLib@ (list Item$)) );if );Field# 2 (t (exit)) );cond (setq Field# (1+ Field#)) (setq StartNo# (+ Cnt# 3)) );progn );if (setq Cnt# (1+ Cnt#)) );while (setq Item$ (substr Text$ StartNo# (- (strlen Text$) StartNo#)) );setq (if BlockLib@ (setq BlockLib@ (append BlockLib@ (list Item$))) (setq BlockLib@ (list Item$)) );if );progn );if (setq EOF t) );if );while (close FileName%) (Sel_Lib TitleLib@ SlideLib@ BlockLib@) (setq *error* Old_error) (princ) );defun c:Sel_Lib ;------------------------------------------------------------------------------- ; Sel_Lib [Select Block Library] - Select Block Library to use or add or edit ; library definitions. ; Arguments: 3 ; TitleLib@ = List of Library titles ; SlideLib@ = List of Pathnames and DefFiles for slides ; BlockLib@ = List of Pathnames and DefFiles for blocks ; Returns: Selects a Block Library to use or adds or edits library definitions. ;------------------------------------------------------------------------------- (defun Sel_Lib (TitleLib@ SlideLib@ BlockLib@ / Option# Dcl_Id% GetReturn@ Ins# intLib# LibrarySub: nthLibrary$ Pick# Rep# SlideMemb@ TitleMemb@ BlkSldScr );variables ;----------------------------------------------------------------------------- ; Sel_Lib subfunctions = Add_Edit_Defs:, Sel_Lib_dat:, LibrarySub: ;----------------------------------------------------------------------------- ; Add_Edit_Defs: [Add or Edit Library Definitions] ; Arguments: 6 ; Title$ = Title of Library ; SldPath$ = Pathname and DefFile for slides ; BlkPath$ = Pathname and DefFile for blocks ; Dialog$ = Dialog to use, Add_Lib_Defs or Edit_Lib_Defs ; TitleMemb@ = List of valid TitleLib@ items in all caps. ; SlideMemb@ = List of valid SlideLib@ items in all caps. ; Returns: List of Title$, SldPath$ and BlkPath$ or nil. ;----------------------------------------------------------------------------- (defun Add_Edit_Defs: (Title$ SldPath$ BlkPath$ Dialog$ TitleMemb@ SlideMemb@ / BlkFlag Option# Dcl_Id% DialogTitle$ NewBlkPath$ NewSldPath$ Num# OldTitle$ OrgTitle$ Return@ SldFlag ShowPath$ TitleName: ClrTitle: BlkBrowse: FolderOptions: );variables ;--------------------------------------------------------------------------- ; Add_Edit_Defs: subfunctions = TitleName:, ClrTitle:, BlkBrowse:, FolderOptions: ;--------------------------------------------------------------------------- ; TitleName: ;--------------------------------------------------------------------------- (defun TitleName: () (setq Title$ (NoSpaces Title$)) (if (< (strlen Title$) 2) (setq Title$ (strcat Title$)) (setq Title$ (strcat (strcase (substr Title$ 1 1)) (substr Title$ 2 (- (strlen Title$) 1))) );setq );if (if (or (= (strcase Title$) "LIBRARY") (= (strcase Title$) "LIBRARIES")) (setq Title$ "") );if (if (> (strlen Title$) 8) (if (= (strcase (substr Title$ (- (strlen Title$) 7) 8)) " LIBRARY") (setq Title$ (substr Title$ 1 (- (strlen Title$) 8))) );if );if (if (> (strlen Title$) 10) (if (= (strcase (substr Title$ (- (strlen Title$) 9) 10)) " LIBRARIES") (setq Title$ (substr Title$ 1 (- (strlen Title$) 10))) );if );if (if (= Title$ "") (progn (setq Title$ OldTitle$) (set_tile "title" Title$) (GetOK DialogTitle$ "Enter a Library Title. " "Exclam") (mode_tile "title" 2) );progn (progn (if (member Title$ TitleMemb@) (progn (set_tile "title" Title$) (GetOK DialogTitle$ (strcat Title$ " Library has been defined." "\nEnter a different Library Title.") "Exclam" );GetOK (setq Title$ OrgTitle$) (set_tile "title" Title$) (setq OldTitle$ Title$) );progn (progn (set_tile "title" Title$) (setq OldTitle$ Title$) );progn );if );progn );if (setq BlkFlag nil SldFlag nil) );defun TitleName: ;--------------------------------------------------------------------------- ; ClrTitle: ;--------------------------------------------------------------------------- (defun ClrTitle: () (set_tile "title" "") (setq Title$ "") (mode_tile "title" 2) (setq BlkFlag nil SldFlag nil) );defun ClrTitle: ;--------------------------------------------------------------------------- ; BlkBrowse: ;--------------------------------------------------------------------------- (defun BlkBrowse: () (if (/= (strcase Title$) "NEW TITLE NAME") (progn (FolderOptions:) (if (or (= *Fld_Opts* "1")(= *Fld_Opts* "2")) (progn (if (= *Fld_Opts* "1") (GetOK DialogTitle$ (strcat "If needed, create a new folder for the\n" Title$ ".def file for the " Title$ " Library, then\n" "select it as the new folder location.") "Filefolder" );GetOK );if (if (not *LastPath$) (setq *LastPath$ "") );if (setq NewBlkPath$ (getfiled " Block Folder Location" (strcat *LastPath$ Title$ ".def") "def" (atoi *Fld_Opts*)) );setq (if NewBlkPath$ (setq *LastPath$ (car (GetPathFile NewBlkPath$))) );if (if (and NewBlkPath$ (member (strcase NewBlkPath$) SlideMemb@)) (progn (setq Num# (- (length SlideMemb@) (length (member (strcase NewBlkPath$) SlideMemb@))) );setq (GetOK DialogTitle$ (strcat NewBlkPath$ " has been defined\n" "by the " (nth Num# TitleMemb@) " Library. Choose or create a new folder\n" "for the " Title$ ".def file for the " Title$ " Library.") "Filefolder" );GetOK (setq NewBlkPath$ nil) );progn );if (if (and NewBlkPath$ (= (car (GetPathFile NewBlkPath$)) "C:\\Custom\\Blk_Sld\\") );and (progn (GetOK DialogTitle$ (strcat "C:\\Custom\\Blk_Sld folder is used by Drawing Blocks\n" "and View Blocks. Choose or create a new folder\n" "for the " Title$ ".def file for the " Title$ " Library.") "Filefolder" );GetOK (setq NewBlkPath$ nil) );progn );if (if (and NewBlkPath$ (= (car (GetPathFile NewBlkPath$)) "C:\\Custom\\Blk_Lib\\") );and (progn (GetOK DialogTitle$ (strcat "C:\\Custom\\Blk_Lib folder is used and defined\n" "by Block Library. Choose or create a new folder\n" "for the " Title$ ".def file for the " Title$ " Library.") "Filefolder" );GetOK (setq NewBlkPath$ nil) );progn );if (if (and NewSldPath$ (= (car (GetPathFile NewSldPath$)) "C:\\Custom\\") );and (progn (GetOK DialogTitle$ (strcat "No new folder was created inside C:\\Custom.\n" "Choose or create a new folder for the\n" Title$ ".def file for the " Title$ " Library.") "Filefolder" );GetOK (setq NewSldPath$ nil) );progn );if (if NewBlkPath$ (progn (if BlkSldScr (setq BlkSldScr nil SldPath$ "" );setq );if (setq *PreviousPath$ NewBlkPath$ BlkPath$ NewBlkPath$ );setq (if (= SldPath$ "") (progn (setq NewSldPath$ NewBlkPath$ *PreviousPath$ NewBlkPath$ SldPath$ NewBlkPath$ );setq (set_tile "sldpath" SldPath$) );progn );if (setq NewSldPath$ NewBlkPath$ *PreviousPath$ NewBlkPath$ SldPath$ NewBlkPath$ );setq );progn );if (set_tile "blkpath" BlkPath$) (setq BlkFlag nil SldFlag nil) );progn );if (if (= *Fld_Opts* "3") (progn (if *PreviousPath$ (setq NewBlkPath$ (getfiled (strcat " Select a drawing in a folder for " Title$ " Library") (car (GetPathFile *PreviousPath$)) "dwg" 2) );setq (progn (if (not *LastPath$) (setq *LastPath$ "") );if (setq NewBlkPath$ (getfiled (strcat " Select a drawing in a folder for " Title$ " Library") *LastPath$ "dwg" 2) );setq );progn );if (if NewBlkPath$ (setq NewBlkPath$ (strcat (car (GetPathFile NewBlkPath$)) Title$ ".def") *LastPath$ (car (GetPathFile NewBlkPath$)) );setq );if (if (and NewBlkPath$ (member (strcase NewBlkPath$) SlideMemb@)) (progn (setq Num# (- (length SlideMemb@) (length (member (strcase NewBlkPath$) SlideMemb@))) );setq (GetOK DialogTitle$ (strcat NewBlkPath$ " has been defined\n" "by the " (nth Num# TitleMemb@) " Library. Choose or create a new folder\n" "for the " Title$ ".def file for the " Title$ " Library.") "Filefolder" );GetOK (setq NewBlkPath$ nil) );progn );if (if (and NewBlkPath$ (= (car (GetPathFile NewBlkPath$)) "C:\\Custom\\Blk_Sld\\") );and (progn (GetOK DialogTitle$ (strcat "C:\\Custom\\Blk_Sld folder is used by Drawing Blocks\n" "and View Blocks. Choose or create a new folder\n" "for the " Title$ ".def file for the " Title$ " Library.") "Filefolder" );GetOK (setq NewBlkPath$ nil) );progn );if (if (and NewBlkPath$ (= (car (GetPathFile NewBlkPath$)) "C:\\Custom\\Blk_Lib\\") );and (progn (GetOK DialogTitle$ (strcat "C:\\Custom\\Blk_Lib folder is used and defined\n" "by Block Library. Choose or create a new folder\n" "for the " Title$ ".def file for the " Title$ " Library.") "Filefolder" );GetOK (setq NewBlkPath$ nil) );progn );if (if (and NewSldPath$ (= (car (GetPathFile NewSldPath$)) "C:\\Custom\\") );and (progn (GetOK DialogTitle$ (strcat "No new folder was created inside C:\\Custom.\n" "Choose or create a new folder for the\n" Title$ ".def file for the " Title$ " Library.") "Filefolder" );GetOK (setq NewSldPath$ nil) );progn );if (if NewBlkPath$ (progn (setq BlkSldScr t *PreviousPath$ NewBlkPath$ BlkPath$ NewBlkPath$ NewSldPath$ NewBlkPath$ *PreviousPath$ NewBlkPath$ SldPath$ NewBlkPath$ );setq (set_tile "sldpath" SldPath$) );progn (setq BlkSldScr nil) );if (set_tile "blkpath" BlkPath$) (setq BlkFlag nil SldFlag nil) );progn );if );progn (progn (GetOK DialogTitle$ "Enter a new Library Title name." "Exclam") (mode_tile "title" 2) );progn );if );defun BlkBrowse: ;--------------------------------------------------------------------------- ; FolderOptions: - Options for Library Folders ;--------------------------------------------------------------------------- (defun FolderOptions: (/ Dcl_Id% Info:) (defun Info: () (GetOK "Block Library Message" (strcat "The option, to use a folder with drawings to create\n" "a new Library, is only available in a Single Document\n" "Interface. If you need this option, close all other\n" "open drawings and try again.") "" );GetOK (mode_tile "accept" 2) );defun Info: (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (new_dialog "FolderOptions" Dcl_Id%) (if (not *Fld_Opts*) (setq *Fld_Opts* "1")) (if (and (> (length (GetDwgsList)) 1)(= *Fld_Opts* "3")) (setq *Fld_Opts* "1")) (if (> (length (GetDwgsList)) 1) (progn (mode_tile "3" 1) (mode_tile "msg3" 1) (mode_tile "msg4" 1) );progn );if (set_tile "title" (strcat " " DialogTitle$)) (set_tile "radio" *Fld_Opts*) (set_tile "msg1" "Select or create a new Library Folder.") (set_tile "msg2" "Map to an existing Library folder.") (set_tile "msg3" "Use a folder with drawings to create a") (set_tile "msg4" "new Library and run a script to make slides.") (action_tile "radio" "(setq *Fld_Opts* $value)") (action_tile "info" "(Info:)") (start_dialog) (unload_dialog Dcl_Id%) (princ) );defun FolderOptions: ;--------------------------------------------------------------------------- ; Add_Edit_Defs: - Start Main Function ;--------------------------------------------------------------------------- (if (= Dialog$ "Add_Lib_Defs") (progn (princ "\nAdd Library Definitions ")(princ) (setq DialogTitle$ "Add Library Definitions") );progn (progn (princ "\nEdit Library Definitions ")(princ) (setq DialogTitle$ "Edit Library Definitions") );progn );if ;--------------------------------------------------------------------------- ; Load DCL dialog: Add_Lib_Defs or Edit_Lib_Defs in Blk_Lib.dcl ;--------------------------------------------------------------------------- (setq Cloice# 99) (if (/= SldPath$ "") (setq NewSldPath$ SldPath$) (setq NewSldPath$ nil) );if (if (/= BlkPath$ "") (setq NewBlkPath$ BlkPath$) (setq NewBlkPath$ nil) );if (setq OldTitle$ Title$) (setq OrgTitle$ Title$) (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (princ "\nSelect an option: ")(princ) (while (/= Option# 1) (if (> (GetDclWidth SldPath$) 41.26) (progn (setq ShowPath$ (strcat (substr SldPath$ 4) (substr SldPath$ 1 3) "...")) (while (> (GetDclWidth ShowPath$) 41.26) (setq ShowPath$ (substr ShowPath$ 2)) );while (setq ShowPath$ (strcat (substr ShowPath$ (- (strlen ShowPath$) 5)) (substr ShowPath$ 1 (- (strlen ShowPath$) 6)))) );progn (setq ShowPath$ SldPath$) );if (new_dialog Dialog$ Dcl_Id%) (set_tile "title" Title$) (set_tile "titlelabel" "Title:") (set_tile "folderlabel" "Folder:") (set_tile "sldpath" ShowPath$) (mode_tile "sldpath" 1);grey out (action_tile "title" "(setq Title$ $value)(TitleName:)") (action_tile "clear" "(ClrTitle:)") (action_tile "browse" "(BlkBrowse:)");browse (action_tile "accept" "(done_dialog 4)");accept (action_tile "delete" "(done_dialog 3)");delete (action_tile "cancel" "(done_dialog 2)");cancel (setq Option# (start_dialog)) (if (= Option# 4);accept (progn (setq Option# 1) (if (and (/= SldPath$ "") (/= BlkPath$ "")) (if (not BlkSldScr) (setq Return@ (list Title$ SldPath$ BlkPath$) *Blk_Lib* Title$ );setq (setq Return@ (list Title$ SldPath$ BlkPath$) *Blk_Lib* Title$ );setq );if (progn (GetOK DialogTitle$ "Folder location is required!" "Exclam") (Add_Edit_Defs: Title$ SldPath$ BlkPath$ Dialog$ TitleMemb@ SlideMemb@) );progn );if );progn );if (if (= Option# 3);delete (progn (setq Option# 1) (if (= (GetYesNo DialogTitle$ (strcat "Are you sure you want to delete" "\nthe definitions for " OrgTitle$ " Library?") "Delete") "Yes") (setq Return@ (list "delete" "delete" "delete")) (setq Return@ nil) );if );progn );if (if (= Option# 2);cancel (setq Option# 1 Return@ nil );setq );if );while (unload_dialog Dcl_Id%) Return@ );defun Add_Edit_Defs: ;----------------------------------------------------------------------------- ; Sel_Lib_dat: - Updates changes to Sel_Lib.dat Library definitions. ; Arguments: 3 ; TitleLib@ = List of Library Titles ; SlideLib@ = List of Pathname and DefFile for slides ; BlockLib@ = List of Pathname and DefFile for blocks ; Returns: Updates new changes to Sel_Lib.dat Library definitions. ;----------------------------------------------------------------------------- (defun Sel_Lib_dat: (TitleLib@ SlideLib@ BlockLib@ / FileName% Text$ Q$ Rep# WriteData@ );variables (setq Text$ (strcat ";" (String$ 79 "-"))) (setq FileName% (open PathDat$ "w")) (write-line Text$ FileName%) (write-line (strcat "; " DatFile$) FileName%) (write-line Text$ FileName%) (setq Q$ "\"")(setq Rep# 0) (foreach Item TitleLib@ (setq WriteData@ (strcat Q$(nth Rep# TitleLib@)Q$ "," ;LibTitle$ Q$(nth Rep# SlideLib@)Q$ "," ;PathDef$ Q$(nth Rep# BlockLib@)Q$) ;PathBlk$ );setq (write-line WriteData@ FileName%) (setq Rep# (1+ Rep#)) );foreach (close FileName%) );defun Sel_Lib_dat: ;----------------------------------------------------------------------------- ; LibrarySub: ;----------------------------------------------------------------------------- (defun LibrarySub: () (setq nthLibrary$ (get_tile "library") intLib# (atoi nthLibrary$) *Blk_Lib* (nth intLib# TitleLib@) );setq (set_tile "library" nthLibrary$) );defun LibrarySub: ;----------------------------------------------------------------------------- ; Sel_Lib - Start Main Function ;----------------------------------------------------------------------------- ; Load DCL dialog: Sel_Lib in Blk_Lib.dcl ;----------------------------------------------------------------------------- (setq Cloice# 99) (if (and (= (type *Blk_Lib*) 'STR) (member *Blk_Lib* TitleLib@)) (setq intLib# (- (length TitleLib@) (length (member *Blk_Lib* TitleLib@))) nthLibrary$ (itoa intLib#) );setq (setq *Blk_Lib* "Block" intLib# (- (length TitleLib@) (length (member *Blk_Lib* TitleLib@))) nthLibrary$ (itoa intLib#) );setq );if (setq Dcl_Id% (load_dialog "Blk_Lib.dcl")) (princ "\nSelect an option: ")(princ) (while (/= Option# 1) (new_dialog "Sel_Lib" Dcl_Id%) (start_list "library") (mapcar 'add_list TitleLib@) (end_list) (set_tile "library" nthLibrary$) (action_tile "library" "(LibrarySub:)") (action_tile "add" "(done_dialog 5)");add (action_tile "edit" "(done_dialog 4)");edit (action_tile "select" "(done_dialog 3)");select (action_tile "cancel" "(done_dialog 2)");cancel (setq Option# (start_dialog)) (if (= Option# 5);add (setq Pick# 5 Option# 1 );setq );if (if (= Option# 4);edit (setq Pick# 4 Option# 1 );setq );if (if (= Option# 3);select (setq Pick# 3 Option# 1 );setq );if (if (= Option# 2);cancel (setq Option# 1) );if );while (unload_dialog Dcl_Id%) (if (= Pick# 5);add (progn (setq TitleMemb@ TitleLib@) (setq Rep# 0 SlideMemb@ nil) (foreach Item SlideLib@ (if SlideMemb@ (setq SlideMemb@ (append SlideMemb@ (list (strcase (nth Rep# SlideLib@)))) );setq (setq SlideMemb@ (list (strcase (nth Rep# SlideLib@)))) );if (setq Rep# (1+ Rep#)) );foreach (setq GetReturn@ (Add_Edit_Defs: "New Title Name" "" "" "Add_Lib_Defs" TitleMemb@ SlideMemb@) );setq (if GetReturn@ (progn (setq Rep# 0 Ins# nil) (foreach Item TitleLib@ (if (> (strcase (nth 0 GetReturn@)) (strcase (nth Rep# TitleLib@)) );> (setq Ins# Rep#) );if (setq Rep# (1+ Rep#)) );foreach (if Ins# (setq Ins# (1+ Ins#)) );if (if (not Ins#) (setq Ins# 0) );if (if (= Ins# (length TitleLib@)) (setq Ins# nil) );if (if Ins# (setq TitleLib@ (Insert_nth Ins# (nth 0 GetReturn@) TitleLib@) SlideLib@ (Insert_nth Ins# (nth 1 GetReturn@) SlideLib@) BlockLib@ (Insert_nth Ins# (nth 2 GetReturn@) BlockLib@) );setq (setq TitleLib@ (append TitleLib@ (list (nth 0 GetReturn@))) SlideLib@ (append SlideLib@ (list (nth 1 GetReturn@))) BlockLib@ (append BlockLib@ (list (nth 2 GetReturn@))) );setq );if (if BlkSldScr (if (= (GetYesNo "Block Library Message" (strcat "Block Library needs to run a script" "\nto create slides for " (nth 0 GetReturn@) " Library." "\nDo you want to continue?") "Quest") "Yes") (progn (SaveDwgName);Save Drawing*.dwg as a different name (Sel_Lib_dat: TitleLib@ SlideLib@ BlockLib@) (Slide_Script (nth 2 GetReturn@)) );progn (progn (Sel_Lib_dat: TitleLib@ SlideLib@ BlockLib@) (c:Sel_Lib) );progn );if (progn (Sel_Lib_dat: TitleLib@ SlideLib@ BlockLib@) (c:Sel_Lib) );progn );if );progn (c:Sel_Lib) );if );progn );if (if (= Pick# 4);edit (if (= (strcase (nth intLib# TitleLib@)) "BLOCK") (progn (GetOK "Select Block Library" (strcat "Cannot edit the default definitions for Block Library." "\nAdd or select another Library to edit definitions.") "AlertX" );GetOK (c:Sel_Lib) );progn (progn (setq Rep# 0 TitleMemb@ nil) (foreach Item TitleLib@ (if (/= Rep# intLib#) (if TitleMemb@ (setq TitleMemb@ (append TitleMemb@ (list (nth Rep# TitleLib@)))) (setq TitleMemb@ (list (nth Rep# TitleLib@))) );if );if (setq Rep# (1+ Rep#)) );foreach (setq Rep# 0 SlideMemb@ nil) (foreach Item SlideLib@ (if (/= Rep# intLib#) (if SlideMemb@ (setq SlideMemb@ (append SlideMemb@ (list (strcase (nth Rep# SlideLib@)))) );setq (setq SlideMemb@ (list (strcase (nth Rep# SlideLib@)))) );if );if (setq Rep# (1+ Rep#)) );foreach (setq GetReturn@ (Add_Edit_Defs: (nth intLib# TitleLib@) (nth intLib# SlideLib@) (nth intLib# BlockLib@) "Edit_Lib_Defs" TitleMemb@ SlideMemb@) );setq (if GetReturn@ (progn (if (= (nth 1 GetReturn@) "delete") (setq TitleLib@ (Delete_nth intLib# TitleLib@) SlideLib@ (Delete_nth intLib# SlideLib@) BlockLib@ (Delete_nth intLib# BlockLib@) );setq (if (= (strcase (nth 0 GetReturn@)) (strcase (nth intLib# TitleLib@))) (setq TitleLib@ (Change_nth intLib# (nth 0 GetReturn@) TitleLib@) SlideLib@ (Change_nth intLib# (nth 1 GetReturn@) SlideLib@) BlockLib@ (Change_nth intLib# (nth 2 GetReturn@) BlockLib@) );setq (progn (setq TitleLib@ (Delete_nth intLib# TitleLib@) SlideLib@ (Delete_nth intLib# SlideLib@) BlockLib@ (Delete_nth intLib# BlockLib@) );setq (setq Rep# 0 Ins# nil) (foreach Item TitleLib@ (if (> (strcase (nth 0 GetReturn@)) (strcase (nth Rep# TitleLib@)) );> (setq Ins# Rep#) );if (setq Rep# (1+ Rep#)) );foreach (if Ins# (setq Ins# (1+ Ins#)) );if (if (not Ins#) (setq Ins# 0) );if (if (= Ins# (length TitleLib@)) (setq Ins# nil) );if (if Ins# (setq TitleLib@ (Insert_nth Ins# (nth 0 GetReturn@) TitleLib@) SlideLib@ (Insert_nth Ins# (nth 1 GetReturn@) SlideLib@) BlockLib@ (Insert_nth Ins# (nth 2 GetReturn@) BlockLib@) );setq (setq TitleLib@ (append TitleLib@ (list (nth 0 GetReturn@))) SlideLib@ (append SlideLib@ (list (nth 1 GetReturn@))) BlockLib@ (append BlockLib@ (list (nth 2 GetReturn@))) );setq );if );progn );if );if (Sel_Lib_dat: TitleLib@ SlideLib@ BlockLib@) (c:Sel_Lib) );progn (c:Sel_Lib) );if );progn );if );if (if (= Pick# 3);select (Blk_Lib (nth intLib# TitleLib@) (nth intLib# SlideLib@) (nth intLib# BlockLib@) );Blk_Lib