Jump to content

Help to correct autolisp program


fathihvac

Recommended Posts

Hello,

I am working on a lisp that calculates square and round ductwork weight but i got error:

bad argument type: stringp nil.

Please help

KG.LSP

Edited by fathihvac
Link to comment
Share on other sites

bad argument type: stringp nil means that a string argument was expected but not received. Take a look at the following areas in your code:

 

In your first condition statement near the top of (C:KG), you assign a string to the variable diameter when the length of your text equals 4 characters (but you don't assign anything to variables a and b). When the length equals 7 or 8 characters, you assign portions of the string to variables a and b (but you don't assign anything to diameter). After you exit the cond statement, you call the atoi function on a and again on b, and call atof on diameter. Both atof and atoi expect a string argument, so if you're passing nil to either of these, you will see an error.

 

BTW, near the end of (C:KG), you calculate the weight, convert it to a string, and assign it to a variable weights. Later, in the "TEXT" command call, you supply a variable poids where (I think) you probably intended to pass weights(?).

 

Hope this helps,

Tom

Link to comment
Share on other sites

Thank very much.

I think i found the fault:

How to extract real number from the following text representing duct diameter example Ø300,Ø450 ...so reals are 300,450..

Link to comment
Share on other sites

can you provide the pattern for the selected text string.

 

((eq dimcar 4 )

((eq dimcar 7 )

((eq dimcar 8 )

 

Ø300 is 6 characters in this case... (atoi (substr txt 4)) would be sufficient to give you an Integer or (distof (substr txt 4) 2) for real, where txt is the variable of the selected string.

 

subsequently you can filter the selection with (setq ss (ssget '((0 . "*TEXT")(1 . "%%C*,*-*")))) or whatever symbol you use , that is if the target strings all contains the "Ø" or "-" symbol

 

and judging by the conditions you gave

4 would be Øxxx where string length is actually 6 counting Ø as 3 rather than 1

7 would be xxx-xxx

8 would be xxxx-xxx

 

Also with by using the appropriate function you can derived the Total Length of the entities listed on your cond

(cond
  ((= et "LINE") (tlines))
  ((= et "ARC") (tarcs))
  ((= et "LWPOLYLINE") (tplines))
  ((= et "POLYLINE") (tplines))
  ((= et "SPLINE") (tsplines))

 

using just one function

 
(vlax-curve-getDistAtParam
     (setq ob (vlax-ename->vla-object (car (entsel))))
     (vlax-curve-getEndParam ob)
     )

you can eliminate all the extra codes you have in there (tplines/tarcs/....)

 

would you mind giving us more info..... :)

Edited by pBe
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...