+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Forum Newbie
    Discipline
    Architectural
    Using
    AutoCAD LT 2009
    Join Date
    Dec 2016
    Posts
    5

    Default I want to add "center alignment" to this lisp

    Registered forum members do not see this ad.

    Hello. I got this lisp here, and I've been using this very well.
    This lisp has center alignment.
    when I use this, this lisp aligns selected objects both X value and Y value.
    BUT
    I'd like to align objects only by X value.
    Could I get this?




    (defun c:AA (/ ActDoc Sel AliObj AliLl AliUr ss AliOpt Ent tempObj tempLl tempUr)

    (vl-load-com)
    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vla-EndUndoMark ActDoc)
    (vla-StartUndoMark ActDoc)
    (if
    (and
    (setq Sel (entsel "\n Select base object (for aligning): "))
    (not (redraw (car Sel) 3))
    (setq AliObj (vlax-ename->vla-object (car Sel)))
    (not (vla-GetBoundingBox AliObj 'AliLl 'AliUr))
    (setq AliLl (safearray-value AliLl))
    (setq AliUr (safearray-value AliUr))
    (setq ss (ssget))
    (not (initget "Left Right Center Top Bottom"))
    (setq AliOpt
    (if (setq AliOpt (getkword "\n Alignment option [Center / Left / Right / Top / Bottom]: <Center> "))
    AliOpt
    "Center"
    )
    )
    (setq cnt -1)
    )
    (while (setq Ent (ssname ss (setq cnt (1+ cnt))))
    (setq tempObj (vlax-ename->vla-object Ent))
    (vla-GetBoundingBox tempObj 'tempLl 'tempUr)
    (setq tempLl (safearray-value tempLl))
    (setq tempUr (safearray-value tempUr))
    (cond
    ((= AliOpt "Center")
    (vlax-invoke
    tempObj
    'Move
    (mapcar '(lambda (a b) (/ (+ a b) 2.0)) tempLl tempUr)
    (mapcar '(lambda (a b) (/ (+ a b) 2.0)) AliLl AliUr)
    )
    )
    ((= AliOpt "Left")
    (vlax-invoke
    tempObj
    'Move
    tempLl
    (list
    (car AliLl)
    (cadr tempLl)
    (caddr tempLl)
    )
    )
    )
    ((= AliOpt "Right")
    (vlax-invoke
    tempObj
    'Move
    tempUr
    (list
    (car AliUr)
    (cadr tempUr)
    (caddr tempUr)
    )
    )
    )
    ((= AliOpt "Top")
    (vlax-invoke
    tempObj
    'Move
    tempUr
    (list
    (car tempUr)
    (cadr AliUr)
    (caddr tempUr)
    )
    )
    )
    ((= AliOpt "Bottom")
    (vlax-invoke
    tempObj
    'Move
    tempLl
    (list
    (car tempLl)
    (cadr AliLl)
    (caddr tempLl)
    )
    )
    )
    )
    )
    )
    (if Sel (redraw (car Sel) 4))
    (vla-EndUndoMark ActDoc)
    (princ)
    )
    (prompt "\nEnter AO to start.")

  2. #2
    Forum Newbie
    Discipline
    Architectural
    Using
    AutoCAD LT 2009
    Join Date
    Dec 2016
    Posts
    5

    Default

    If the alignment could be added to that lisp, I'd like to name it "Middle(M)".

  3. #3
    Super Member
    Computer Details
    tombu's Computer Details
    Operating System:
    Windows 7 64-bit
    Computer:
    Dell
    Monitor:
    two 21"
    Using
    Civil 3D 2015
    Join Date
    Dec 2010
    Location
    Tallahassee, FL USA
    Posts
    519

    Default

    1st Wrap [CODE] tags around selected text using # from Toolbar above.
    2nd Paste the link to where you got the lisp. It gives credit to the author and provides more information about the lisp.

  4. #4
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    751

    Default

    Thats a nice code, just found the source thread and the author is Tim Willey.

    Anyway heres my attempt:
    Code:
    ; Align Objects with Justification
    (defun C:test ( / m mv *error* Lst s SS c acDoc i o d Lst2 sBL sTR dBL dTR)
      
      (defun m (p1 p2) (apply 'mapcar (cons '(lambda (a b) (/ (+ a b) 2.)) (list p1 p2))))
      (defun mv (o p1 p2) (vlax-invoke o 'move p1 p2))
      (defun *error* (m) (and acDoc (vla-EndUndoMark acDoc))(print m)(princ))
      (setq Lst
        (list
          (cons "Left" '((d) (list (cadr d) (list (car (car s)) (cadr (cadr d)) (caddr (cadr d))))))
          (cons "Center" '((d) (list (cadddr d) (list (car (caddr s)) (cadr (cadddr d)) (caddr (cadddr d))))))
          (cons "Right" '((d) (list (caddr d) (list (car (cadr s)) (cadr (caddr d)) (caddr (caddr d))))))
          (cons "Top" '((d) (list (caddr d) (list (car (caddr d)) (cadr (cadr s)) (caddr (caddr d))))))
          (cons "Middle" '((d) (list (cadddr d) (list (car (cadddr d)) (cadr (caddr s)) (caddr (cadddr d))))))
          (cons "Bottom" '((d) (list (cadr d) (list (car (cadr d)) (cadr (car s)) (caddr (cadr d))))))
        )
      )
      
      (setvar 'errno 0)
      (while (/= 52 (getvar 'errno))
        (setq s (car (entsel "\nSelect base object for aligning <exit>: ")))
        (cond
          ((= 7 (getvar 'errno)) (princ "\nMissed.") (setvar 'errno 0))
          (
            (and s 
              (or 
                (not (vlax-method-applicable-p (vlax-ename->vla-object s) 'GetBoundingBox))
                (vl-catch-all-error-p (vl-catch-all-apply 'vla-GetBoundingBox (list (vlax-ename->vla-object s) 'sBL 'sTR)))
              )
            )
            (princ "\nInvalid object.")
          )
          (s 
            (and
              (setq s (mapcar 'safearray-value (list sBL sTR)))
              (setq s (append s (list (apply 'm s))))
              (princ "\nSelect objects to be aligned: ")
              (setq SS (ssget "_:L"))
              (not (initget (apply 'strcat (mapcar '(lambda (x) (strcat x " ")) (mapcar 'car Lst)))))
              (or 
                (setq c 
                  (getkword 
                    (strcat
                      "\nSpecify alignment option [" 
                      (vl-string-right-trim "/" (apply 'strcat (mapcar '(lambda (x) (strcat x "/")) (mapcar 'car Lst))))
                      "]: <Center> "
                    )
                  )
                )
                (setq c "Center")
              )
              (progn
                (repeat (setq i (sslength SS))
                  (and
                    (vlax-method-applicable-p (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i))))) 'GetBoundingBox)
                    (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-GetBoundingBox (list o 'dBL 'dTR))))
                    (setq d (mapcar 'safearray-value (list dBL dTR))) ; o BL TR MC
                    (setq d (append (list o) d (list (apply 'm d))))
                    (setq Lst2 (cons d Lst2))
                  ); and
                ); repeat
                (if Lst2
                  (progn 
                    (setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
                    (or (/= 8 (logand (getvar 'undoctl) 8)) (not (vla-EndUndoMark acDoc)) ) 
                    (not (vla-StartUndoMark acDoc))
                    (mapcar '(lambda (x) (apply 'mv (append (list (car x)) ((cdr (assoc c Lst)) x)))) Lst2)
                    (and (= 8 (logand (getvar 'undoctl) 8)) (vla-EndUndoMark acDoc))
                  )
                )
              )
            ); and 
            (setvar 'errno 52)
          )
        )
      ); while
      
      (princ)
    ); defun

  5. #5
    Forum Newbie
    Discipline
    Architectural
    Using
    AutoCAD LT 2009
    Join Date
    Dec 2016
    Posts
    5

    Default

    Thank you! I will follow the rules here next time

  6. #6
    Forum Newbie
    Discipline
    Architectural
    Using
    AutoCAD LT 2009
    Join Date
    Dec 2016
    Posts
    5

    Default

    Grrr. I really appreciate what you did.
    Could I ask you to add one more thing ?
    I'd like to add "Inner center" that works as "Center" of the previous LISP. And I hope that "the inner center" will be the default option.
    ex) Alignment option [Left / Center / Right / Top / Middel / Bottom / Inner center]: <Inner center>
    If you have some free time, would you help me?

  7. #7
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    751

    Default

    For "Match Center" include this in the Lst variable:
    Code:
    (cons "MatchCenter" '((d) (list (cadddr d) (caddr s))))
    Last edited by Grrr; 9th Jan 2017 at 11:47 am.

  8. #8
    Forum Newbie
    Discipline
    Architectural
    Using
    AutoCAD LT 2009
    Join Date
    Dec 2016
    Posts
    5

    Default

    That is just What I wanted!
    I'm really i really appreciate you doing so, Grrr
    Have a nice day!

  9. #9
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,361

    Default

    Registered forum members do not see this ad.

    Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[CODE]Your Code Here[/CODE] =
    Code:
    Your Code Here
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



Similar Threads

  1. Dimension center of "wall" best practices
    By ColtM16A1 in forum AutoCAD Beginners' Area
    Replies: 0
    Last Post: 25th Aug 2015, 08:38 pm
  2. HELP to include "AcDbAlignedDimension" code for a "Dimension deleting" LISP
    By vernonlee in forum AutoLISP, Visual LISP & DCL
    Replies: 14
    Last Post: 10th Apr 2015, 04:03 pm
  3. little "green dot" at center of x y axis is missing
    By mperry in forum Autodesk Inventor
    Replies: 4
    Last Post: 29th Nov 2012, 06:41 pm
  4. Inventor "Content Center" Question
    By AGMore in forum Autodesk Inventor
    Replies: 18
    Last Post: 16th Apr 2012, 05:17 pm
  5. Replies: 6
    Last Post: 10th Sep 2010, 04:16 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