Jump to content

Recommended Posts

Posted

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

  • Like 1
Posted

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)

 

 

Posted
23 minutes ago, Tharwat said:

You can not use foreach function over selection set. 

 

OK, change it into a while loop then

  • Funny 1
Posted (edited)
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
  • 1 year later...
Posted

Do any of you have the original Mlabel.lsp code as it is no longer available and I would already be happy with that functionality. 

Posted

@mhupp Your code seems to work only it places the arrowheads of all the leaders in the origin instead of on the objects.

Posted
29 minutes ago, JeJe said:

Do any of you have the original Mlabel.lsp code as it is no longer available and I would already be happy with that functionality. 

It's available in the first post.

  • Like 1
Posted
1 hour ago, SLW210 said:

It's available in the first post.

I think it was because I wasn't registered yet. It just said "not available anymore". Very useful lisp. If the issue with the new lisp that handles multiple objects would be solved this could help me and others greatly. Trying to get Chatgpt to do it didn't work. I'm not able to code lisp sadly.

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...