Jump to content

Lisp required to Align zig zag placed attributes


amb2301

Recommended Posts

Hi Friends, 

       i got some task to align zig zag attributes to proper way as shown in screenshot.

also i have attached the sample dwg file for the same, could someone please provide me lisp to do this task,

it would be a great help for me.

 

Thanks in Advance.

image.png.fe1e89a7e8ab98a111c0c3b205b66f5c.png

sample_dwg.dwg

Link to comment
Share on other sites

This should work unless you have the insert point of your attributed blocks far from the attribute definition.

(defun c:test (/ int sel 1pt 2pt alg ent ins cls)
  (and (princ "\nSelect Attributed blocks to align to line : ")
       (setq int -1
             sel (ssget "_:L" '((0 . "INSERT") (66 . 1)))
       )
       (setq 1pt (getpoint "\nSpecify base point of line : "))
       (setq 2pt (getpoint "\nSpecify next point of line : " 1pt))
       (setq
         alg (entmakex (list '(0 . "LINE") (cons 10 1pt) (cons 11 2pt)))
       )
       (while (setq int (1+ int)
                    ent (ssname sel int)
              )
         (and (setq ins (cdr (assoc 10 (entget ent)))
                    cls (vlax-curve-getclosestpointto alg ins)
              )
              (vlax-invoke (vlax-ename->vla-object ent) 'Move ins cls)
         )
       )
  )
  (and alg (entdel alg))
  (princ)
) (vl-load-com)

 

  • Thanks 2
Link to comment
Share on other sites

1 hour ago, rlx said:

Brilliant  as always Tharwat 👍

Thank you rlx, that's to kind of you to say. :) 

 

1 hour ago, amb2301 said:

Thank you so much Sir, it worked perfectly.

Really you saved my day Sir.

 

 

You're welcome anytime. :) 

Link to comment
Share on other sites

On 11/15/2020 at 3:09 AM, Tharwat said:

Thank you rlx, that's to kind of you to say. :) 

 

You're welcome anytime. :) 

Tharwat, one check is to make sure that the current layer is unlocked so entdel works. It's one of the most annoying checks to miss...

Plus, I believe it's better if you supply the "extend infinitely" argument to the vlax-curve-getclosestpointto function, just my opinion so that you can just supply the two points closer to each other.

Nonetheless, everything else is great!

Edited by Jonathan Handojo
Link to comment
Share on other sites

Thanks Jonathan for your comments.

Definitely I agree with you but my codes were to help the OP to automate their work and it was not a commercial program to account for every eventuality that the user might think of or encounter, so its simple as that.

  • Like 1
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...