Jump to content

Last angle of a Pline


shakuhachi

Recommended Posts

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)

)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...