place multi-leader Object Layer DESCRITPTION

place multi-leader Object Layer DESCRITPTION

DJGinAZ
Advocate Advocate
1,541 Views
4 Replies
Message 1 of 5

place multi-leader Object Layer DESCRITPTION

DJGinAZ
Advocate
Advocate

This is my first post so please bear with me. 

 

Our senior tech made a lisp that sets a multileader style and annotation layer current, then the user selects an object in an xref which populates the multileader text with that object layer. We then use search and replace to edit the text. I would like to remove the search&replace step by modifying the lisp to read and the Layer Description instead of the layer. The senior tech is out of the office for some time and he's the resident LISP programming expert.

 

Please help me figure out how to change this from reading the LAYER and instead read the Layers' DESCRIPTION. Thank you!

(defun cmdoff()(setvar "cmdecho" 0)(princ))
(defun cmdon()(setvar "cmdecho" 1)(princ))
(defun c:TMK ( / oldosm entn entl ent8 sctr ent8l pstr stp1 stp2)
  (princ "TRAFFIC MARKING KEY MULTILEADER")
  (cmdoff)
  (setq oldosm (getvar "osmode"))
  (setq oldmsty (getvar "cmleaderstyle"))
  (setvar "clayer" "C-ANNO-TEXT")
  (setvar "osmode" 513)
  (setvar "cmleaderstyle" "TMK")
  (setq entn (car (nentsel )))
  (if entn
    (progn
    (setq entl (cdr (entget entn)))
    (setq ent8 (cdr (assoc 8 entl)))
    ;
    (setq sctr 2 ent8l (strlen ent8))
    (while (<= sctr ent8l )
      (setq pstr (substr ent8 sctr 1 ))
      (if (= pstr "|" )
	(progn
	  (setq stp1 (substr ent8 1 (- sctr 1 )))
	  (setq stp2 (substr ent8 (+ 1 sctr ) ent8l ))
	  )
	)
      (setq sctr (+ 1 sctr))
      )
    ;
    (command "mleader" pause pause stp2 "")
    )
    (setvar "osmode" oldosm)
    ;(setvar "cmleaderstyle" oldmsty)
    )(cmdon)
  (princ)
  )

 

0 Likes
Accepted solutions (1)
1,542 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

Try replacing this much:

    ;
    (setq sctr 2 ent8l (strlen ent8))
    (while (<= sctr ent8l )
      (setq pstr (substr ent8 sctr 1 ))
      (if (= pstr "|" )
        (progn
          (setq stp1 (substr ent8 1 (- sctr 1 )))
          (setq stp2 (substr ent8 (+ 1 sctr ) ent8l ))
        )
      )
      (setq sctr (+ 1 sctr))
      )
    ;

 

[which is extracting the Layer name, minus the Xref-dependent part, and could be done more concisely], with this [lightly tested]:

 

    (setq stp2 (vla-get-Description (vlax-ename->vla-object (tblobjname "layer" ent8))))

 

and if not already done by something else, add this somewhere in the .lsp file, so it will be able to use those (vl...) functions:

 

(vl-load-com)

Kent Cooper, AIA
0 Likes
Message 3 of 5

DJGinAZ
Advocate
Advocate

Thanks for you quick reply Kent.

 

I couldn't even copy/paste that correctly without getting the "error: malformed list input." message. Not sure where i went wrong with it. Basically, I'm only capable of changing some quoted text when it comes to modifying lisps. Any chance you could format if so I could copy/paste into my .lsp?

 

Thank you.

(defun cmdoff()(setvar "cmdecho" 0)(princ))
(defun cmdon()(setvar "cmdecho" 1)(princ))
(defun c:TMK ( / oldosm entn entl ent8 sctr ent8l pstr stp1 stp2)
  (princ "TRAFFIC MARKING KEY MULTILEADER")
  (cmdoff)
  (setq oldosm (getvar "osmode"))
  (setq oldmsty (getvar "cmleaderstyle"))
  (setvar "clayer" "C-ANNO-TEXT")
  (setvar "osmode" 513)
  (setvar "cmleaderstyle" "TMK")
  (setq entn (car (nentsel )))
  (if entn
    (progn
    (setq entl (cdr (entget entn)))
    (setq ent8 (cdr (assoc 8 entl)))
    ;
;;    (setq sctr 2 ent8l (strlen ent8))
;;    (while (<= sctr ent8l )
;;      (setq pstr (substr ent8 sctr 1 ))
;;      (if (= pstr "|" )
;;	(progn
;;	  (setq stp1 (substr ent8 1 (- sctr 1 )))
;;	  (setq stp2 (substr ent8 (+ 1 sctr ) ent8l ))
;;	  )
;;	)
;;     (setq sctr (+ 1 sctr))
;;      )
;;    ;
(vl-load-com)
(setq stp2 (vla-get-Description (vlax-ename->vla-object (tblobjname "layer" ent8)))

    (command "mleader" pause pause stp2 "")
    )
    (setvar "osmode" oldosm)
    ;(setvar "cmleaderstyle" oldmsty)
    )(cmdon)
  (princ)
  )
0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... 

I couldn't even copy/paste that correctly without getting the "error: malformed list input." message. Not sure where i went wrong with it. ....


You caught that too fast -- I noticed almost immediately that I'd left off a right parenthesis, but you got to it before I edited that in.  Go back to mine and get the line with four )))) at the end [or just add that extra one to your edited code].

 

[And typically, one would put the (vl-load-com) outside a (defun) function definition, such as at the top or bottom of the .lsp file, though it should still work where you have it.]

Kent Cooper, AIA
0 Likes
Message 5 of 5

DJGinAZ
Advocate
Advocate

Awesome! You just made me look like a true hero. This is a ridiculously useful lisp now.

 

Thank you so much Kent!

0 Likes