+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Full Member
    Computer Details
    rwsice9's Computer Details
    Operating System:
    Windows 7 64Bit
    Computer:
    Dell M-4500
    CPU:
    Core i7
    RAM:
    8GB
    Using
    AutoCAD 2011
    Join Date
    Feb 2009
    Location
    Michigan, USA
    Posts
    43

    Default LISP to Grab Layer from a block

    Registered forum members do not see this ad.

    Hey guys. I have a LISP I wrote this morning that asks for an insertion point, grabs the layer of the object, then draws a MLEADER on an associated layer. I have it working completely, except when a block is selected. Can anyone take a look at the code and help out? Thanks in advance!

    Code:
    (defun c:wtags (/ p1 )
    (setq oldlayer (getvar "clayer"))  
    (setq os (getvar "osmode"))
    (setvar "osmode" 531)  
    (setq p1 (getpoint "\nSelect wire to tag: "))
    (setq ent (entget (car (nentselp p1))))
    (setq wlayer (cdr (assoc 8 ent)))
      (if (= wlayer "F-ALRM-WIRE")(setvar "clayer" "F-ANNO-TAGS"))
      (if (= wlayer "F-ALRM-WIRE-SPKR")(setvar "clayer" "F-ANNO-TAGS-SPKR"))
      (if (= wlayer "F-ALRM-WIRE-INDC")(setvar "clayer" "F-ANNO-TAGS-INDC"))
      (if (= wlayer "F-ALRM-WIRE-DTCT")(setvar "clayer" "F-ANNO-TAGS-DTCT"))
      (if (= wlayer "F-ALRM-WIRE-PWR")(setvar "clayer" "F-ANNO-TAGS-PWR"))
      (if (= wlayer "F-ALRM-WIRE")(SETQ TAG ""))
      (if (= wlayer "F-ALRM-WIRE-SPKR")(SETQ TAG "S"))
      (if (= wlayer "F-ALRM-WIRE-INDC")(SETQ TAG "V"))
      (if (= wlayer "F-ALRM-WIRE-DTCT")(SETQ TAG "M"))
      (if (= wlayer "F-ALRM-WIRE-PWR")(SETQ TAG "P"))
      (command "_MLeader" p1 pause tag)
    (setvar "osmode" os)
    (setvar "clayer" oldlayer)
      )

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,595

    Default

    Try something like this rwsice9:
    Code:
    (defun c:wtags ( / *error* la pt ss vl vr wl )
    
        (defun *error* ( msg )
            (mapcar 'setvar vr vl)
            (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
                (princ (strcat "\nError: " msg))
            )
            (princ)
        )
    
        (setq vr '(clayer osmode cmdecho)
              vl  (mapcar 'getvar vr)
        )
        (setvar 'osmode 531)
        (setvar 'cmdecho 0)
        (if (setq pt (getpoint "\nSelect Wire to Tag: "))
            (if (setq ss (ssget pt))
                (if (wcmatch (setq wl (strcase (cdr (assoc 8 (entget (ssname ss 0)))))) "F-ALRM-WIRE*")
                    (progn
                        (setq wl (substr wl 12)
                              la (strcat "F-ANNO-TAGS" wl)
                        )
                        (if (tblsearch "LAYER" la)
                            (command "_.-layer" "_U" la "_T" la "_ON" la "_S" la "")
                            (command "_.-layer" "_M" la "")
                        )
                        (command "_.mleader" "_non" pt "\\"
                            (cond
                                (   (= wl "-SPKR") "S")
                                (   (= wl "-INDC") "V")
                                (   (= wl "-DTCT") "M")
                                (   (= wl "-PWR")  "P")
                                (   ""   )
                            )
                        )
                    )
                    (princ "\nObject not on \"F-ALRM-WIRE*\" layer.")                      
                )
                (princ "\nNo Object found at selected point.")
            )
        )
        (*error* nil)
        (princ)
    )
    Last edited by Lee Mac; 26th Apr 2013 at 04:20 pm.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  3. #3
    Full Member
    Computer Details
    rwsice9's Computer Details
    Operating System:
    Windows 7 64Bit
    Computer:
    Dell M-4500
    CPU:
    Core i7
    RAM:
    8GB
    Using
    AutoCAD 2011
    Join Date
    Feb 2009
    Location
    Michigan, USA
    Posts
    43

    Default

    Thanks Lee! Works perfect as far as setting the correct layers, but it doesn't want to fill in the text now. I do appreciate the help!

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,595

    Default

    Quote Originally Posted by rwsice9 View Post
    Thanks Lee! Works perfect as far as setting the correct layers, but it doesn't want to fill in the text now. I do appreciate the help!
    Oops! Sorry, I forgot the hyphen on each of the layer name patterns. I have now corrected the above code, and have used a cond expression in place of an association list for safety, should the layer name pattern not appear in the list.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  5. #5
    Full Member
    Computer Details
    rwsice9's Computer Details
    Operating System:
    Windows 7 64Bit
    Computer:
    Dell M-4500
    CPU:
    Core i7
    RAM:
    8GB
    Using
    AutoCAD 2011
    Join Date
    Feb 2009
    Location
    Michigan, USA
    Posts
    43

    Default

    Awesome! Thank you very much!

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,595

    Default

    You're very welcome!
    Ask if you have any questions about the code.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  7. #7
    Full Member
    Computer Details
    rwsice9's Computer Details
    Operating System:
    Windows 7 64Bit
    Computer:
    Dell M-4500
    CPU:
    Core i7
    RAM:
    8GB
    Using
    AutoCAD 2011
    Join Date
    Feb 2009
    Location
    Michigan, USA
    Posts
    43

    Default

    I think I sort of at least understand what the code is doing, but not enough to modify on my own with no help. I do have one last question for you (I think). Is there a way to have it prompt for an MLEADER value when the object selected is on the F-ALRM-WIRE layer? While most of the layers have pre-set tags, the general F-ALRM-WIRE layer does not. The current code just draws in the blank mleader. (dont get me wrong, the code you whipped up is awesome )

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,595

    Default

    Quote Originally Posted by rwsice9 View Post
    I do have one last question for you (I think). Is there a way to have it prompt for an MLEADER value when the object selected is on the F-ALRM-WIRE layer?
    Sure, try this:
    Code:
    (defun c:wtags ( / *error* la pt ss vl vr wl )
    
        (defun *error* ( msg )
            (mapcar 'setvar vr vl)
            (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
                (princ (strcat "\nError: " msg))
            )
            (princ)
        )
    
        (setq vr '(clayer osmode cmdecho)
              vl  (mapcar 'getvar vr)
        )
        (setvar 'osmode 531)
        (setvar 'cmdecho 0)
        (if (setq pt (getpoint "\nSelect Wire to Tag: "))
            (if (setq ss (ssget pt))
                (if (wcmatch (setq wl (strcase (cdr (assoc 8 (entget (ssname ss 0)))))) "F-ALRM-WIRE*")
                    (progn
                        (setq wl (substr wl 12)
                              la (strcat "F-ANNO-TAGS" wl)
                        )
                        (if (tblsearch "LAYER" la)
                            (command "_.-layer" "_U" la "_T" la "_ON" la "_S" la "")
                            (command "_.-layer" "_M" la "")
                        )
                        (command "_.mleader" "_non" pt "\\")
                        (cond
                            (   (= wl "-SPKR") (command "S"))
                            (   (= wl "-INDC") (command "V"))
                            (   (= wl "-DTCT") (command "M"))
                            (   (= wl "-PWR")  (command "P"))
                            (   (command "" "_.ddedit" (entlast) ""))
                        )
                    )
                    (princ "\nObject not on \"F-ALRM-WIRE*\" layer.")                      
                )
                (princ "\nNo Object found at selected point.")
            )
        )
        (*error* nil)
        (princ)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  9. #9
    Full Member
    Computer Details
    rwsice9's Computer Details
    Operating System:
    Windows 7 64Bit
    Computer:
    Dell M-4500
    CPU:
    Core i7
    RAM:
    8GB
    Using
    AutoCAD 2011
    Join Date
    Feb 2009
    Location
    Michigan, USA
    Posts
    43

    Default

    Quote Originally Posted by Lee Mac View Post
    Sure, try this:
    Code:
                            (   (command "" "_.ddedit" (entlast) ""))
    I probably should have been able to figure that one out.. Now that I see it it seems like the obvious solution. Thanks again, man. Works absolutely perfectly!

  10. #10
    Full Member
    Computer Details
    rwsice9's Computer Details
    Operating System:
    Windows 7 64Bit
    Computer:
    Dell M-4500
    CPU:
    Core i7
    RAM:
    8GB
    Using
    AutoCAD 2011
    Join Date
    Feb 2009
    Location
    Michigan, USA
    Posts
    43

    Default

    Registered forum members do not see this ad.

    And it even worked on the F-ALRM-WIRE-CTRL layer! That's not even in the code at all!! Awesome!

Similar Threads

  1. lisp for changing all objects in a block to layer "0"
    By chulse in forum AutoLISP, Visual LISP & DCL
    Replies: 26
    Last Post: 23rd Jun 2016, 09:14 pm
  2. LISP to Rename BLock to Match its Layer Name
    By nod684 in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 8th Sep 2012, 09:37 am
  3. Text Can't grab It
    By lulumara in forum AutoCAD General
    Replies: 15
    Last Post: 6th Mar 2012, 09:44 am
  4. LISP program for inserting block selected layer (points) only
    By cadamrao in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 23rd Apr 2010, 03:50 am
  5. Dimension can't grab it
    By lulumara in forum AutoCAD General
    Replies: 7
    Last Post: 27th Aug 2009, 05:05 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