stevsmith Posted August 17, 2009 Posted August 17, 2009 I would like to try and set up a Multileader that reads the description of a block. For example when I am making the block I would like to put some descriptive text that may say "Post top insert connected to haboe pin" After the block is compelted and placed into a new drawing I would then select the multi leader option and then it would automtically fill in the text. (from the pre-defined description) I would like it to be similar to a callout in solidworks. Quote
alanjt Posted August 17, 2009 Posted August 17, 2009 not too terribly difficult: (defun c:TEST (/ #Entsel #InsPoint #Name #Desc #LandPoint) (if (setq #Entsel (AT:Entsel nil "\nSelect block: " '((0 . "INSERT")) nil) ) ;_ setq (progn ;; convert to vla-object (setq #Entsel (vlax-ename->vla-object (car #Entsel)) ;; insertion point #InsPoint (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint #Entsel) ) ;_ vlax-variant-value ) ;_ vlax-safearray->list ;; block name #Name (vla-get-name #Entsel) ;; block description #Desc (vla-get-comments (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)) ) ;_ vla-get-blocks #Name ) ;_ vla-item ) ;_ vla-get-comments ) ;_ setq (cond ;; no description in block ((eq "" #Desc) (princ (strcat "\nNo description for block: \"" #Name "\"" ) ;_ strcat ) ;_ princ ) ;; specify leader landing location ((setq #LandPoint (getpoint #InsPoint "\nSpecify leader landing location: " ) ;_ getpoint ) ;_ setq (vl-cmdf "_.mleader" "_non" #InsPoint "_non" #LandPoint #Desc) ) ) ;_ cond ) ;_ progn ) ;_ if (princ) ) ;_ defun you'll need this subroutine: ;;; Entsel or NEntsel with options ;;; #Nested - Entsel or Nentsel (T for Nentsel, nil for Entsel) ;;; #Message - Selection message (if nil, "\nSelect object: " is used) ;;; #FilterList - DXF ssget style filtering, no cons (nil if not required) ;;; #Keywords - Keywords to match instead of object selection (nil if not required) ;;; Example: (AT:Entsel nil "\nSelect MText not on 0 layer [settings]: " '((0 . "MTEXT")(8 . "~0")) "Settings") ;;; Alan J. Thompson, 04.16.09 ;;; Updated: Alan J. Thompson, 06.04.09 (changed filter coding and added layer option) (defun AT:Entsel (#Nested #Message #FilterList #Keywords / #Count #Message #Choice #Ent ) (setvar "errno" 0) (setq #Count 0) (or #Message (setq #Message "\nSelect object: ")) (if #Nested (setq #Choice nentsel) (setq #Choice entsel) ) ;_ if (while (and (not #Ent) (/= (getvar "errno") 52) ) ;_ and (and #Keywords (initget #Keywords)) (cond ((setq #Ent (#Choice #Message)) (and #FilterList (vl-consp #Ent) (or (not (member nil (mapcar '(lambda (x) (wcmatch (if (eq (type (cdr (assoc (car x) (entget (car #Ent)))) ) ;_ type 'STR ) ;_ eq (strcase (cdr (assoc (car x) (entget (car #Ent)))) ) ;_ strcase (cdr (assoc (car x) (entget (car #Ent)))) ) ;_ if (cdr x) ) ;_ wcmatch ) ;_ lambda #FilterList ) ;_ mapcar ) ;_ member ) ;_ not (setq #Ent nil) ) ;_ or ) ;_ and ) ) ;_ cond (and (= (getvar "errno") 7) (not #Ent) (setq #Count (1+ #Count)) (prompt (strcat "\nNope, keep trying! " (itoa #Count) " missed pick(s)." ) ;_ strcat ) ;_ prompt ) ;_ and ) ;_ while #Ent ) ;_ defun Quote
stevsmith Posted August 18, 2009 Author Posted August 18, 2009 What do I do with the second script? i get this error Select block: ; error: no function definition: VLAX-ENAME->VLA-OBJECT Quote
alanjt Posted August 18, 2009 Posted August 18, 2009 What do I do with the second script? i get this error Select block: ; error: no function definition: VLAX-ENAME->VLA-OBJECT just put it in the .lsp file with the other. i always forget to add (vl-load-com) because i have it it my startup file. here, i'll just put it together for you: TEST.lsp Quote
stevsmith Posted August 18, 2009 Author Posted August 18, 2009 Thanks Alan. That is exactly what I'm looking for. I'm trying to learn lisp myself. Lee gave me hundreds of tutorials to muck around with, but I'm trying to get back into Solidworks to look for new employment, so the lisp has been sidelined just now. i thought that there was maybe an option in the cui or setup i could have changed to do this. But this lisp is everything Im looking for. Thanks again mate. Quote
alanjt Posted August 18, 2009 Posted August 18, 2009 Thanks Alan.That is exactly what I'm looking for. I'm trying to learn lisp myself. Lee gave me hundreds of tutorials to muck around with, but I'm trying to get back into Solidworks to look for new employment, so the lisp has been sidelined just now. i thought that there was maybe an option in the cui or setup i could have changed to do this. But this lisp is everything Im looking for. Thanks again mate. happy to help had a few minutes last night and i was curious how to access the comments on a block (took a little research). btw, this will exit and prompt you if the block does not have a description. Quote
seapea Posted March 29, 2011 Posted March 29, 2011 How about the block name? This lisp is great, I just want to do the name rather than desc. I've tryed hacking the lisp code with no success 'cause I have no idea what I'm doing. Could you guide me throught how to get the block name in the multileader. Thanks in advance. Quote
alanjt Posted March 29, 2011 Posted March 29, 2011 How about the block name? This lisp is great, I just want to do the name rather than desc. I've tryed hacking the lisp code with no success 'cause I have no idea what I'm doing. Could you guide me throught how to get the block name in the multileader. Thanks in advance. (defun c:BNameLabel (/ obj lastentity ent) (vl-load-com) (if (setq obj (car (entsel "\nSelect block: "))) (if (eq (cdr (assoc 0 (entget obj))) "INSERT") (progn (setq lastentity (entlast)) (vl-cmdf "_.mleader" "_non" (trans (vlax-get (setq obj (vlax-ename->vla-object obj)) 'InsertionPoint) 0 1) PAUSE ) (while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (vl-cmdf "")) (if (not (equal lastentity (setq ent (entlast)))) (vla-put-textstring (vlax-ename->vla-object ent) (vlax-get-property obj (if (vlax-property-available-p obj 'EffectiveName) 'EffectiveName 'Name ) ) ) ) ) (princ "\nInvalid object!") ) ) (princ) ) Quote
seapea Posted March 29, 2011 Posted March 29, 2011 I'm impressed with your quick reply. thanks ok, i run rhe lsp, select the block, see "abc", click to 'Specify opposite corner:', and it all goes away! What am I missing? Does this code go into the other lisp file test.lsp? confused Quote
alanjt Posted March 29, 2011 Posted March 29, 2011 I'm impressed with your quick reply. thanks ok, i run rhe lsp, select the block, see "abc", click to 'Specify opposite corner:', and it all goes away! What am I missing? Does this code go into the other lisp file test.lsp? confused Completely separate from the other routine and it should work fine - does on my end... Quote
janickovic Posted June 11, 2013 Posted June 11, 2013 Hello, does anybody know, how to update this lisp code in a way, that the leader would not start at the block insertion point? I tried to delete some lines from the code, but ended up in AC crash thanks for help Quote
alanjt Posted June 11, 2013 Posted June 11, 2013 Hello, does anybody know, how to update this lisp code in a way, that the leader would not start at the block insertion point? I tried to delete some lines from the code, but ended up in AC crash thanks for help (defun c:BNameLabel (/ ent entl obj) (cond ((not (setq ent (car (entsel "\nSelect block: "))))) ((not (eq (cdr (assoc 0 (entget ent))) "INSERT")) (princ "\nInvalid 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 'EffectiveName) 'EffectiveName 'Name ) ) ) ) ) ) (princ) ) (vl-load-com) (princ) 1 Quote
janickovic Posted June 12, 2013 Posted June 12, 2013 (edited) Hi, thanks, I figured it out in the mean time, nevermind. In addition, I updated the code, so now the leader can read attribute from a block and attach it to the name of the block. But I am getting some weird error about parameters and I would like to have ability to show more parameters, but I don't know the way how to do it (I learned list 10 years ago, in school, but my memory are not the good, I was only able to do this). (defun c:TEST (/ #Entsel #InsPoint #Name #Desc #LandPoint) (if (setq #Entsel (AT:Entsel nil "\nSelect block: " '((0 . "INSERT")) nil) ) ;_ setq (progn ;; convert to vla-object (setq #Entsel (vlax-ename->vla-object (car #Entsel)) ;; insertion point #InsPoint (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint #Entsel) ) ;_ vlax-variant-value ) ;_ vlax-safearray->list ;; block name #Name (vla-get-name #Entsel) ;; block description #Desc (vla-get-comments (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)) ) ;_ vla-get-blocks #Name ) ;_ vla-item ) ;_ vla-get-comments ) ;_ setq (cond ;; no description in block ((eq "" #Desc) (princ (strcat "\nNo description for block: \"" #Name "\"" ) ;_ strcat ) ;_ princ ) (and (foreach att (vlax-invoke #Entsel 'GetAttributes) (eq "TAG" (vla-get-textstring att) (vl-cmdf "_.mleader" "_non" PAUSE "_non" PAUSE (strcat #Name (chr 10) (vla-get-textstring att))) ) ) ; (vl-cmdf "_.mleader" "_non" PAUSE "_non" PAUSE #Name) ) ) ;_ cond ) ;_ progn ) ;_ if (princ) ) ;_ defun Edited June 12, 2013 by janickovic Quote
SLW210 Posted June 12, 2013 Posted June 12, 2013 Please read the Code posting guidelines and use Code Tags for your Code. Quote
swilliams Posted November 4, 2015 Posted November 4, 2015 Is there a way to do the opposite of this lisp? That is, create and then name a block based on its multileader callout)? [the block name would also be followed by a postscript]. I have about a thousand of these to do, each w/ a different name. Quote
MPEREZ Posted November 22, 2017 Posted November 22, 2017 I'm impressed with your quick reply. thanks ok, i run rhe lsp, select the block, see "abc", click to 'Specify opposite corner:', and it all goes away! What am I missing? Does this code go into the other lisp file test.lsp? confused Were you able to figure this out? Quote
MPEREZ Posted November 22, 2017 Posted November 22, 2017 Were you able to figure this out? I see that I was not using the correct command. Quote
ecorom Posted December 12, 2017 Posted December 12, 2017 Hello I'm using the code from post #13 and I would like to modify it a bit. All the blocks in my the drawing have an attribute named "TAG" and I would like to show that value instead of the block name. Can anyone help me please. Thanks. 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.