+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 24
  1. #11
    Super Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    531

    Default

    Registered forum members do not see this ad.

    You can quite easily perform this task manually with two move operations.
    BricsCAD 16

  2. #12
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,073

    Default

    I'd just swap the two selection sets by their centroids.

  3. #13
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2012
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    599

    Default

    [QUOTE=Tharwat;685933]Try this:
    [CODE]
    (defun c:Test ( / one two no1 ob1 ls1 no2 ob2 ls2 sr1 sr2 nos a b en1 en2)
    ;; Tharwat


    Beautiful!

  4. #14
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,053

    Default

    Quote Originally Posted by rlx View Post
    Beautiful!
    Thank you.

  5. #15
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2012
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    599

    Default

    Quote Originally Posted by Tharwat View Post
    Thank you.



    I did make something simular for my VT text editor but its much bigger and not nearly as elegant as yours. But it can do multiple rows (or columns) and also attributes.


    Code:
    ; based on VT.lsp by Rlx
    (defun c:SwapTextRows ( / p1 p2 el1 el2 tl1 tl2)
      (if (and (setq el1 (sfs (setq p1 (getpoint "\nSelect 1st corner source row(s) : "))
         (setq p2 (getcorner p1 "\nOther corner : "))))
        (setq el2 (sfs (setq p1 (getpoint "\nSelect 1st corner target row(s) : "))
         (setq p2 (getcorner p1 "\nOther corner : ")))))
        (progn
          (setq el1 (SortElist el1) tl1 (mapcar '(lambda (x) (cdr (assoc 1 (entget x)))) el1)
         el2 (SortElist el2) tl2 (mapcar '(lambda (x) (cdr (assoc 1 (entget x)))) el2))
          (us el1 tl2)
          (us el2 tl1)
        )
      )
    )
    
    ;remove duplicates
    (defun rdup ( i / o ) (vl-remove-if '(lambda (x) (cond ((vl-position x o) t) ((setq o (cons x o)) nil))) i))
    
    
    ;get insertion point
    (defun getip ( e / ent)
      (setq ent (vlax-ename->vla-object e))
      (if (= (vla-get-alignment ent) 0)
        (reverse (cdr (reverse (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint ent))))))
        (reverse (cdr (reverse (vlax-safearray->list (vlax-variant-value (vla-get-TextAlignmentPoint ent))))))))
    
    
    
    ;el = elist , xl = x , yl = y , ml = matrix , sl = sorted elist
    (defun SortElist ( %elist / el xl yl ml sl)
      (if %elist
        (progn
          (setq el (mapcar '(lambda (x) (list (getip x) x)) %elist) ; %elist -> el ( ((ip)e1) ((ip)e2) .. )
         xl (vl-sort (rdup (mapcar 'caar el)) '<) yl (vl-sort (rdup (mapcar 'cadar el)) '>))
          (foreach y yl (foreach x xl (setq ml (append ml (list (list x y))))));sort by row
          (setq sl (vl-remove 'nil (mapcar '(lambda (x) (if (assoc x el)(cadr (assoc x el)))) ml))))))
    
    
    ; update string
    (defun us (%el %sl)
      (mapcar '(lambda (e s / en)(setq en (entget e))(entmod (subst (cons 1 s) (assoc 1 en) en))) %el %sl))
    
    
    ; (point) inside window
    (defun inside_w (ent p1 p2 / ip )
      (setq ip (getip ent))
      (if (and (>= (car ip)  (min (car p1)(car p2)))   (<= (car ip)  (max (car p1)(car p2)))
        (>= (cadr ip) (min (cadr p1)(cadr p2))) (<= (cadr ip) (max (cadr p1)(cadr p2)))) t nil))
    
    
    
    ;scan for string
    (defun sfs ( %p1 %p2 / i ss el e et)
     (if (setq i 0 ss (ssget "c" %p1 %p2))
       (while (setq e (ssname ss i))
        (setq et (cdr (assoc 0 (entget e))) i (1+ i))
        (cond ((member et '("TEXT" "MTEXT" "ATTRIB" "ATTDEF"))(setq el (cons e el)))
       ((= et "INSERT") (mapcar '(lambda (x) (if (inside_w x %p1 %p2)(setq el (cons x el))))(get-ents e)))))) el)
    
    
    ; get (block) entities
    (defun get-ents ( b / obj e lst)
      ;attrib
      (setq obj (vlax-ename->vla-object b))
      (if (eq :vlax-true (vla-get-HasAttributes obj)) (setq lst (mapcar 'vlax-vla-object->ename (vlax-invoke obj 'GetAttributes))))
      ;text , disable if only attributes are needed
      (setq e (tblobjname "block" (vla-Get-EffectiveName obj)))
      (while (setq e (entnext e)) (if (member (cdr (assoc 0 (entget e))) (list "TEXT" "ATTDEF")) (setq lst (cons e lst)))) lst)
    ;-------
    I try to be as elegant as a 'dragon' can be ... but sometimes ... when it works , it works :-)


    gr. Rlx
    Last edited by rlx; 14th Jun 2017 at 01:33 pm.

  6. #16
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,073

    Default

    Tharwat, you inspired me to play with this - grread version:



    Code:
    ; Grrr - Exploded Table Shift Rows
    ; Credits to: Lee Mac, Tharwat
    ; 1. Select text/mtext that are representing cells from a exploded table
    ; 2. Use grread to shift their values
    (defun C:test ( / SS->SortedMatrixL ShiftL L vL grr Stop )
      
      ; Map to the nth level items - Lee Mac :
      (defun mapncar ( n f l ) (if (< 0 n) (mapcar '(lambda ( x ) (mapncar (1- n) f x)) l) (mapcar f l) ) ) 
      
      ; (mysort (lambda (a b) (apply '< (mapcar 'car (list a b)))) pL)
      (defun mysort ( f L ) (mapcar (function (lambda (x) (nth x L))) (vl-sort-i L (function f))) )
      
      ;; Unique with Fuzz  -  Lee Mac
      ;; Returns a list with all elements considered duplicate to a given tolerance removed.
      (defun LM:UniqueFuzz ( l f / x r )
        (while l (setq x (car l) l (vl-remove-if (function (lambda ( y ) (equal x y f))) (cdr l)) r (cons x r) ) ) (reverse r)
      )
      
      (setq SS->SortedMatrixL
        (lambda ( fuzz / SS i o L tmpL rtn )  
          (cond
            ( (and (princ "\nSelect Text-Cells from Exploded Table to Shift: ") (setq SS (ssget "_:L-I" '((0 . "*TEXT")))))
              (repeat (setq i (sslength SS)) 
                (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
                (setq L (cons (list (vlax-get o 'InsertionPoint) o) L))
              ); repeat 
              (foreach x (LM:UniqueFuzz (mapcar 'caar L) fuzz)
                (and 
                  (setq tmpL (vl-remove-if-not (function (lambda (q) (equal x (caar q) fuzz))) L))
                  (setq tmpL (mysort (lambda (a b) (apply '< (mapcar 'cadr (mapcar 'car (list a b))))) tmpL))
                  (setq rtn (cons tmpL rtn))
                ); and
              ); foreach 
              (and rtn
                (setq rtn (vl-sort rtn (function (lambda (a b) (> (caaar a) (caaar b)))))) 
                (setq rtn (mapncar 1 '(lambda (x) (cadr x)) rtn))
              ); and
              rtn
            ); SS
          ); cond 
        ); lambda 
      ); setq SS->SortedMatrixL
      
      (setq ShiftL (lambda ( fl L ) (if (vl-consp L) (if fl (append (cdr L) (list (car L))) (append (list (last L)) (reverse (cdr (reverse L)))))))) 
      
      (cond 
        ( (not (setq L (SS->SortedMatrixL 1e-1))) (princ "\n Nothing Selected or Invalid Selection") ) ; '((o1 o2 o3) (o4 o5 o6) (o7 o8 o9))
        ( (not (and (vl-every 'vl-consp L) (apply '= (mapcar 'length L)))) (princ "\n Invalid Selection: Select equal amount of items per row.") )
        ( (princ "\nPress [W] or [S] to shift the Rows | [A] or [D] to shift the Columns <exit>: ")
          (setq vL (mapcar 'vla-get-TextString (apply 'append L))) ; values
          (while (not Stop) (setq grr (grread T)) 
            (and (or (equal grr '(2 13)) (member (car grr) '(3 25))) (setq Stop T)) ; Exit keys = ENTER or LMB/RMB
            (cond
              ( (and (= (car grr) 2) ) ; KBD
                (and
                  (cond 
                    ( (member (cadr grr) '(97 65)) (setq L (ShiftL T L)) )
                    ( (member (cadr grr) '(100 68)) (setq L (ShiftL nil L)) )
                    ( (member (cadr grr) '(119 87)) (setq L (mapcar (function (lambda (x) (ShiftL T x))) L)) )
                    ( (member (cadr grr) '(115 83)) (setq L (mapcar (function (lambda (x) (ShiftL nil x))) L)) )
                  ); cond
                  (mapcar (function vla-put-TextString) (apply 'append L) vL)
                ); and 
              ); KBD
            ); cond			
          ); while
        )
      ); cond 
      (princ)
    ); defun C:test
    Although I think that the simpliest way to "switch" both selections would be the way I mentioned in my previous post.

    Not sure if posting the code of my previous demo will be a good idea, since I appreciate your programming work - and I don't feel like spreading freeware programs (although that was easy to assemble from a couple of subfunctions).

  7. #17
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,053

    Default

    Quote Originally Posted by Grrr View Post
    Tharwat, you inspired me to play with this - grread version:
    Cool.
    Nicely done.

  8. #18
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2012
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    599

    Default

    [QUOTE=Grrr;686042] Tharwat, you inspired me to play with this


    Not sure if this is what requester wanted but brilliant nevertheless

  9. #19
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,073

    Default

    Thank you guys for the positive feedback!
    Hopefully you could benefit from that code.

  10. #20
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2012
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    599

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Grrr View Post
    Thank you guys for the positive feedback!
    Hopefully you could benefit from that code.

    I'm not sure if the smoke comming out of my brain when looking at your code is a benefit for me right now , but in time I hope to understand your code

Similar Threads

  1. Lisp for switching multiple layers...?
    By Rsblades in forum AutoLISP, Visual LISP & DCL
    Replies: 23
    Last Post: 30th Sep 2014, 05:43 am
  2. Switching layout tabs with lisp
    By Grigs in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 22nd Jan 2013, 11:33 pm
  3. Lisp for switching layouts
    By OMEGA-ThundeR in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 6th Dec 2012, 05:37 pm
  4. Lisp For Autocad Table
    By rochel1280 in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 31st Mar 2010, 07:08 am
  5. lisp: no items in selection
    By markschu in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 2nd Jul 2009, 01:11 pm

Tags for this Thread

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