Jump to content

Lisp for Layout name to block attribute


gamulj

Recommended Posts

Hi to all!

 

I'am building the title block (block with attributes) and I need a routine that will automatically read layout name, in multi layout dwg, and write it into block attribute „LAYOUT“ for every layout. Field with Ctab doesn't suits my needs...:(

 

Is something like this possible?

Thanks!

Link to comment
Share on other sites

Yes it is possible .

 

What is the name of your attributed title block ?

 

Hi Tharwat!

 

The name of block is TITLEBLOCK.

Link to comment
Share on other sites

Here we go , try this program .

 

(defun c:Test  nil
 ;;------------------------------------;;
 ;;    Tharwat 20.05.2015        ;;
 ;;    Modify Title Blocks that have     ;;
 ;;    Tag name "LAYOUT" wiht its    ;;
 ;;    location is each Layout's Name    ;;
 ;;------------------------------------;;
 (vlax-for x  (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
   (if (/= (vla-get-name x) "Model")
     (vlax-for b  (vla-get-block x)
       (and (eq (vla-get-objectname b) "AcDbBlockReference")
            (eq (vla-get-effectivename b) "TILTEBLOCK")
            (vl-some
              '(lambda (a)
                 (if
                   (eq "LAYOUT" (strcase (vla-get-tagstring a)))
                    (vla-put-textstring a (vla-get-name x))
                    )
                 )
              (vlax-invoke b 'getattributes)
              )
            )
       )
     )
   )
 (princ)
 )(vl-load-com)


Link to comment
Share on other sites

Works great!

 

Thanks a million!!!

 

Excellent . You are most welcome .

 

 

Is there a way to make lisp automatically recall on open/save or refresh?

 

You must be in need of running the program on many drawing files . mustn't you ?

Open and save commands shouldn't work , so you need to a third party program to do processing on a list of drawing files .

Link to comment
Share on other sites

Excellent . You are most welcome .

 

 

 

 

You must be in need of running the program on many drawing files . mustn't you ?

Open and save commands shouldn't work , so you need to a third party program to do processing on a list of drawing files .

 

Exactly!

 

You know some?

Link to comment
Share on other sites

If you don't have that much of files to implement the program on , just add this (c:Test) to the program after the last parenthesis and add the lisp file to the briefcase of the appload command then just open the drawings you want to run the program in and the program should run automatically and do the job solely then just save and close the drawing to have the new changes saved .

Link to comment
Share on other sites

If you don't have that much of files to implement the program on , just add this (c:Test) to the program after the last parenthesis and add the lisp file to the briefcase of the appload command then just open the drawings you want to run the program in and the program should run automatically and do the job solely then just save and close the drawing to have the new changes saved .

 

Works perfectly:)

 

Tharwat, you made my day!

 

Thanks again!

Link to comment
Share on other sites

  • 1 year later...
Can this be modified to use in a field to get the current tab's name? The CTAB variable doesn't work with data extractions.

 

Try this mods.

(defun c:Test (/ doc )
 ;; Tharwat - 29.Nov.2016 ;;
 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
 (vlax-for x  (vla-get-layouts doc)
   (if (/= (vla-get-name x) "Model")
     (vlax-for b  (vla-get-block x)
       (and (eq (vla-get-objectname b) "AcDbBlockReference")
            (eq (vla-get-effectivename b) "TILTEBLOCK")
            (vl-some
              '(lambda (a)
                 (and (eq "LAYOUT" (strcase (vla-get-tagstring a)))
                   (progn
                     (vla-put-textstring a "%<\\AcVar ctab>%") t)
                   )
                 )
              (vlax-invoke b 'getattributes)
              )
            )
       )
     )
   )
 (vla-regen doc acAllViewports)
 (princ)
 )(vl-load-com)

Link to comment
Share on other sites

I'm not sure how to use it. I tried copying it into the diesel expression in the field, but it says invalid field code.

 

I have part files that use the layout name in the part name, so that the name is automated. However, when a data extraction is done, it only uses that last saved tab.

Link to comment
Share on other sites

Just be sure to copy all posted codes above to a new txt file and save it with an extension of .lsp then back to AutoCAD and type the command name: APPLOAD or AP then selected the lisp file, then finally type test to run the lisp routine and you should have the block name "TITLEBLOCK" modified with its related Layout name that is resides in.

Link to comment
Share on other sites

I'm trying to avoid user interaction. When the user/draftsperson creates a new part, I don't want to have to rely on that person to run the command. The part name attribute has the filename variable and CTAB variable plus an increasing number to identify the part. So if that part is in the VM file on the "3" tab the part would be VM-3-X, where the x is any number.

 

Your code extracts the layout name without the use of the CTAB variable, and I would like to put that into a field in a attribute, maybe via a diesel expression.

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