Jump to content

autocad lisp to create lines by typing point names.


withyou

Recommended Posts

hello

i am looking for a lisp that can create lines or pline by typing point names.

i have the points in my autocad file as blocks attribute with name for each point.

any idea ?

please see attached file

Link to comment
Share on other sites

This should do what you ask

 

(defun c:plbtwnpoints (/ blockSS)
 
 ;; Get Attribute Value  -  Lee Mac
;; Returns the value held by the specified tag within the supplied block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; Returns: [str] Attribute value, else nil if tag is not found.

(defun LM:vl-getattributevalue ( blk tag )
   (setq tag (strcase tag))
   (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att)))
       (vlax-invoke blk 'getattributes)
   )
)

 (defun Line (p1 p2)
 (entmakex (list (cons 0 "LINE")
                 (cons 10 p1)
                 (cons 11 p2))))
 
 (if (setq blockSS (ssget "X" (list (cons 0 "INSERT") (cons 2 "CIVIL-0"))))
   (progn
     (setq nameLatLongList (mapcar '(lambda (x) (list (LM:vl-getattributevalue (vlax-ename->vla-object x) "NAME") (cdr (assoc 10 (entget x))))) (mapcar 'cadr (ssnamex blockSS))))))
 (princ "\nDrawing Line...\n")
 (setq firstpoint (getstring "Enter the name of the first point: "))
 (if (assoc firstpoint nameLatLongList)
   (while (not (eq (setq nextpoint (getstring "\nType the name of the next point: ")) ""))
     (if (assoc nextpoint nameLatLongList)
(line (cadr (assoc firstpoint nameLatLongList)) (cadr (assoc (setq firstpoint nextpoint) nameLatLongList)))
(princ "\nInvalid point. Try again..."))
     ))

 
 )

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...