Jump to content
gamulj

Lisp for Layout name to block attribute

Recommended Posts

gamulj

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!

Share this post


Link to post
Share on other sites
Tharwat

Yes it is possible .

 

What is the name of your attributed title block ?

Share this post


Link to post
Share on other sites
gamulj
Yes it is possible .

 

What is the name of your attributed title block ?

 

Hi Tharwat!

 

The name of block is TITLEBLOCK.

Share this post


Link to post
Share on other sites
Tharwat

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)


Share this post


Link to post
Share on other sites
gamulj

I will try,

Thanks!

Share this post


Link to post
Share on other sites
Tharwat
I will try,

Thanks!

 

Okay , I will be waiting for your try and reply .

Share this post


Link to post
Share on other sites
gamulj

Works great!

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

 

Thanks a million!!!

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Tharwat

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 .

Share this post


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

Share this post


Link to post
Share on other sites
Tharwat
Works perfectly:)

 

Tharwat, you made my day!

 

Thanks again!

 

You are most welcome . :thumbsup:

Share this post


Link to post
Share on other sites
ramcharger318

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.

Share this post


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

Share this post


Link to post
Share on other sites
ramcharger318

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.

Share this post


Link to post
Share on other sites
Tharwat

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.

Share this post


Link to post
Share on other sites
ramcharger318

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.

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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