Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

bad argument type: consp

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Ethan_Gale
3606 Views, 3 Replies

bad argument type: consp

Hello All,

Getting an error; bad argument type: consp TWLIST

 

what Lee Mac's website is telling me is...

 

" function requiring a list argument has been passed an argument of incorrect data type with the value noted in the error message. Can be generated by passing any of the c..r functions, foreach, member, nth, or vl-sort-i functions an invalid list argument."

 

So I am led to believe that I am trying to input elements into the list above which are not of the right type.

I am new to trying to create a list of lists (ie, points of (x,y) coordinates) so this is probably my problem.

 

Note that I have commented in a section labeled "ATTENTION ATTENTION" for where I believe my code is going bad.

 

Thank you all for your time.

 

(vl-load-com);load activeX functionality

;*****Start of intersections function*****

;; Intersections  -  Lee Mac
;; Returns a list of all points of intersection between two objects
;; for the given intersection mode.
;; ob1,ob2 - [vla] VLA-Objects
;;     mod - [int] acextendoption enum of intersectwith method


(defun LM:intersections ( ob1 ob2 mod / lst rtn )
  (if (and (vlax-method-applicable-p ob1 'intersectwith)
           (vlax-method-applicable-p ob2 'intersectwith)
           (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
           )
    (repeat (/ (length lst) 3)
      (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
            lst (cdddr lst)
            )
      )
    )
  (reverse rtn)
  )

;*****Start of honum function*****

;;honum
;;Creates offset of polylines based on ratio of distance between vertices of each polyline.
;;

(defun c:honum (/ oldsnap oldortho oldlayer twpoly bwpoly toeslope denom inc twxval twyval twlist twminxval twmaxxval linexval pntlist point1 point2 currentline twintsxpnt bwintsxpnt dist extydist finalpoint bwxval bwyval bwlist bwminxval bwmaxxval) ; all local variables
  
  ;Save System Variables
  (setq oldsnap (getvar "osmode")) ;save snap settings
  (setq oldortho (getvar "orthomode")) ;save orthomode settings
  (setq oldlayer (getvar "clayer")) ;save layer
  
  ;Turn System Variables Off
  (setvar "osmode" 0)
  (setvar "orthomode" 0)
  (command "-LAYER" "MAKE" "CONSTRUCT" "");set layer to construct or creates
  
 ;*****User Input Section*****
  
  ;Set Polylines
  (setq twpoly (vlax-ename->vla-object (car (entsel "\nPlese select Top of Wall Polyline: "))));Selects TOW polyline and converts to vlax object
  (setq bwpoly (vlax-ename->vla-object (car (entsel "\nPlese select Bottom of Wall Polyline: "))));Selects BOW polyline and converts to vlax object
 
  ;Indicate toeslope geometry
	(prompt "\nWhat is the toeslope geometry?")
	(initget 1 "2H:1V 3H:1V Horizontal Abutment")
	(setq toeslope (getkword "\n[2h:1v/3h:1v/Horizontal/Abutment]: "))
	(prompt "\nYou chose ")
	(prompt toeslope)
	;set denominator value from geometry
	(cond	((= toeslope "2H:1V") (setq denom 7))
			((= toeslope "3H:1V") (setq denom 10))
			((= toeslope "Horizontal") (setq denom 20))
			((= toeslope "Abutment") (setq denom 10))
			(t (princ))
	)
  
 ;*****Top of Wall Polyline Section*****
  ;get twpoly points
  (setq inc 0) ;set increment to 0
;ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION (while (<= inc (vlax-curve-getEndParam twpoly)) ;progress through number of vertices (setq twxval (car (vlax-curve-getPointAtParam twpoly inc))) ;get x coordinate of currrent polyline vertex (setq twyval (cadr (vlax-curve-getPointAtParam twpoly inc))) ;get y coordinate of current polyline vertex (setq twlist (list 'twlist '(twxval twyval))) ;creates list of point lists I BELIEVE THIS IS WHERE THE ERROR IS HAPPENING ;ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION ;increase increment for next polyline point (setq inc (1+ inc)) ) (setq twminxval (caar twlist)) ;first x-value value of twlist (setq twmaxxval (car (last twlist))) ;last x-value of twlist (setq linexval twminxval) (setq pntlist nil) ;instantiates a point list (setq inc 0) ;creates inc to 0 (while (< linexval twmaxxval) ;progress through number of ranges (setq point1 (list linexval twyval 0.0)) ;set initial point at linexval for x value and yval from above...should be yvalue of last vertex in polyline (setq point2 (list linexval (- twyval 0.01) 0.0)) ;set final point at linexval for x value and a small distance down from yval (command "LINE" point1 point2 "");draw intersection line (setq currentline (entlast));set last drawn line to currentline (setq twintsxpnt (LM:intersections twpoly (vlax-ename->vla-object currentline) acExtendOtherEntity)) ;above sets currentline to VLA object, finds the intersection if currentline is extended to twpoly and returns that point (setq bwintsxpnt (LM:intersections bwpoly (currentline) acExtendOtherEntity)) ;currentline already VBA object, finds the intersection if currentline is extended to bwpoly and returns that point (command "ERASE" currentline "");erases intersection line (setq dist (distance twintsxpnt bwintsxpnt));distance between tw and bw at current x value (setq extydist (+ (/ dist denom) dist));extended y distance after ratio added (setq finalpoint '((car twintsxpnt) (- (cdr twintsxpnt) extydist)));gets x-val of tw point and y-val of twpoint minus extydist, adds them to a list, and sets to finalpoint (setq pntlist (append pntlist finalpoint));adds finalpoint to pntlist (setq linexval (+ linexval space));add space to linexval and then go to while loop );end while ;*****Bottom of Wall Polyline Section***** ;get bwpoly points (setq inc 0) ;set increment to 0 (while (<= inc (vlax-curve-getEndParam bwpoly)) ;progress through number of vertices (setq bwxval (car (vlax-curve-getPointAtParam bwpoly inc))) ;get x value of polyline vertex (setq bwyval (cadr (vlax-curve-getPointAtParam bwpoly inc))) ;get y value of polyline vertex (setq bwlist (append bwlist '(bwxval bwyval))) ;creates list of point lists ;increase increment for next polyline point (setq inc (1+ inc)) ) (setq bwminxval (caar bwlist)) ;first x-value value of twlist (setq bwmaxxval (car (last bwlist))) ;last x-value of twlist (setq linexval bwminxval) (setq inc 0) ;creates inc to 0 (while (< linexval bwmaxxval) ;progress through number of ranges (setq point1 (list linexval bwyval 0.0)) ;set initial point at linexval for x value and yval from above...should be yvalue of last vertex in polyline (setq point2 (list linexval (- bwyval 0.01) 0.0)) ;set final point at linexval for x value and a small distance down from yval (command "LINE" point1 point2 "");draw intersection line (setq currentline (entlast));set last drawn line to currentline (setq twintsxpnt (LM:intersections twpoly (vlax-ename->vla-object currentline) acExtendOtherEntity)) ;above sets currentline to VLA object, finds the intersection if currentline is extended to twpoly and returns that point (setq bwintsxpnt (LM:intersections bwpoly (currentline) acExtendOtherEntity)) ;currentline already VBA object, finds the intersection if currentline is extended to bwpoly and returns that point (command "ERASE" currentline "");erases intersection line (setq dist (distance twintsxpnt bwintsxpnt));distance between tw and bw at current x value (setq extydist (+ (/ dist denom) dist));extended y distance after ratio added (setq finalpoint '((car twintsxpnt) (- (cdr twintsxpnt) extydist)));gets x-val of tw point and y-val of twpoint minus extydist, adds them to a list, and sets to finalpoint (setq pntlist (append pntlist finalpoint));adds finalpoint to pntlist... pntlist should list all TOW Extension points followed by BOW Extension points, thus not sorted (setq linexval (+ linexval space));add space to linexval and then go to while loop );end while ;*****Draw final polyline section***** (vl-sort pntlist (function (lambda (e1 e2) (< (caar e1) (caar e2))))) ;sorts point list by x-values and discards any similiar points....BUT I DONT KNOW HOW IT WORKS (setq inc 0) (command "PLINE") ;begin PLINE command (repeat (- (length pntlist) 1) ;repeast for one less time than the length of pntlist (setq inc (+ inc 1)) ;increase increment by one (setq p1 (nth (- inc 1) pntlist)) ;set p1 to previous increment point (setq p2 (nth inc pntlist)) ;set p2 to current increment point (command p1 p2) ;indicating points in command line for PLINE command );end repeat (command "") ;finishe PLINE command ;Restore System Variables (setvar "osmode" oldsnap) (setvar "orthomode" oldortho) (setvar "clayer" oldlayer) (princ);print cleanly );end of definition
3 REPLIES 3
Message 2 of 4
ВeekeeCZ
in reply to: Ethan_Gale

When building a list always use this, NOTHING else:

(setq lst (cons itm lst))

It creates a reversed list. Get used to it. It's fundamental!!!

Message 3 of 4
ВeekeeCZ
in reply to: Ethan_Gale

And told you last time something about this:

 

'(twxval twyval)

 

The same error here:

(setq finalpoint '((car twintsxpnt) (- (cdr twintsxpnt) extydist)))

 

Also the same as last time.

(currentline)
Message 4 of 4
dlanorh
in reply to: Ethan_Gale

(setq twlist (list 'twlist '(twxval twyval)))

This is the offending line.

 

'twlist ==> twlist

'(twxval twyval) ==> (twxval twyval)

 

the quote means literal

twlist is not initialised. It doesn't need to be, but it is prudent so somewhere you will need to

 

(setq twlist nil) or (setq twlist '())

 

Then try

 

(setq twlist (cons (list twxval twyval) twlist))

and after the while has finished you will need to

 

(setq twlist (reverse twlist))

to set the list into the order it was constructed

I am not one of the robots you're looking for

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report