Reputation: 317
Is it possible to use local variables in dwg file and display them in text objects?
For example, I need to numerate objects starting with some value:
value0 = 5
value1 = value0 + 1
value2 = value0 + 2
etc...
Can I put value1 and value2 into some text object on my drawing?
Upvotes: 0
Views: 4304
Reputation: 1342
It would help to know what language you prefer to use. This is very easy to do using AutoLISP. Suppose you'd like a program to ask the user for a number, then proceed forward to increment that number and put the increments successively into drawing text (say lot numbers).
Here is a working and complete little sample of how you'd do something like this:
(defun c:consecunum ( / entget_in entsel_in value_in value_out)
(setq
value_in (getint "\nFirst number: ")
value_out value_in
)
(while (setq entsel_in (entsel (strcat "\nText to replace with \"" (itoa value_out) "\": ")))
(setq entget_in (entget (car entsel_in)))
(entmod
(subst
(cons 1 (itoa value_out))
(assoc 1 entget_in)
entget_in
)
)
(setq value_out (1+ value_out))
)
)
If you have any questions about how this works, don't hesitate to ask.
Upvotes: 1
Reputation: 757
User variables will certainly work. Be aware that they are limited in number and other programs may also set them without your knowing. If you want simple values to be be displayed as text AutoCAD can do that. The scope of variables is up to you and the api you choose. (VB, VBA, AutoLisp, .NET etc.) There are other data storage options available in the dwg file.
Upvotes: 2
Reputation: 809
To display an integer in a TEXT or MTEXT (or attribute) object you insert a field, select DieselExpression as the field type and then type your expression. You can do this for other data types as well.
There are various user variables available for the task. To achieve the above, type the following into the AutoCAD command prompt:
setvar useri1 5
(sets the value of user integer1 to 5)
Then you can use the following DieselExpressions in fields inside different text objects:
$(getvar, useri1)
(gets the value of useri1)
$(+,$(getvar,useri1),1)
(add 1 to the value of useri1)
$(+,$(getvar,useri1),2)
(add 2 to the value of useri1)
etc...
Upvotes: 1