Bad argument type error on code

Bad argument type error on code

atrotto
Enthusiast Enthusiast
645 Views
3 Replies
Message 1 of 4

Bad argument type error on code

atrotto
Enthusiast
Enthusiast

Hello, I keep getting a "error: bad argument type: numberp: OS" error when I run this code, specifically after I select the object, which I assume is because the error happens when os is called upon with the two mapcar functions. I've previously made functions using this exact format using real numbers in the place of the os variable, so I am unsure how setting os as real would make this any different. 

(defun c:OffsetBX (/ os eName mn mx mno mxo)
  (vl-load-com)
  (setq os (getreal "\nOffset Amount: "))
  (if (setq eName (car (entsel "\n  >>  Select Object  >> ")))
    (progn
      (vla-getboundingbox (vlax-ename->vla-object eName) 'mn 'mx)
      (vl-cmdf "._rectang"
	       (mapcar '- (vlax-safearray->list mn) '( os os))
	       (mapcar '+ (vlax-safearray->list mx) '( os os)))
    )
  )
  (princ)
  )

 Thanks in advance for your help. 

Accepted solutions (1)
646 Views
3 Replies
Replies (3)
Message 2 of 4

rkmcswain
Mentor
Mentor

Did you view the Error trace? It will drill you down to the offending line.

 

rkmcswain_0-1705350877154.png

 

 

 

R.K. McSwain     | CADpanacea | on twitter
Message 3 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

Maybe not the only issue, but the one that jumps out to me:

A "quoted list" [read about the (list) function and the (quote) function in the AutoLisp Reference] such as your

  '( os os)

cannot contain anything requiring evaluation.  Since the os variable must be evaluated to use its value, you must do this instead:

  (list os os)

Kent Cooper, AIA
Message 4 of 4

atrotto
Enthusiast
Enthusiast

I had eagerly implemented the quoted list when I had heard about it but forgot that caveat now that I'm coming back around to it. Thanks for the reminder!

0 Likes