And I'm not smart enough to figure out why. This program calculates the slope of a line by dividing the difference of 2 elevations by the user input polyline length.
It's erroring out when prompting to:
Pick right point of slope:
Error: bad argument type: stringp nil
Any ideas?
(defun c:slo (/ osm ent1 ent2 str1 str2 len pt1 pt2 txt angl)
;;;Error function
(defun *error* (msg)
(princ "\nError: ")
(princ msg)
(princ)
(gc)
(princ)
)
;;;A rewrite of the entsel function.
(defun ent_sel (msg / ent)
(while (not ent)
(cond ((setq ent (entsel msg)))
((= (getvar "ErrNo") 7)
(princ "\nSelection missed. Please try again.")
)
((= (getvar "ErrNo") 52) (exit))
)
)
ent
)
;;;dTests the supplied argument to see if it is a Text object.
(defun etest (ent)
(if (wcmatch (cdr (assoc 0 ent)) "*TEXT")
ent
)
)
;;;Returns the length of the supplied polyline.
(defun get_length (ent / obj)
(setq obj (vlax-ename->vla-object ent))
(vlax-curve-getDistAtParam obj (vlax-curve-getendparam obj))
)
;;;A math function.
(defun txts (s1 s2 d1) (* (/ (- (atof s1) (atof s2)) d1) 100))
;;;Another Math Function
(defun rtd (radians) (* 180.0 (/ radians pi)))
;;;Main Program.
(and
(setq osm (getvar "OSMODE"))
(while (not ent1)
(setq
ent1 (getreal
"\nEnter the Upper Elevation <Hit Enter to select>:"
)
)
(if (not ent1)
(and (setq ent1 (ent_sel "\nSelect the Upper Elevation: "))
(setq ent1 (etest (entget (car ent1))))
)
(setq str1 (rtos ent1 2 2))
)
)
(while (not ent2)
(setq
ent2 (getreal
"\nEnter the Lower Elevation <Hit Enter to select>:"
)
)
(if (not ent2)
(and (setq ent2 (ent_sel "\nSelect the Lower Elevation: "))
(setq ent2 (etest (entget (car ent2))))
)
(setq str2 (rtos ent2 2 2))
)
)
(if (and (not str1) (not str2))
(mapcar 'set
'(str1 str2)
(mapcar '(lambda (x) (cdr (assoc 1 x))) (list ent1 ent2))
)
)
(setvar "OSMODE" 545)
)
(command "-layer" "m" "D-SWM-P-SLOPE_LINES" "")
(prompt "\nPick points: ")
(command "_.pline")
(while (> (getvar "CMDACTIVE") 0) (command pause))
(and
(setq len (get_length (entlast)))
(not (initget 1))
(setq pt1 (getpoint "\nPick left point of slope:"))
(not (initget 1))
(setq pt2 (getpoint pt1 "\nPick right point of slope:"))
(setq txt (txts str1 str2 len))
(setq angl (rtd (angle pt1 pt2)))
(not (prompt "\nSelect insertion point of slope text: "))
(not
(if
(> (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))) 0)
(command "_text"
"j"
"bc"
pause
angl
(strcat (rtos txt 2 2) "%")
)
(command "_text"
"j"
"bc"
pause
""
angl
(strcat (rtos txt 2 2) "%")
)
)
)
)
(setvar "osmode" osm)
(princ)
)