Jump to content

Block into multileader text


Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    7

  • stevsmith

    4

  • seapea

    2

  • janickovic

    2

Top Posters In This Topic

Posted Images

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 year later...

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 years later...

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

  • 2 years later...

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.

Link to comment
Share on other sites

  • 6 months later...
  • 1 year later...
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?

Link to comment
Share on other sites

  • 3 weeks later...

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.

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