shakuhachi Posted April 12, 2011 Share Posted April 12, 2011 I found this code on the net and can't figure out what's wrong. I need to find the last angle so I can insert a block to the last point in the direction of the last angle. Any help is much appreciated. (DEFUN C:FPOLE(/ ent sub1 ptlist pt1 pt2 ang) (COMMAND "pLINE") (while (= 1 (getvar "cmdactive")) (command pause) ) (SETQ ENT (CAR (ENTLAST))) (SETQ SUB1 (ENTNEXT ENT)) (SETQ PTLIST NIL) (WHILE SUB1 (IF (= (CDR (aSSOC 0 (ENTGET SUB1))) "VERTEX") (SETQ PTLIST (APPEND PTLIST (LIST (CDR (aSSOC 10 (ENTGET SUB1)))))) ) (SETQ SUB1 (ENTNEXT SUB1)) ) (SETQ PT1 (CADR (REVERSE PTLIST))) (SETQ PT2 (LAST PTLIST)) (SETQ ANG1 (ANGLE PT1 PT2)) (SETQ ANG2 (RTOS (* 180.0 (/ ANG1 pi))) 2 4) (COMAND "INSERT" "FLAG" "1" "1" ANG2) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 12, 2011 Share Posted April 12, 2011 The last 'command' function has only one 'm', and the Insert command doesn't specify an Insertion Point. I would be inclined however to use the curve functions for this task, since the code will then be suitable for Arcs, Circles, Lines, Polylines, LWPolylines, Ellipses, Splines etc. (defun c:test ( / a e p ) (vl-load-com) (if (and (setq e (car (entsel))) (not (vl-catch-all-error-p (setq p (vl-catch-all-apply 'vlax-curve-getEndParam (list e)) ) ) ) (setq a (* 180. (/ (angle '(0. 0. 0.) (vlax-curve-getFirstDeriv e p)) pi))) ) (command "_.-insert" "flag" "_non" (trans (vlax-curve-getPointatParam e p) 0 1) "1" "1" a) ) (princ) ) Note that there is no checking for existence of the 'flag' block. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 12, 2011 Share Posted April 12, 2011 Oh, by the way, read this regarding posting code. Quote Link to comment Share on other sites More sharing options...
shakuhachi Posted April 13, 2011 Author Share Posted April 13, 2011 Thanks Lee! your the best. You always inspires me on how simple to do lisp yet too complicated on one simple mind. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 13, 2011 Share Posted April 13, 2011 Thanks Shakuhachi I'm glad I could provide some inspiration with my posts Quote Link to comment Share on other sites More sharing options...
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.