Jump to content

Create automatic leaders by layer name


m1r

Recommended Posts

Happy new year my friends.

 

Can someone help me by modifying this lisp, this code inserts a leader in one selected object and return the layer name.

 

It would be nice this lisp could work on multiple objects at the same time, i don't mind if the leaders with the layer name are inserted on top of each, the main objective is to make a selection window and not have to pick one single object.

 

Many Thanks

MLabel.lsp

Link to comment
Share on other sites

Just writing this quickly,

 

Look at ssget instead of entsel (http://lee-mac.com/ssget.html) and do a foreach loopin each item selected

 

Soemthing like this (not checked that I have typed it all in correct but gives you a clue where to go with this

 

(defun c:Mlabel (/ ent entl obj ss x)


  (setq ss (ssget)) ; gets a selection set
  (foreach x ss ;; loop for each entity in the selection set
  (cond ((not (setq ent (ssname x ss)))) ;;gets the entity name for current position in selection set



;; (cond ((not (setq ent (car (entsel "\nSelect object: ")))))
       ((setq pt (getpoint "\nSpecify first point: "))
        (setq entl (entlast))
        (vl-cmdf "_.mleader" "_non" pt "\\")
        (while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (vl-cmdf ""))
        (if (not (equal entl (setq entl (entlast))))
          (vla-put-textstring
            (vlax-ename->vla-object entl)
            (vlax-get-property
              (setq obj (vlax-ename->vla-object ent))
              (if (vlax-property-available-p obj 'LayerName)
                'LayerName
                'Layer
              )
            )
          )
        )
       )
 )


  ); end foreach


 (princ)
)
(vl-load-com)
(princ)

 

 

Link to comment
Share on other sites

3 hours ago, Tharwat said:

You can not use foreach function over selection set. 

 

You have to use ssnamex to get all the entity names

 

(defun c:Mlabel (/ SS ent obj)
  (vl-load-com)
  (if (setq SS (ssget))  ; gets a selection set
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (redraw ent 3)     ;Highlight entity that layer name will be pulled from
      (vl-cmdf "_.mleader" "_non" (vlax-curve-getclosestpointto (setq obj (vlax-ename->vla-object ent)) (getpoint "\nSpecify first point: ")) "\\") 
      ;this will pick a point on the entity
      (while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (vl-cmdf "")) ;wait for 2nd point for mleader
      (vla-put-textstring (vlax-ename->vla-object (entlast)) 
        (vlax-get-property obj 'Layer)
      )
      (redraw ent 4) ;un-highlight entity
    )
  )
  (princ)
)

 

--Edit

Will need to add a bit more code. ill have something later tonight.

  • needed to add redraw so the current entity would be highlighted so user can pick a point closest to it
  • moves the leader point onto the entity
  • waits for 2nd point cmdactive reused from original lisp.
  • un-highlights entity so next loop the current entity will only be highlighted.
Edited by mhupp
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...