Trizza Posted June 3, 2011 Posted June 3, 2011 Ok so I wrote this LISP in 2010 at home and got it to work as i excpected it to. Saved it to a stick, took it to work and ran it in 2011 on what it was created for and an error came up (i believe it is consp, cant be sure coz server is down, will reassure later) The LISP is design to place a point at every endpoint in a polyline: ;;Place points at each vertice of a polyline (defun c:pl2pt (/ SelSet o_max o object Location ent_db ent_t ent_v X Y Z p) (setq SelSet (ssget)) (setq o_max (sslength SelSet)) (setq o 0) (while (< o o_max) ;search through selected objects (setq ent_db (entget (ssname SelSet o))) (setq ent_t (cdr (assoc 0 ent_db))) (princ ent_t) ;Line "LINE" ;End of Line case ;Polyline ;(if (= ent_t "LWPOLYLINE") ;( ;true statement ;(cond ;((= ent_t "LWPOLYLINE") ( (setq Z (cdr (assoc 38 ent_db))) (setq ent_v (cdr (assoc 90 ent_db))) (setq p 13) (while (< p (+ (* ent_v 5) 9)) (setq X (cadr (nth p ent_db))) (setq Y (caddr (nth p ent_db))) (setq Location (list X Y Z)) (command "_point" Location) (setq p (+ p 5)) ;next sector of polyline ) ;endwhile - end of polyline search ;endtrue - end of true statement ;endif ;end condition ;End of Polyline case ;2DPolyline ;End of 2DPolyline case ;3DPolyline "POLYLINE" ;End of 3DPolyline case (setq o (+ o 1)) ;next object ) ;endwhile for objects in selection set ) I also want to be able to do this for lines, 3d polylines and 2d polylines (if anyone knows the type for a 2d polyline that would save me a few minutes), but when i introduce the 'if (= ent_t "LWPOLYLINE")' statement that is currently a comment the point creating script produces and error (again can't give you the error because the server is down). I also tried using cases to see if that works but with no positive result. Any clues? Quote
Ahankhah Posted June 3, 2011 Posted June 3, 2011 ;;Place points at each vertice of a polyline (defun c:pl2pt (/ SelSet o_max o object Location ent_db ent_t ent_v X Y Z p) (setq SelSet (ssget)) (setq o_max (sslength SelSet)) (setq o 0) (while (< o o_max) ;search through selected objects (setq ent_db (entget (ssname SelSet o))) (setq ent_t (cdr (assoc 0 ent_db))) (princ ent_t) ;Line "LINE" ;End of Line case ;Polyline ;(if (= ent_t "LWPOLYLINE") ;( ;true statement ;(cond ;((= ent_t "LWPOLYLINE") ( (setq Z (cdr (assoc 38 ent_db))) (setq ent_v (cdr (assoc 90 ent_db))) (setq p 13) (while (< p (+ (* ent_v 5) 9)) [color=red](setq X (cadr (nth p ent_db)))[color=black]<--It refers to a cons list: (39 . 0.0), it isn't point list[/color] [/color] (setq Y (caddr (nth p ent_db))) (setq Location (list X Y Z)) (command "_point" Location) (setq p (+ p 5)) ;next sector of polyline ) ;endwhile - end of polyline search ;endtrue - end of true statement ;endif ;end condition ;End of Polyline case ;2DPolyline ;End of 2DPolyline case ;3DPolyline "POLYLINE" ;End of 3DPolyline case (setq o (+ o 1)) ;next object ) ;endwhile for objects in selection set ) Quote
Trizza Posted June 3, 2011 Author Posted June 3, 2011 Thanks Ahankhan, ill have to check the entity database again, seems like they have changed it between versions Any clue about why including the if statement causes an error? Quote
BlackBox Posted June 3, 2011 Posted June 3, 2011 Consider stepping through each entity in a filtered selection set, and extract the vertex coordinates using vlax-curve-getpointatparam ( I'm pretty sure Alan, or Lee posted something similar here already. Hope this helps! Quote
Trizza Posted June 7, 2011 Author Posted June 7, 2011 I went searching for that code u mentioned and found this by Alan, i had to put some comments in to explain it to myself and spend a few days figuring out what was goin on (defun AT:Segment (objPnt) ;; Retreive segment number and Start & End points ;; objPnt - List with object & point ;; Alan J. Thompson, 11.10.09 / 08.19.10 (if (vl-consp objPnt) ((lambda (seg) (list seg (list (vlax-curve-getPointAtParam (car objPnt) seg) (cond ((vlax-curve-getPointAtParam (car objPnt) (1+ seg))) ((vlax-curve-getPointAtParam (car objPnt) (1- seg))) ) ;end cond ) ;end list ) ;end list = (seg# ((list.xyz) (cond.xyz)) ) ) ;end lambda (function) (fix (vlax-curve-getParamAtPoint (car objPnt) (vlax-curve-getClosestPointTo (car objPnt) (trans (cadr objPnt) 1 0)) ) ) ;end fix ) ;end true ) ;endif ) ;end func Im slightly confused on a few things 1. how to use an AT: command 2. how would i define the objPnt variable 3. what is the lambda function doing in this function (ie. what is it returning/defining) PS. i had to get my head around the lambda function in general but it was usually used with mapcar 4. similarly with the fix function, i know that it turns a real into integer but that integer isnt being used in anyway Quote
BlackBox Posted June 7, 2011 Posted June 7, 2011 Im slightly confused on a few things 1. how to use an AT: command 2. how would i define the objPnt variable 3. what is the lambda function doing in this function (ie. what is it returning/defining) PS. i had to get my head around the lambda function in general but it was usually used with mapcar 4. similarly with the fix function, i know that it turns a real into integer but that integer isnt being used in anyway For LISP functions that are not preceded by "c:" ( (AT:Segment [color=red]objPnt[/color]) ... Just be sure to include a qualified argument for this function, i.e, (cons vla-Object PointList). Lambda may take a little bit to sink in. In this case, it (the lambda) concisely provides a means by which to supply the lambda's "seg" argument by performing the fix function, and performing the vlax-curve-getpointatparam function within the lambda itself. That may not make sense, but basically the alternative would be to perform the fix function first (store to variable), then perform the the vlax-curve-getpointatparam component, followed by a princ/prompt, etc.. The posted method is a more concise method. Hope this helps! Quote
Trizza Posted June 9, 2011 Author Posted June 9, 2011 (edited) Thanks again. Hmm, gonna have to ponder on that one I have been working on this other routine with a little help from other threads (edited) (defun c:ContSep (/ ss i interval ent_db) (setq ss (ssget)) (setq interval (getreal "\nEnter contour interval: ")) (setq i 0) (while (< i (sslength ss)) ( (setq ent_db (entget (ssname ss i))) (if (= (rem (cdr (assoc 38 ent_db)) interval) 0) (entmod (subst (cons 8 (strcat "Contour_" (rtos interval 2) "m")) (assoc 8 ent_db) ent_db ) ) ) (setq i (1+ i)) ) ) ) and i keep getting 'too few arguments' error and i have looked through, check brackets, looked up the commands and made sure everything is there. Maybe i keep missing it but i just cant find what is causing the error. I found i was misusing entmod and subst commands but with the updated code I am getting 'extra cdrs in dotted pair input'. If i run the script in visual lisp console without the while and increment 'i' manually it works fine. But how can '( Edited June 9, 2011 by Trizza Quote
Recommended Posts
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.