+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 24
  1. #1
    Full Member
    Discipline
    Electrical
    Using
    AutoCAD 2016
    Join Date
    Apr 2017
    Posts
    56

    Default Switching two items in a table in AutoCAD LISP

    Registered forum members do not see this ad.

    Hello,

    I was wondering if anyone was able to make a LISP that would swap two line items in a panel schedule to where you select the two circuits and they swap the information in each.



    I realize excel does this but we do not do it that way.

    I'm thinking that this LISP will have to be using a move command simultaneously with a selected common basepoint for the two items. I'm not very good at coding but this would be a huge time saver for me.

    Mirroring the two items does not always work because not all schedules are using text centered between the two lines.

    Thank you in advance!

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,368

    Default

    Are you using a table object or is the table composed of text & lines?
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,165

    Default

    Previously I was about to ask if there was such functionality to shift table rows, but decided to code it myself rather than asking on the forums.


  4. #4
    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 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    637

    Default

    Quote Originally Posted by Grrr View Post
    Previously I was about to ask if there was such functionality to shift table rows, but decided to code it myself rather than asking on the forums.

    Very nice Grrr, cool!

    gr. Rlx

  5. #5
    Full Member
    Discipline
    Electrical
    Using
    AutoCAD 2016
    Join Date
    Apr 2017
    Posts
    56

    Default

    could you share?

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

    Default

    @ryankevin15:
    You should answer Lee's crucial question. If your table is not an actual table object Grrr's code won't work. Looking at your image I doubt it is a table object.
    BricsCAD 18

  7. #7
    Full Member
    Discipline
    Electrical
    Using
    AutoCAD 2016
    Join Date
    Apr 2017
    Posts
    56

    Default

    No it's line objects in AutoCAD. Looks better/more control of style.

  8. #8
    Forum Newbie sieu khung khiep's Avatar
    Computer Details
    sieu khung khiep's Computer Details
    Operating System:
    Windows 8.1 pro
    Discipline
    Architectural
    Using
    AutoCAD 2007
    Join Date
    Jan 2017
    Posts
    9

    Default

    Nice Grrr

  9. #9
    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,088

    Default

    Quote Originally Posted by ryankevin15 View Post
    No it's line objects in AutoCAD. Looks better/more control of style.
    Try this:
    Code:
    (defun c:Test ( / one two no1 ob1 ls1 no2 ob2 ls2 sr1 sr2 nos a b en1 en2)
      ;;	Tharwat - Date:13.Jun.2017	;;
    (if (and (princ "\nSelect texts in 1st row :")
          (setq one (ssget "_:L" '((0 . "*TEXT"))))
          (princ "\nSelect texts in 2nd row :")
          (setq two (ssget "_:L" '((0 . "*TEXT"))))
          )
      (progn
        (repeat (setq no1 (sslength one))
          (setq ob1 (ssname one (setq no1 (1- no1)))
                ls1 (cons (list (car (cdr (assoc 10 (entget ob1)))) ob1) ls1)
            )
          )
        (repeat (setq no2 (sslength two))
          (setq ob2 (ssname two (setq no2 (1- no2)))
                ls2 (cons (list (car (cdr (assoc 10 (entget ob2)))) ob2) ls2)
            )
          )
        (setq sr1 (vl-sort ls1 '(lambda (a b) (< (car a) (car b))))
              sr2 (vl-sort ls2 '(lambda (a b) (< (car a) (car b))))
              nos 0
          )
        (while (and (setq a (nth nos sr1))
                    (setq en1 (entget (cadr a)))
                    (setq b (nth nos sr2))
                    (setq en2 (entget (cadr b)))
                 )
          (entmod (subst (assoc 1 en1) (assoc 1 en2) en2))
          (entmod (subst (assoc 1 en2) (assoc 1 en1) en1))
          (setq nos (1+ nos))
          )
        )
      )
    (princ))

  10. #10
    Full Member
    Discipline
    Electrical
    Using
    AutoCAD 2016
    Join Date
    Apr 2017
    Posts
    56

    Default

    Registered forum members do not see this ad.

    Wow! that works perfectly, could we get it where it'll work where you could have 2-3 lines trade with 2-3 lines? Maybe an error if the selections don't match in terms of the number of lines?


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