TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: fabcad on October 26, 2011, 04:18:43 AM
-
Hello,
How to Populates a selected attribute with a Field referencing the date.
Syntax of the date field :
%<\AcVar Date \f "d MMMM yyyy">%
Thanks,
-
If you want to add that through lisp, then you need to escape the special characters such as backslash and double quote with a preceding backslash. The easiest way I know to get this is to use the getstring method. Copy the following to your command-line:
(getstring t "Paste string: ")
Then paste the text you want into that. It should return the string with the needed escapes:Command: (getstring t "Paste string: ")
Paste string: %<\AcVar Date \f "d MMMM yyyy">%
"%<\\AcVar Date \\f \"d MMMM yyyy\">%"
Then you need to set the text/attrib/etc.'s text value to that string. Either using the dxf data list as obtained from entget and then subst a new (1 . "new string") for the old (assoc 1 dxflist), then use entmod to modify to match the new DXF list. Or using the vla-object of the text/attrib and setting its TextString property to the new string.
There's pro's and con's to both: The entmod screws up with annotative text - so try to remove stuff like height & width when using this. The vla method has trouble with UniCode characters.
-
Thanks irneb,
The syntax is correct, the field fills with the date but displays # # # # instead. But by updating the field by the AutoCAD command, the date is displayed.
What should I add to prevent the manual update of the field in question.
thank you,
-
You could choose any of several ideas: e.g. issue the UdpateField command through the lisp function; issue a regen command; use the vla-RegenAll function on the current view; etc. Generally I simply do a regen when I've added field codes.
I think if you go with the vla method you need not go through this scenario, though I can't remember. You might need to check.
-
If you want to add that through lisp, then you need to escape the special characters such as backslash and double quote with a preceding backslash. The easiest way I know to get this is to use the getstring method.
I find it easiest to just create the field in a piece of text then use (vla-getfieldcode (vlax-ename->vla-object (car (entsel)))) to extract. Very little legwork.