This is simply a post for learning purposes, I'm just looking for better methods of completing the tasks within this routine.
I know that the way I wrote it just works and "just works" is not good enough for me.
I want it to run faster and more efficient and I'm sure this is the place to get all the tips and tricks and advancements for this routine that I need.
This could be a great thread for not only me but for anyone else who is in the somewhat of a beginner phase of writing routines. My routine is very readable for newcomers because that's what I am, so showing how to better my routine can produce clean connections from one way of doing a task, to a more advanced way.
I appreciate any input/advice that the community provides!
(defun C:UtilitiesCOH()
(setvar "cmdecho" 0)
(setvar "expert" 3)
(setq planVar 0)
(while (= planVar 0)
(setq plan (substr (strcase (getstring "Include Plan Numbers? ((Y)es/(N)o):")) 1 1))
(cond
((= plan "Y") (setq planVar 1))
((= plan "N") (setq planVar 2))
(T (prompt "Invalid Entry\n"))
)
)
(setq tmpVar planVar)
;;Provide used layers
(if (null (tblsearch "layer" "GasUtilitiesCombo"))
(command "-layer" "make" "GasUtilitiesCombo" "color" "yellow" "" ""))
(if (null (tblsearch "layer" "GasUtilitiesStorm"))
(command "-layer" "make" "GasUtilitiesStorm" "color" "64" "" ""))
(if (null (tblsearch "layer" "GasUtilitiesSanitary"))
(command "-layer" "make" "GasUtilitiesSanitary" "color" "26" "" ""))
(if (null (tblsearch "layer" "GasUtilitiesWater"))
(command "-layer" "make" "GasUtilitiesWater" "color" "171" "" ""))
(setq sel (ssget '((0 . "LINE,*POLYLINE"))))
(repeat (setq i (sslength sel))
(setq ent (ssname sel (setq i (1- i))))
(setq startpoint (vlax-curve-getstartpoint ent))
(setq endpoint (vlax-curve-getendpoint ent))
(if (null (ade_odgetfield ent "SewerMain" "SYSTEMTYPE" 0))
(progn
(if (null (ade_odgetfield ent "TBL_WATER_MAIN" "DIAMETER" 0))
(setq od "TBL_SERVICE")
(setq od "TBL_WATER_MAIN")
)
(setq sys "Water")
(setq dia (ade_odgetfield ent od "DIAMETER" 0))
(setq planNum (strcat "(" (ade_odgetfield ent od "PLANNUMBER" 0) ")"))
)
(progn
(setq sys (ade_odgetfield ent "SewerMain" "SYSTEMTYPE" 0))
(setq dia (ade_odgetfield ent "SewerMain" "DIAMETER" 0))
(setq planNum (strcat "(" (ade_odgetfield ent "SewerMain" "MAPREF" 0) ")"))
)
)
(if (= planNum "()") (setq planNum ""))
;;get variables to usable string
(varConv)
;;set LT Definition
(setq LTdef (strcat "____" LTdia "'' " LTsys "____" LTdia "'' " LTsys "___\n"))
(if (null (tblsearch "ltype" lt))(createLT))
(changeProps)
(if (= planVar 1)
(progn
(tmaskon)
(if (/= tmpVar planVar)
(setq planVar tmpVar)
)
)
)
(if (= i 0) (setvar "expert" 0))
)
(setq text (ssget "_X" '((0 . "MTEXT"))))
(command "select" text "")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END MAIN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;BEGIN CALLOUTS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;VARIABLE CONVERSION;;;;;;;;
(defun varConv()
(setq tester (/ dia 10))
(cond
((= sys "STORM") (setq LTsys "STM"))
((= sys "SANITARY") (setq LTsys "SAN"))
((= sys "COMBINED") (setq LTsys "CMB"))
((= sys "Water") (setq LTsys "W"))
(T (prompt "unknown system type"))
)
(cond
((< tester 1) (setq LTdia (substr (rtos dia) 1 1)))
((>= tester 10) (setq LTdia (substr (rtos dia) 1 3)))
(T (setq LTdia (substr (rtos dia) 1 2)))
)
(cond
((= LTdia "0") (setq lt LTsys))
((= sys "Water") (setq lt (strcat sys LTdia "''")))
(T (setq lt (strcat LTsys LTdia "''")))
)
)
;;;;;;;LINETYPE;;;;;;;;
(defun createLT ()
(setq diaLength (strlen LTdia))
(setq sysLength (strlen LTsys))
(setq total (+ dialength syslength))
(setq bspace (atof ".1"))
(setq x (float (* (atof ".008") (+ total 3))))
(setq espace (float (* (atof ".05") (+ total 3))))
(setq LTdef (strcat "____" LTdia "'' " LTsys "____" LTdia "'' " LTsys "___\n"))
(setq LTspacing (strcat "A,4,-"(rtos bspace)",[""\"" LTdia "'' " LTsys "\",LT_FONT,X=-"(rtos x)",y=-.03,S=.08],-"(rtos espace)"\n"))
;;Filepath/name
(setq fname "C:\\Users\\Public\\TeamFishel\\Autodesk\\Google Drive\\R19.1\\Linetypes\\Custom.lin")
;;Appends written text to Custom.lin file
(setq linFile (open fname "a"))
(write-line (strcat "*" lt ", " LTdef LTspacing) linFile)
(close linFile)
(command "-linetype" "load" lt "C:\\Users\\Public\\TeamFishel\\Autodesk\\Google Drive\\R19.1\\Linetypes\\Custom" "")
)
;;;;;;;CHANGE PROPERTIES;;;;;;;;
(defun changeProps()
(command "chprop" ent "")
(cond
((= LTsys "CMB")(command "layer" "GasUtilitiesCombo" "color" "bylayer"))
((= LTsys "SAN")(command "layer" "GasUtilitiesSanitary" "color" "bylayer"))
((= LTsys "STM")(command "layer" "GasUtilitiesStorm" "color" "bylayer"))
(T (command "layer" "GasUtilitiesWater" "color" "bylayer"))
)
(cond
((>= dia 24)
(progn
(command "")
(command "laymcur" ent)
(pipeOffset)
)
)
((> dia 0)
(progn
(command "ltype" lt "" )
(command "laymcur" ent)
(if (= planVar 1)
(command "mtext" "m2p" startpoint endpoint "j" "ml" "s" "ROMANS" "h" "1.3" "l" "" "2.1667"
"r" endpoint "w" "0" planNum "")
)
)
)
(T
(progn
(command "ltype" LTsys "" )
(command "laymcur" ent)
(if (= planVar 1)
(command "mtext" "m2p" startpoint endpoint "j" "ml" "s" "ROMANS" "h" "1.3" "l" "" "2.1667"
"r" endpoint "w" "0" planNum "")
)
)
)
)
)
;;;;;;;LINE OFFSET;;;;;;;;
(defun pipeOffset()
(setq ofd (float (/ (/ dia 12.00) 2.00)))
(if (setq ss (ssget "p"))
(repeat (sslength ss)
(setq ent (vlax-ename->vla-object (ssname ss 0)))
(if (vlax-method-applicable-p ent 'Offset)
(mapcar '(lambda (o)
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-offset (list ent o))))(list ofd (- ofd)))
)
(ssdel (ssname ss 0) ss)
)
)
(princ)
(command "chprop" "p" "" "ltype" lt "layer" "Defpoints" "")
(if (= planVar 1)
(command "mtext" "m2p" startpoint endpoint "j" "ml" "s" "ROMANS" "h" "1.3" "l" "" "2.1667"
"r" endpoint "w" "0" (strcat LTdia "'' " LTsys " " planNum) "")
(command "mtext" "m2p" startpoint endpoint "j" "ml" "s" "ROMANS" "h" "1.3" "l" "" "2.1667"
"r" endpoint "w" "0" (strcat LTdia "'' " LTsys) "")
)
(setq planVar 1)
)
(defun TMaskOn ()
(vl-load-com)
(setq s (ssget "_L" '((0 . "MTEXT"))))
(if s
(mapcar '(lambda (x)
(setq ob1 (vlax-ename->vla-object x))
(if (= (vla-get-backgroundfill ob1) :vlax-false)
(vla-put-backgroundfill ob1 :vlax-true)
)
)
(vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
)
)
(prin1)
)