Author Topic: My slope routine stopped working  (Read 2400 times)

0 Members and 1 Guest are viewing this topic.

NoTebowNoHope

  • Guest
My slope routine stopped working
« on: January 10, 2012, 05:09:04 PM »
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?

Code: [Select]
(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)
)

fixo

  • Guest
Re: My slope routine stopped working
« Reply #1 on: January 10, 2012, 05:18:14 PM »
Change :
Code: [Select]
(defun c:slo (/ osm ent1 ent2 str1 str2 len pt1 pt2 txt angl)on:
Code: [Select]
(defun c:slo (/ *error* osm ent1 ent2 str1 str2 len pt1 pt2 txt angl)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: My slope routine stopped working
« Reply #2 on: January 10, 2012, 05:28:34 PM »
Maybe my tutorial will help you determine the source of the error.  :-)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: My slope routine stopped working
« Reply #3 on: January 10, 2012, 06:11:01 PM »
ib4 "cancel this thread, I don't need this or you!!!!!"

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

NoTebowNoHope

  • Guest
Re: My slope routine stopped working
« Reply #4 on: January 10, 2012, 09:45:11 PM »
I might learn something afterall. Thanks for the links and suggestions. :lol:

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: My slope routine stopped working
« Reply #5 on: January 11, 2012, 07:00:53 AM »
ib4 "cancel this thread, I don't need this or you!!!!!"



 :-D