Input values are getting "error: bad argument type: consp"

Input values are getting "error: bad argument type: consp"

AnthonyVitullo
Observer Observer
484 Views
10 Replies
Message 1 of 11

Input values are getting "error: bad argument type: consp"

AnthonyVitullo
Observer
Observer

Hopefully someone can help me with this issue. I haven't written a LISP program in 30 years, so I may be overlooking something obvious.  Please refer to the attached files. This is a simple program, but instead of looking like Fig. 2, I get Fig. 1 (with two lines drawn vertically on top of each other.)

 

I believe it is due to an error with my user inputs values.
When I check my user input values [USING: (CAR SR)], all of the values are numerically correct, but I get
"error: bad argument type: consp" for all three of my GETREAL inputted variables (SR. LR, AN).
The SP input variable using GETPOINT is fine.

 

If anyone can help me fix this I would really appreciate it.

If you have any thoughts on getting the lines trimmed as in Fig 3., I would be really happy!
Thanks,
Anthony

 

0 Likes
485 Views
10 Replies
Replies (10)
Message 2 of 11

paullimapa
Mentor
Mentor

You can do a lot of testing & see what AutoCAD returns by copy & pasting each line of code to the command line like this:

When you use getreal function you'll get a real number in return:

paullimapa_2-1752773040634.png

You cannot use car function since it's not a list.

But when you use getpoint function you'll get a list in return with 3 real numbers representing x, y & z coordinates:

paullimapa_3-1752773101745.png

Now you can use the car function to get the first item in the list:

paullimapa_4-1752773173582.png

My suggestion instead of using getreal function to get radius is to use getdist function which offers you the option to pick points on the drawing area and enter a number:

paullimapa_7-1752773397257.png

Now as to why both Lines are drawn with the same endpoints on the outer Circle:

paullimapa_8-1752773451060.png

your code uses the same to get both endpoints EPR & EPL:

paullimapa_9-1752773591559.png

So you'll need to request another value like perhaps an angle between the 2 Lines.

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 11

Kent1Cooper
Consultant
Consultant

You may be able to just  1.  change one of the ARRD's to ALRD in setting the endpoints for the Lines, AND  2.  ensure you at least don't have QUAdrant mode running in Object Snap, which could be why your Lines are coming out vertical.  [The same-code problem that @paullimapa pointed out should have them both at the same angle, but not vertical.]  Preferably, turn off Osnap altogether.

I would also suggest you use (getangle) for the shroud angle, because you can type in a value in degrees but the returned value will be already in radians, so no conversion is needed.

Kent Cooper, AIA
0 Likes
Message 4 of 11

Kent1Cooper
Consultant
Consultant

Looked like an interesting challenge, so I tried modifying your code, incorporating the various suggestions and some other efficiencies, like setting System Variables directly instead of using (command) functions to do it, consolidating multiple variable settings into one (setq) function, etc., to draw the shape directly.  Very limited testing, but it seems to work.

(defun C:SHD (/ SR LR AN SP AO AR AL OL OS PW LT)
  (setq
    SR (getdist "\nSMALL RADIUS:")
    LR (getdist "\nLARGE RADIUS:")
    AN (getangle "\nSHROUD ANGLE:")
    SP (getpoint "\nCENTER POINT: ")
    AO (/ (- (* pi 2) AN) 2)
    AR (- (/ pi 2) AO) 
    AL (+ (/ pi 2) AO)
    OL (getvar 'clayer)
    OS (getvar 'osmode)
    PW (getvar 'plinewid)
    LT (getvar 'celtype)
  ); setq
  (setvar 'clayer "0")
  (setvar 'osmode 0)
  (setvar 'plinewid 0)
  (setvar 'celtype "CONTINUOUS")
  (command "_.pline"
    (polar SP AR SR)
    "_arc" "_second" (polar SP (* pi 1.5) SR) (polar SP AL SR)
    "_line" (polar SP AL LR)
    "_arc" "_second" (polar SP (* pi 1.5) LR) (polar SP AR LR)
    "_line" "_close"
  ); command
  (setvar 'clayer OL)
  (setvar 'osmode OS)
  (setvar 'plinewid PW)
  (setvar 'celtype LT)
  (prompt "Shroud has been drawn.")
  (prin1)
 )

Kent1Cooper_1-1752780492407.png

I don't know how you work with linetypes, but if Layer 0's linetype is Continuous [as I suspect it would be for most Users], I would go for setting CELTYPE to BYLAYER instead.

It could also benefit from adding *error* handling to ensure resetting those System Variables if something goes wrong.

[Actually, it doesn't need the Large and Small Radii to be in that relationship -- it still works if the so-called Large one given is smaller than the Small one.  It could be made to verify that Large is larger than Small, if it matters.]

EDIT:  It could also be made to remember your values and offer them as defaults on subsequent use, if you ever do more than one of these but keeping any of the same values.

Kent Cooper, AIA
Message 5 of 11

scot-65
Advisor
Advisor

@AnthonyVitullo 

 

scot65_1-1752787505490.png

 

1. Gather user input.

2. TEST user input.

3. Execute.

 

;1. Gather user input.
(if (and
     (setq SR (getreal "\nSMALL RADIUS:"))
     (setq LR (getreal "\nLARGE RADIUS:"))
     (setq AN (getreal "\nSHROUD ANGLE:"))
     (setq SP (getpoint "\nCENTER POINT: "))
    );and
 (progn
  ...
  ;2. Test user input here.
  ...
  ;A command is being used. Best to first turn off OSMODE.
  (if (< getvar 'OSMODE) 16384) (setvar 'OSMODE (+ (getvar 'OSMODE) 16384)));if
  ...
  ;3. Execute
  ...
  ;Execute ended. Reset OSMODE.
  (if (> (getvar 'OSMODE) 16384) (setvar 'OSMODE (- (getvar 'OSMODE) 16384)));if
  ...
 );progn
);if

 

The first 3 inputs can be made into a dialog and tested before closing dialog to specify a point.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 6 of 11

Sea-Haven
Mentor
Mentor

@Kent1Cooper maybe I am doing something wrong.  45 deg = 0.785398163397448 radians

(setq AN (getangle "\nSHROUD ANGLE:"))
SHROUD ANGLE:45
5.49778714378214

 I also tried pick 2 points approximating 45 and got similar 5.xx answer. Tried changing units to radians etc but no difference. Using Brticscad.

 

"The first 3 inputs can be made into a dialog "

 

;The dtr function converts degrees to radians
;The rtd function converts radians to degrees
(defun dtr (a)
(* pi (/ a 180.0))
)
;
(defun rtd (a)
(/ (* a 180.0) pi)
)

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm (list "Enter Values" "Small radius " 5 4 "50" "Big Radius" 5 4 "100" "Shroud angle" 5 4 "25" )))

(setq sr (atof (nth 0 ans))
  LR (atof (nth 1 ans))
  AN (dtr (atof (nth 2 ans)))
)

Save multi getvals into a support path as its auto loaded. Can be used in any code.

SeaHaven_0-1752800101791.png

 

0 Likes
Message 7 of 11

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

@Kent1Cooper maybe I am doing something wrong.  45 deg = 0.785398163397448 radians

(setq AN (getangle "\nSHROUD ANGLE:"))
SHROUD ANGLE:45
5.49778714378214

....


It works fine for me, in both AutoCAD 2020 and 2026:

Kent1Cooper_0-1752803058838.png

And stand-alone:

Command: (getangle "\nAngle: ")
Angle: 45
0.785398

Must be a Bricscad issue.

Kent Cooper, AIA
0 Likes
Message 8 of 11

Kent1Cooper
Consultant
Consultant

@scot-65 wrote:
Kent1Cooper_1-1752803301778.png

....


Which code resulted in that message?  It's not true, at least not for my routine -- see the first two shapes in the image in Message 4, both of which have shroud angles greater than 180°.  It's not true of the (getangle) function in general, either, unless somehow LT works differently with that.

Kent Cooper, AIA
0 Likes
Message 9 of 11

Sea-Haven
Mentor
Mentor

Thanks @Kent1Cooper found the answer, but more issues. Set angbase 90, type 45 = 0.785... But pick two points and get 5.43421... etc it works the two point answer in a backward sense. For me will stick to Getreal.

0 Likes
Message 10 of 11

komondormrex
Mentor
Mentor

@AnthonyVitullo 

do not you stick to the 30-year-old milestone, move forward! check this direct shroud pline drawing.

(defun c:shrd (/ center_point radius_1 radius_2 shroud_angle right_side_angle bulge shrd_point_list shroud_pline)
  (setq center_point (getpoint "\nShroud center point: ")
      radius_1 (getdist center_point "\nRadius 1: ")
      radius_2 (getdist center_point "\nRadius 2: ")
      shroud_angle (* (getreal "\nAngle: ") (/ pi 180))
      right_side_angle (- (* 0.5 pi) (- pi (* 0.5 shroud_angle)))
      bulge (/ (sin (* 0.25 shroud_angle)) (cos (* 0.25 shroud_angle)))
      shrd_point_list (apply 'append (mapcar '(lambda (point) (mapcar '+ point '(0 0))) 
		                            (list (polar (trans center_point 1 0) right_side_angle radius_1) 
		                                  (polar (trans center_point 1 0) (- pi right_side_angle) radius_1) 
		                                  (polar (trans center_point 1 0) (- pi right_side_angle) radius_2) 
		                                  (polar (trans center_point 1 0) right_side_angle radius_2)
		                            )
                      		     )
                      )
      shroud_pline (vla-addlightweightpolyline
	                (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
	                (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 1 (length shrd_point_list)))
	                                shrd_point_list
	                )
             	   )
  )
  (vla-put-closed shroud_pline :vlax-true)
  (mapcar '(lambda (index bulge) (vla-setbulge shroud_pline index bulge)) '(0 1 2 3) (list (- bulge) 0 bulge 0))
  (vla-put-layer shroud_pline "0")
  (vla-put-linetype shroud_pline "CONTINUOUS")
  (princ)
)

  

0 Likes
Message 11 of 11

AnthonyVitullo
Observer
Observer

It is working now.

Thanks to everyone who provided input.

 

0 Likes