Author Topic: Bad argument type: numberp: nil  (Read 5050 times)

0 Members and 1 Guest are viewing this topic.

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Bad argument type: numberp: nil
« on: September 13, 2005, 06:04:33 PM »
I'm trying use this code to select text that has a number value, extract the text contents, and make calculations based on that.  
Code: [Select]
 (setq ent (entget (car (entsel "\nSELECT text: ")))
contents (cdr (assoc 1 ent))
8percent (rtos (* contents 0.08) 2 1)
);setq

But I keep getting [; error: bad argument type: numberp: nil]

I've done (type contents) and it comes back as STR, so RTOS should work, in my mind, anyway...

Does RTOS need to go in when I'm extracting assoc code 1 instead of during the calculation?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Bad argument type: numberp: nil
« Reply #1 on: September 13, 2005, 06:06:55 PM »
Read up on distof, then consider this --

Code: [Select]
(defun MyDistOf ( string )
    ;;  returns numeric value or nil
    (cond
        ((/= 'str (type string)) nil)
        ((distof string 2))
        ((distof string 3))
        ((distof string 5))
        ((distof string 1))
    )
)
« Last Edit: September 13, 2005, 06:12:15 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Bad argument type: numberp: nil
« Reply #2 on: September 13, 2005, 06:11:35 PM »
Read up on distof.

Fantastic!  Thank you very much! :mrgreen:

Finished code:
Code: [Select]
(setq ent (entget (car (entsel "\nSELECT text: ")))
      contents (cdr (assoc 1 ent))
      contents (distof contents 2)
      8percent (rtos (* contents 0.08) 2 1)
      );setq
« Last Edit: September 13, 2005, 06:13:17 PM by Dommy2Hotty »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Bad argument type: numberp: nil
« Reply #3 on: September 13, 2005, 06:14:32 PM »
My pleasure.

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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Bad argument type: numberp: nil
« Reply #4 on: September 13, 2005, 06:26:23 PM »
Just for fun ...

Code: [Select]
(defun MyDistOf ( string / result )
    (if (eq 'str (type string))
        (vl-some
           '(lambda (mode)
                (setq result
                    (distof
                        string
                        mode
                    )
                )
            )
           '(2 3 5 4 1)
        )
    )   
    result
)
« Last Edit: September 13, 2005, 06:28:10 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Bad argument type: numberp: nil
« Reply #5 on: September 14, 2005, 09:23:37 AM »
Actually ... I shouldn't test that the argument passed is a string; iow, if passed anything but a string it should promptly crash. Thus:

Code: [Select]
(defun MyDistOf ( string / result )
    (vl-some
       '(lambda (mode)
            (setq result
                (distof
                    string
                    mode
                )
            )
        )
       '(2 3 5 4 1)
    )
    result
)

Or ...

Code: [Select]
(defun MyDistOf ( string )
    (cond
        ((distof string 2))
        ((distof string 3))
        ((distof string 5))
        ((distof string 4))
        ((distof string 1))
    )
)

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

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Bad argument type: numberp: nil
« Reply #6 on: September 14, 2005, 09:52:26 AM »
 :? :-o :?