Jump to content
stevsmith

Block into multileader text

Recommended Posts

stevsmith

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.

Share this post


Link to post
Share on other sites
stevsmith

similar to this

multitext01.JPG

multitext02.JPG

Share this post


Link to post
Share on other sites
alanjt

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

Share this post


Link to post
Share on other sites
stevsmith

What do I do with the second script?

 

i get this error

 

Select block: ; error: no function definition: VLAX-ENAME->VLA-OBJECT

Share this post


Link to post
Share on other sites
alanjt
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

Share this post


Link to post
Share on other sites
stevsmith

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.

Share this post


Link to post
Share on other sites
alanjt
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.

Share this post


Link to post
Share on other sites
seapea

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.

Share this post


Link to post
Share on other sites
alanjt
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)
)

Share this post


Link to post
Share on other sites
seapea

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

Share this post


Link to post
Share on other sites
alanjt
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...

 

BnameLabel.gif

Share this post


Link to post
Share on other sites
janickovic

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

Share this post


Link to post
Share on other sites
alanjt
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)

Share this post


Link to post
Share on other sites
janickovic

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 by janickovic

Share this post


Link to post
Share on other sites
swilliams

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.

Share this post


Link to post
Share on other sites
gustavo_alonge

I tried, but is giving fatal error :(

Share this post


Link to post
Share on other sites
MPEREZ
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?

Share this post


Link to post
Share on other sites
MPEREZ
Were you able to figure this out?

 

I see that I was not using the correct command.:ouch:

Share this post


Link to post
Share on other sites
ecorom

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×