m1r Posted January 3, 2023 Posted January 3, 2023 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 1 Quote
Steven P Posted January 3, 2023 Posted January 3, 2023 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) Quote
Tharwat Posted January 3, 2023 Posted January 3, 2023 You can not use foreach function over selection set. Quote
Steven P Posted January 3, 2023 Posted January 3, 2023 23 minutes ago, Tharwat said: You can not use foreach function over selection set. OK, change it into a while loop then 1 Quote
mhupp Posted January 3, 2023 Posted January 3, 2023 (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 January 3, 2023 by mhupp 2 Quote
JeJe Posted October 11 Posted October 11 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. Quote
JeJe Posted October 11 Posted October 11 @mhupp Your code seems to work only it places the arrowheads of all the leaders in the origin instead of on the objects. Quote
SLW210 Posted October 11 Posted October 11 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. 1 Quote
JeJe Posted October 11 Posted October 11 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. Quote
Recommended Posts
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.