Jump to content

Recommended Posts

Posted

Hii Everyone,

I want a lisp to move all mtexts to nearest polyline ends.

 

DWG sample is attached.

new block3.dwg

Thanks in Advance

Posted
(defun c:test (/ int sel ent get pos pts ins srt)
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (and (princ "\nSelect Polylines & Texts : ")
       (setq int -1
             sel (ssget "_:L" '((0 . "*TEXT,LWPOLYLINE")))
       )
       (while (setq int (1+ int)
                    ent (ssname sel int)
              )
         (setq get (entget ent)
               pos (cdr (assoc 10 get))
         )
         (or (and (= (cdr (assoc 0 get)) "LWPOLYLINE")
                  (setq pts (cons pos pts)
                        pts (cons (cdr (assoc 10 (reverse get))) pts)
                  )
             )
             (setq ins (cons (list pos ent) ins))
         )
       )
       (while (and ins pts)
         (and (setq pos (car ins))
              (setq srt (car (vl-sort
                               pts
                               (function
                                 (lambda (j k)
                                   (< (distance (car pos) j) (distance (car pos) k))
                                 )
                               )
                             )
                        )
                    pts (vl-remove srt pts)
              )
              (vlax-invoke
                (vlax-ename->vla-object (cadr pos))
                'Move
                (car pos)
                (append srt '(0.0))
              )
         )
         (setq ins (cdr ins))
       )
  )
  (princ)
) (vl-load-com)

 

  • Like 1
Posted

Thank you so much for your reply, it works brilliantly.

 

Can same type of lisp work on block ?

You can find it in the attached drawingnew block3.dwg

Posted

You're welcome. :)

Just add the entity name to the selection set as follows.

(0 . "*TEXT,INSERT,LWPOLYLINE")

 

  • Like 2
  • 1 year later...
Posted (edited)
On 9/6/2022 at 6:46 PM, Tharwat said:
(defun c:test (/ int sel ent get pos pts ins srt)
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (and (princ "\nSelect Polylines & Texts : ")
       (setq int -1
             sel (ssget "_:L" '((0 . "*TEXT,LWPOLYLINE")))
       )
       (while (setq int (1+ int)
                    ent (ssname sel int)
              )
         (setq get (entget ent)
               pos (cdr (assoc 10 get))
         )
         (or (and (= (cdr (assoc 0 get)) "LWPOLYLINE")
                  (setq pts (cons pos pts)
                        pts (cons (cdr (assoc 10 (reverse get))) pts)
                  )
             )
             (setq ins (cons (list pos ent) ins))
         )
       )
       (while (and ins pts)
         (and (setq pos (car ins))
              (setq srt (car (vl-sort
                               pts
                               (function
                                 (lambda (j k)
                                   (< (distance (car pos) j) (distance (car pos) k))
                                 )
                               )
                             )
                        )
                    pts (vl-remove srt pts)
              )
              (vlax-invoke
                (vlax-ename->vla-object (cadr pos))
                'Move
                (car pos)
                (append srt '(0.0))
              )
         )
         (setq ins (cdr ins))
       )
  )
  (princ)
) (vl-load-com)

 

 

 

Please , How to Select All Polylines in the drawing except from Frozen and Locked and OFF layers ?

 

 

Edited by Engineer_Yasser

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