Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update "DATE" field via lisp routine

Status
Not open for further replies.

victoriaair

Technical User
Sep 13, 2010
10
US
Since this thread has been closed:

I'm needing assistance to have our date field updated automatically.
What I have done is used a date field and I have to manually update this field to show the current date. This lisp routine looks like a time saver but I'm having issues using it.
Please help.
 
Since you're using a field then you'd use a somewhat different approach.

According to help, "Note-The Date field is updated by UPDATEFIELD, but it is not updated automatically based on the setting of the FIELDEVAL system variable."

How/when would you want this field/date updated? Is this for one particular drawing, or for many drawings, and a common block, or...
A routine could be made that is initiated with a command; or on opening a file. If you wanted it updated automatically upon, say plotting, I believe it would take a reactor.
 
Yes, you are correct the UPDATEFIELD is not automatic.
Whenever a new drawing is open I would like our print-status date to be updated.
We send updated prints to our PM's and field hands and the print status date shows them the latest drawing they need to be referring to.
It would multiple drawings at certain times.
We have a template setup and this date would be in this template.
Reactor? Please elaborate more . . .
 
If the date needs to be updated just when you open the drawing, I believe that can be handled with come code in acad.lsp or acaddoc.lsp file, rather than using the reactor method. A reactor is code that is executed upon some event, such as when a certain command is issued, the reactor code would fiirst be executed.

So back to your template, I assume this is a block with attributes, or a separate mtext field? How do you manually update the date, do you run UPDATEFIELD and select this block? I'm thinking the lisp routine would duplicate the manual method, except the block name would be provided in the code. This code would be executed on opening a drawing, so it runs automatically.
 
Yes, it is a block with multiple attributes. To update the fields we normally just double click the TB and it opens the enhanced attribute editor.
I'm following you so far :) . . . .
Thats why I thought the link I provided would help, it could either run automatically (which I prefer) or run as a lisp routine and we key it in.
Thanks in advance!
 
Try the following lisp routine..once we get it working it could be placed in acad.lsp file & modified to run upon opening a drawing.

Code:
(defun c:upd ()
  (setq tb_set (ssget "_X" (list '(0 . "INSERT") (cons 2 "Title_block_name_here"))))
  (if tb_set
      (command "._UPDATEFIELD" (ssname 0 tb_set) ""))
   )
   (princ)
)

Modify code above to replace "Title_block_name_here" with the titleblock's block name. Save the text to a text file, save with any desired name with a ".lsp" extension. Load the lisp, run it by typing "upd". (alternatively for testing purposes could copy & paste the code to the command line)

 
It worked, although I did get an error message. I had to manually select the field.
It will do the same thing if I was to type in updatefield.
But I guess like you said, we can tweek this lisp so it will run upon opening a any drawing everytime. Even any previous saved drawing(s)?
See attached file for reference
 
 http://www.mediafire.com/file/d52f9n82zbbl7ej/UPD.png
OK as usual I had some typos..I actually tested the following code:

Code:
(defun c:upd ()
(setq tb_set (ssget "_X" (list '(0 . "INSERT") (cons 2 "block_name_here"))))
(if tb_set
(command "._UPDATEFIELD" (ssname tb_set 0) "")
)
(princ)
)
 
Now it doesnt update any fields?

[Command: upd
._UPDATEFIELD
Select objects: 1 found

Select objects:
0 field(s) found.
0 field(s) updated. ]

Any ideas?
 
Hmmm, don't know offhand,as it worked for a simple test block, single attribute with a "date" field.
Looks like the block is getting selected but the field is not found/updated. Are you sure the date field is really an attribute versus some stand alone mtext field? If this is the case, the code could change to select all mtext:



Code:
(defun c:upd ()
  (setq mt_set (ssget "_X" '((0 . "MTEXT"))))
  (if mt_set
     (command "._UPDATEFIELD" mt_set "")
  )
  (princ)
)
 
the title block is an attribute and the actual date field is single text converted to a date field. Sorry if I didnt iterate that correctly.
Could the lisp you provided read within the attribute which tag to change? If so, that would be great. Because the title blocks tags can all stay as one attribute block and the lisp could read withing the block and look for the date tag and update that?
 
For some reason that link doesn't wotrk for me.
What would be most helpful would be if you could send me a drawing,

c a b AT e e i t e a m DOT c o m
 
OK I saw the second link...
1. Seeing it is a block with attributes it should have worked if you edited the code for block name
(0 . "INSERT") (cons 2 "Vac Title Block_Original")

2. In the editor dialogue box at the link, no "value" is shown for he "date" tag, is that correct? With my test the last updated date would show up as the value.
 
Here's what i have.
The Template dwt
Title block is inserted into the paperspace as an insert,
within the actual template. This is kept as a block and not exploded.
Now the statusdate in the title block has a date field in it. I dont update the title block's statusdate but I update the date field with "UPD".
It ask for me to select it and it will change.
So, what i did was revert back to our original TB and removed the date field from the template so I could update the statusdate within the title block.
The command line prompts me this:
Command: upd
._UPDATEFIELD
Select objects: 1 found
1 was not in current space.
 
From that last message, sounds like you ran "upd" while in MS, but the block is in PS? Any difference if you run it from PS?

I really need to sse the setup, I'd be gals to look at if you email me an example drawing to address I posted above.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top