Jump to content

What is wrong with this code? (; error: bad argument type: stringp)


Perifanos

Recommended Posts

(defun C:Heatest()

(Princ "Define Area:")

(Command "area")

 

(while (= 1 (getvar "cmdactive"))

(command pause)

)

(setq A (getvar "area"))

(princ A)

 

)

Link to comment
Share on other sites

Firstly, please read the Code Posting Guidlines for instructions on how to format code in your posts and please edit your post as required.

 

I don't see anything in your code that would cause an error, however, there is the possibility that you have inadvertently redefined the pause symbol to something other than "\\", and you have also not declared the symbol a as a local variable (for more information on variable localisation, see my tutorial here).

 

Here is an alternative way to write your code:

(defun c:heatest ( )
   (command "_.area")
   (while (< 0 (getvar 'cmdactive))
       (command "\\")
   )
   (princ (getvar 'area))
   (princ)
)

Link to comment
Share on other sites

(defun c:heatest (/ a)
   (command "_.area")
   (while (< 0 (getvar 'cmdactive))
       (command "\\")
   )
   (princ "Area:" (getvar 'area))

)

 

 

I have just Copy/Pasted your code above, adding a string after princ.

 

I get this error: ; error: bad argument type: FILE

 

I dont know what is wrong, really.

Link to comment
Share on other sites

(defun c:heatest (/a)
  (setq a 10)
 (princ a)
 )

 

And if the previous is difficult, read this one...I get the same error...

Link to comment
Share on other sites

Man, have you tried to read about LIST function?

Just interesting to know

Here is good place I'll recommend to start from

www.afralisp.net

Try

 
 (setq a 10 b 20)
 (princ (list a b))
(terpri)
 (print (list a b))
(terpri)
 (princ (vl-princ-to-string (list a b)))

Link to comment
Share on other sites

I dont know what is wrong, really.

 

This is the source of the error:

 

I have just Copy/Pasted your code above, adding a string after princ.

 

You also removed the final call to princ for some reason.

 

The princ function accepts two optional arguments: a string to print to the command-line or to a file, and a file descriptor (if printing to file).

 

You have supplied the string "Area:" as the first argument, and (getvar 'area) as the second argument. However, (getvar 'area) is not a file descriptor as expected by princ for the second argument, hence the error.

 

To print the string "Area:" followed by the value of (getvar 'area), you will need to either convert the area value to a string using the rtos function, and then use strcat to concatenate the two strings; or use a separate princ expression to print the area value:

 

(defun c:heatest ( / a )
   (command "_.area")
   (while (< 0 (getvar 'cmdactive))
       (command "\\")
   )
   (princ (strcat "Area:" (rtos (getvar 'area))))
   (princ)
)

(defun c:heatest ( / a )
   (command "_.area")
   (while (< 0 (getvar 'cmdactive))
       (command "\\")
   )
   (princ "Area:")
   (princ (getvar 'area))
   (princ)
)

As for your other posts, I suggest that you first read the AutoLISP Documentation and visit a few AutoLISP tutorial sites to determine the cause of your errors.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...