+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 22
  1. #1
    Junior Member
    Discipline
    Electrical
    Using
    AutoCAD 2017
    Join Date
    Jul 2017
    Posts
    17

    Default Help with lisp to move text to specific locations w/ a better narrative.

    Registered forum members do not see this ad.

    I need help with a lisp to move multiple, (3)lines of text, to a point or an insertion point. I was helped the other day by a awesome individual who instructed me on using the Point Manager and then a lisp to move text to point, and it worked great. I'd like to somehow incorporate similar logic to move (3) lines of text (multiple (3)lines of text) to a common point relative to each set of (3)line text strings. Please see attachment for a visual narrative. Any help will be greatly appreciated. I'll also share the txt2pt code in the hopes that it maybe tweaked to work in this scenario.

    I'd like to thank you all advance,

    Paul
    Attached Files

  2. #2
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    853

    Default

    Quote Originally Posted by poffenberger View Post
    I need help with a lisp to move multiple, (3)lines of text, to a point or an insertion point. I was helped the other day by a awesome individual who instructed me on using the Point Manager and then a lisp to move text to point, and it worked great. I'd like to somehow incorporate similar logic to move (3) lines of text (multiple (3)lines of text) to a common point relative to each set of (3)line text strings. Please see attachment for a visual narrative. Any help will be greatly appreciated. I'll also share the txt2pt code in the hopes that it maybe tweaked to work in this scenario.

    I'd like to thank you all advance,

    Paul
    Based on your example drawing .. try this:
    Code:
    (defun c:foo (/ p t1 t2 t3 x y)
      ;; RJP - 07.07.2017
      ;; Load visual lisp
      (vl-load-com)
      ;; This is a the y offset for text based on example drawing
      ;; (setq y 0.145833)
      (cond
        ;; If no text on layer "OLI_IDTEXT" are in the drawing exit and prompt
        ((null (setq t1 (ssget "_x" '((0 . "text") (8 . "OLI_IDTEXT")))))
         (print "'OLI_IDTEXT' text not found!")
        )
        ;; If no text on layer "OLI_ANTEXT" are in the drawing exit and prompt
        ((null (setq t2 (ssget "_x" '((0 . "text") (8 . "OLI_ANTEXT")))))
         (print "'OLI_ANTEXT' text not found!")
        )
        ;; Rock and roll ;) .. compile a list of all the green text to be moved as a list of ((<alignment_point> . ename)...)
        ((setq
           t2 (mapcar '(lambda (x) (cons (cdr (assoc 11 (entget x))) x)) (mapcar 'cadr (ssnamex t2)))
         )
         ;; Changed to be a 2X factor of the text height in drawing
         (setq y (* 2. (cdr (assoc 40 (entget (cdr (car t2)))))))
         ;; Foreach base text
         (foreach base (mapcar 'cadr (ssnamex t1))
           ;; Grab the alignment point to move to
           (setq p (cdr (assoc 11 (entget base))))
           (if
    	 ;; Sort the 'green text' list by distance
    	 (and (setq t3 (vl-sort t2 '(lambda (a b) (< (distance p (car a)) (distance p (car b))))))
    	      ;; and check that we have at least 3 items in the sorted list
    	      (>= (length t3) 3)
    	 );; For the first 3 items in sorted green text list ( closest to base text )
    	  (foreach x (list (car t3) (cadr t3) (caddr t3))
    	    ;; Move the text using the base text x value and incrementing the y value by 2X the text height
    	    (vlax-invoke
    	      (vlax-ename->vla-object (cdr x))
    	      'move
    	      (car x)
    	      (setq p (list (car p) (+ y (cadr p)) 0.0))
    	    )
    	    ;; Remove the item from the 'green text' list so it won't get processed twice
    	    (setq t2 (vl-remove x t2))
    	  )
           )
         )
        )
      )
      ;; Shhhh
      (princ)
    )
    Last edited by ronjonp; 7th Jul 2017 at 03:03 pm. Reason: added comments and fixed typo

  3. #3
    Junior Member
    Discipline
    Electrical
    Using
    AutoCAD 2017
    Join Date
    Jul 2017
    Posts
    17

    Default

    ronjonp,
    Thanks for the reply.
    I pasted your code in the visual lisp editor and saved to a .lsp file. Loaded application without any errors. In my drawing at the command line I typed foo then nothing... no prompts, errors nothing. Please let me know if my process is wrong. From just researching the forums I believe the foo after the c: is the command name?

    Thanks
    Paul

  4. #4
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    853

    Default

    Did you run it on your "Move Green Text" test drawing? It worked for me.

  5. #5
    Junior Member
    Discipline
    Electrical
    Using
    AutoCAD 2017
    Join Date
    Jul 2017
    Posts
    17

    Default

    You are awesome!!

    I"m new to this coding thing so I'd like to ask you 2 things?
    On a scale of 1-10 (10 being the hardest) how difficult was this?

    Any recommendation on a starting point? Macro's - Lisp - Scripts. Do they sort of line up in a logical order to learn.

    Thanks again for everything.

    Paul

  6. #6
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    673

    Default

    @ronjonp:
    There seems to be a typo here:
    Code:
    (foreach x t3 (setq t2 (vl-remove t3 t2)))
    And you probably want to only remove the first 3 t3 items from t2.
    BricsCAD 18

  7. #7
    Junior Member
    Discipline
    Electrical
    Using
    AutoCAD 2017
    Join Date
    Jul 2017
    Posts
    17

    Default

    Roy_043,

    This routine seems to work great, is there something I'm missing?

  8. #8
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    853

    Default

    Quote Originally Posted by poffenberger View Post
    Roy_043,

    This routine seems to work great, is there something I'm missing?
    Roy is correct there was a typo ( actually a couple ) ( fixed above ) .. the reason it worked fine is because nothing was being removed from the 't2' list because I was calling the whole list 't3' rather than the individual elements of 't3'. Scale of difficulty for me, I'd give it a 2 .
    As far as learning goes, just keep trying to understand what routines are given to you .. I'll comment the code above so you can learn from it .
    Last edited by ronjonp; 7th Jul 2017 at 02:13 pm.

  9. #9
    Junior Member
    Discipline
    Electrical
    Using
    AutoCAD 2017
    Join Date
    Jul 2017
    Posts
    17

    Default

    ronjonp,

    I made an error in the move green text dwg file. For some reason I scaled the dwg by a factor of 1.5, so your routine works but the distance between the 4 lines of text is too great. Please find attached dwg at the proper scale and could I bother to repeat your magic on the move red text drawing.

    Thanks again
    Attached Files

  10. #10
    Super Member
    Computer Details
    ronjonp's Computer Details
    Operating System:
    Windows 10
    Using
    AutoCAD 2018
    Join Date
    Apr 2009
    Location
    Colorado
    Posts
    853

    Default

    Registered forum members do not see this ad.

    Change: (setq y 0.218751) to (setq y 0.145833) .. I also commented the code above so take a look.

    Actually .. I modified the code above so it will use the 2X the text height as the Y spacing so it should not matter now. I can't believe you used to do this manually!

Similar Threads

  1. Lisp needed for Move objects with specific distance
    By dreams in forum AutoLISP, Visual LISP & DCL
    Replies: 20
    Last Post: 4th Feb 2017, 02:39 pm
  2. How to insert many text objects from CSV or XLSX to specific x,y locations?
    By ktd27 in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 4
    Last Post: 20th Aug 2016, 12:42 am
  3. LISP, Move linetype to specific layer
    By mekis in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 28th Mar 2013, 05:42 pm
  4. LISP - Do routine if specific text is found in a specific block attribute
    By h0okem in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 19th Nov 2011, 05:53 am
  5. Faster way of drawing specific radii archs in specific locations.
    By bbankston in forum AutoCAD Beginners' Area
    Replies: 9
    Last Post: 26th Dec 2010, 03:09 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts