@Anonymous wrote:
Steps that lisp will do
1- Asking for starting number for MNH
2- Asking for the name of the pipe Line name (examples: K , K-1 , K-1-22)
3- Clicking on the line so the lisp will draw a block with MNH-# and MNH-#+1 at the ends of the line and putting the Line name in the middle
4- after that just clicking on the lines and the sequence will repeat
Most of the issues encountered with the OG lisp are the following
- Layers does not exists
- Blocks does not exists
- Missed selection
- Insertion scale / INSUNITS
- System variable ATTREQ and/or ATTDIA.
Here's what I did:
I'm guessing the first selection is a Manhole Block and the suceeding selections are LINES. [ modified the code to also accept a block for selection.
When any of these blocks are not found, the program will terminate
(tblsearch "BLOCK" "LINE NAME")
(tblsearch "BLOCK" "MANH")
Added the option to add the layers if it does not exist [ You can change this to suit your requirement ]
Note: I did not include the option for linetype.
(foreach itm '(("SEWER NAME" 4)("S-LINE" 220) ("Sewer_Manh" 7))
(if (not (tblsearch "Layer" (Car itm)))
(entmake (append
(list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
)
(mapcar '(lambda (a b)
(cons a b)) '(2 62) itm))
)
)
)
Here's the modified code
(Defun C:mnum ( / rtd Base poi1 sel poi poi1 ang ent)
(defun rtd (a) (/ (* a 180.0) pi))
(setvar 'Attreq 1)
(setvar 'Attdia 0)
(setvar 'Insunits 6);<-- just an observation
(foreach itm '(("SEWER NAME" 4)("S-LINE" 220) ("Sewer_Manh" 7))
(if (not (tblsearch "Layer" (Car itm)))
(entmake (append
(list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 70 0)
)
(mapcar '(lambda (a b)
(cons a b)) '(2 62) itm))
)
)
)
(or MHNumber (setq MHNumber 0))
(or SNDef (setq SNDef "K"))
(setq MHNumber (cond
((getint (strcat "\nValue to start with"
(if MHNumber
(strcat " <" (itoa MHNumber) ">: ") ": " ))))
(MHNumber))
)
(if
(and
(tblsearch "BLOCK" "LINE NAME")
(tblsearch "BLOCK" "MANH")
(Setq Base (entsel "\nSelect Select first Manhole"))
(Setq poi1 (cdr (assoc 10 (setq ent (entget (car Base))))))
(setq SNDef (getstring (strcat "\nSewer Name ["
(cond (SPName) ("K")) "]: ")) SPName
(cond ((/= SNDef "") (strcase SNDef)) (SPName) ("K"))
)
)
(while
(progn
(setvar 'errno 0)
(setq sel (entsel "\nSelect Sewer Line: " ))
(cond
( (= 7 (getvar 'errno))
(princ "\nMissed, try again.")
)
( (= 'ename (type (car sel)))
(if (not (wcmatch (cdr (assoc 0 (setq ent (entget (car sel))))) "LINE,INSERT"))
(princ "\nInvalid Object Selected.")
(progn
(setq poi (cdr (assoc 10 ent)))
(setq ang (angle poi1 poi)
ang (if (and (> ang (/ pi 2)) (<= ang (* pi 1.5))
) (+ ang pi) ang ))
(setvar 'clayer "Sewer_Manh")
(command "-insert" "MANH" "non" poi "" "" "non" (rtd ang) (strcat "MH" (rtos MHNumber 2 0)))
(setvar 'clayer "S-LINE")
(command "line" "non" poi "non" poi1 "")
(setvar 'clayer "SEWER NAME")
(command "-insert" "LINE NAME"
(list (/ (+ (car poi) (car poi1)) 2)
(/ (+ (cadr poi) (cadr poi1)) 2)
) "" "" (rtd ang) SPName )
(setq poi1 poi MHNumber (1+ MHNumber))
(princ (strcat "\nNext Number is: " (itoa MHNumber)))
)
)
)
)
)
)
)(princ)
)
HTH