Lisp Trouble (bad argument type for compare)

Lisp Trouble (bad argument type for compare)

Ethan_Gale
Contributor Contributor
1,833 Views
3 Replies
Message 1 of 4

Lisp Trouble (bad argument type for compare)

Ethan_Gale
Contributor
Contributor

Hey everyone,

New at writing routines, and especially new at utilizing the ActiveX extensions... so bear with me. Currently getting an "error: bad argument type for compare: XVAL XVAL" when I run the routine.

Tried to comment in my intentions with what the code is supposed to do.

Goal is to be able to insert a user-specified block at horizontal spacing along a polyline. Figured I would utilize the the Lee-Mac extension intersection code to use it.

Thanks for looking/helping.

(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 hspaceblock function*****

(defun c:hspaceblock (/ oldsnap oldortho oldlayer pol polobj space blname inc xval yval listx listy minxval maxxval linexval pntlist point1 point2 currentline intsxpnt) ; 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)
	;layer gets changed in coding below

	;Select plolyline
	(setq pol (car (entsel "\nSelect Polyline: ")))
	(setq polobj (vlax-ename->vla-object pol))
	
	
	;Set Distance
	(setq space (getint "\nPlease enter horizontal spacing: "))
	(setq blname (getstring "\nPlease enter name of block: "))
	
	

	;draw small lines at polyline points, get intersection of bottom of polyline
	(setq inc 0) ;set increment to 0
	(while (<= inc (vlax-curve-getEndParam polobj)) ;progress through number of vertices
		(setq xval (car (vlax-curve-getPointAtParam polobj inc))) ;get x value of polyline vertex
		(setq yval (cadr (vlax-curve-getPointAtParam polobj inc))) ;get y value of polyline vertex
		(setq listx (append listx '(xval))) ;add x to listx
		(setq listy (append listy '(yval))) ;add y to listy
		
		;increase increment for next polyline point
		(setq inc (1+ inc))
	)
	
	(setq minxval (car listx)) ;first value of listx
	(setq maxxval (last listx)) ;last value of listx
	(setq linexval minxval) ;set initial line x value
	(setq pntlist nil) ;instantiates a point list
	(setq inc 0) ;creates inc to 0
	
	(command "-LAYER" "SET" "CONSTRUCT" "");set layer to construct
	
	(while (< linexval maxxval) ;progress through number of ranges
		
		(setq point1 '(linexval yval)) ;set initial point at linexval for x value and yval from above...should be yvalue of last vertex in polyline
		(setq point2 '(linexval (- yval 0.01))) ;set final point at linexval for x value and a small distance down from yval
		
		(command "LINE" point1 point2);draw line
		
		(setq currentline (entlast));set last drawn line to currentline
		(setq intsxpnt (LM:intersections (polobj) (vlax-ename->vla-object currentline) acExtendOtherEntity))
		;above sets currentline to VLA object, finds the intersection if currentline is extended to polobj and returns that point
		
		(command "-INSERT" blname intsxpt "" "") ;insert user-specified block at intscpnt at 1 scale and no rotation
		
		(setq linxval (+  linxval space));add space to linexval and then go to while loop
	
	)
	
	;Restore System Variables
	(setvar "osmode" oldsnap)
	(setvar "orthomode" oldortho)
	(setvar "clayer" oldlayer)
	
	(princ);print cleanly
	
);end of definition
0 Likes
Accepted solutions (1)
1,834 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution

Issues: 

- ones you have a variable, you cannot just quote that '(variable). The variable has to be evaluated. You need to use (list) or (cons)

- you have too many typos in the code: linxval vs linexval, intsxpnt vs intspt...

- line command is wrong. Its line pt1 pt2 <finish>.

- Lees routine returns a list of points - list of lists - you need to take the first one even if there is just one point in a list.

- (polobj) Since polobj is just a variable, don't use ()

- your code fails if no such layer is in the drawing. better to use the "Make" option which makes the layer current OR create it.

 

Here it is fixed:

(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 hspaceblock function*****

(defun c:hspaceblock (/ oldsnap oldortho oldlayer pol polobj space blname inc xval yval listx listy minxval maxxval linexval pntlist point1 point2 currentline intsxpnt) ; 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)
  ;layer gets changed in coding below
  
  ;Select plolyline
  (setq pol (car (entsel "\nSelect Polyline: ")))
  (setq polobj (vlax-ename->vla-object pol))
  
  
  ;Set Distance
  (setq space (getint "\nPlease enter horizontal spacing: "))
  (setq blname (getstring "\nPlease enter name of block: "))
  
  
  
  ;draw small lines at polyline points, get intersection of bottom of polyline
  (setq inc 0) ;set increment to 0
  (while (<= inc (vlax-curve-getEndParam polobj)) ;progress through number of vertices
    (setq xval (car (vlax-curve-getPointAtParam polobj inc))) ;get x value of polyline vertex
    (setq yval (cadr (vlax-curve-getPointAtParam polobj inc))) ;get y value of polyline vertex
    (setq listx (append listx (list xval))) ;add x to listx
    (setq listy (append listy (list yval))) ;add y to listy
    
    ;increase increment for next polyline point
    (setq inc (1+ inc))
    )
  
  (setq minxval (car listx)) ;first value of listx
  (setq maxxval (last listx)) ;last value of listx
  (setq linexval minxval) ;set initial line x value
  (setq pntlist nil) ;instantiates a point list
  (setq inc 0) ;creates inc to 0
  
  (command "-LAYER" "MAke" "CONSTRUCT" "");set layer to construct
  
  (while (< linexval maxxval) ;progress through number of ranges
    
    (setq point1 (list linexval yval 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 (- yval 0.01) 0.)) ;set final point at linexval for x value and a small distance down from yval
    
    (command "LINE" "_non" point1 "_non" point2 "");draw line
    
    (setq currentline (entlast));set last drawn line to currentline
    (setq intsxpnt (LM:intersections polobj (vlax-ename->vla-object currentline) acExtendOtherEntity))
    ;above sets currentline to VLA object, finds the intersection if currentline is extended to polobj and returns that point

    (if intsxpnt
      (command "-INSERT" blname "_s" 1 "_r" 0 "_non" (car intsxpnt))) ;insert user-specified block at intscpnt at 1 scale and no rotation
    
    (setq linexval (+  linexval space));add space to linexval and then go to while loop
    
    )
  
  ;Restore System Variables
  (setvar "osmode" oldsnap)
  (setvar "orthomode" oldortho)
  (setvar "clayer" oldlayer)
  
  (princ);print cleanly
  
  );end of definition

 

0 Likes
Message 3 of 4

Ethan_Gale
Contributor
Contributor

Thank you so much for the help! It is working great now.

I do have a question regarding why you used:

(if intsxpnt (command "-INSERT" blname "_s" 1 "_r" 0 "_non" (car intsxpnt)))

rather than just :

(command "INSERT" blname "_s" 1 "_r" 0 "_non" (car intsxpnt))

to grab the first point (of Lee's list of lists) ?

Additionally, I didn't know that the MAKE option of the LAYER command would switch and/or generate to the specified layer; Very helpful.

Thank you!

 

0 Likes
Message 4 of 4

ВeekeeCZ
Consultant
Consultant

@Ethan_Gale wrote:

Thank you so much for the help! It is working great now.

I do have a question regarding why you used:

(if intsxpnt (command "-INSERT" blname "_s" 1 "_r" 0 "_non" (car intsxpnt)))

rather than just :

(command "INSERT" blname "_s" 1 "_r" 0 "_non" (car intsxpnt))

....


 

Well, you're right, it's not necessary. 

 

It basically tests whether the intersect method found some point(s) or not because then the following insert-command fails and the routine stops. Originally I put it there as part of debugging process because it failed on this command and I wasn't entirely sure of your algorithm if no-found can be the case.

Even then when I found the cause I left it there because it simply does no harm and you know... even the intersect method may fail just because polylines can be complicated in their shape... 

 

BTW even the "_non" is not necessary since you already set the 'osmode to 0. ---- OR maybe, you could try to rewrite the routine without need to mess with sysvars... It wouldn't be to hard. And read THIS recent thread to get some clever thoughts about sysvars. 

 

So anyway, glad that you think about it in detail. The code was quite good!!

0 Likes