AutoCAD/Adding formulas in an Autocad Field
Expert: Bill DeShawn - 4/30/2010
QuestionBill, I was reading about your work and hope you can help me.
I use Autocad 2008 and yesterday I found up the FIELD command and thought it could help me so much because I always extract text and numbers from my model.
Imagine I have a MTEXT which contentīs is "500-DIT-001" (itīs an equipment) and i want to generate its cable named 500DIT001-P, so I use the FIELD command to extract the MTEXT CONTENT.
FIRST QUESTION:
Can I change the " _Object ID" relatet to the MTEXT?
-I was reading some posts and says that the Object ID sometime changes when Autocad is closed and openned several times, still not happened to me but I just wanna be sure-
SECOND QUESTION:
Once I got the content from the Mtext using the field command, I want to eliminate or replace the "-" with blank spaces or a hollow, is that posible?
Iīd be glad and pleased with your answer.
Thanks for all
Antony Chumpitaz
ANSWER: I'm going to try to get more information on this topic, but until then, here is a routine that you can use to change characters like "-" to " " or whatever. It will change only the first encounter of the string you want to change, though. So you will need to type in something like "-DIT-" for the original string and then " DIT " for the replacement string. I'm not sure if this will work in fields. I haven't tried that. But it works with regular MTEXT and TEXT.
Here is the LSP file:
http://my.sterling.net/~bdeshawn/td.lsp
Check back for follow-ups.
Bill DeShawn
http://my.sterling.net/~bdeshawn
---------- FOLLOW-UP ----------
QUESTION: Thank you Bill, that LSP routine helped so far, but itīs too general.
Please let me know if you can find out another solution.
Sincerelly
Antony Chumpitaz
AnswerAntony:
I posted these questions to the AutoCAD 2008 Autodesk discussion group on 4/29/10, and still have no response. I will attempt to answer these two questions myself.
1. I am able to get a list of components and properties of MTEXT via LISP. The list looks like this:
((-1 . <Entity name: 7ed24230>) (0 . MTEXT) (330 . <Entity
name: 7efd0d18>) (5 . 2B6) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 .
MTEXT) (100 . AcDbMText) (10 538.269 558.503 0.0) (40 . 4.0) (41 . 424.757) (46
. 0.0) (71 . 1) (72 . 5) (1 . The quick brown fox jumps over the lazy dog.) (7
. NOTE) (210 0.0 0.0 1.0) (11 1.0 0.0 0.0) (42 . 147.422) (43 . 5.86667) (50 .
0.0) (73 . 1) (44 . 1.0))
I would equate the "_Object ID" that you mention, with the <Entity name: 7ed24230> in the list above. I may be wrong, but I would think that the only way the entity name can be changed is if there was an error in the drawing and you needed to fix the drawing, so you either ran AUDIT in the drawing or RECOVER to open the drawing. Then the objects (entities) could then be named over again, thereby possibly changing names of some or all of the entities. Extended entity data can be added to an object with LISP or with XDATA (also see XDLIST).
2. When you extract data, you most often want to place it in another application. Within most applications Ctrl+H starts a "find and replace" dialog. It is there than you can replace one character with another in a string. Sometimes, though it is a little tricky to get the right replacement string defined. After a while, though, you can get pretty good at choosing how much of the string to replace.
It is good that you did not make this message private. I invite others that may read this message to pitch in with their comments on this subject.
Bill DeShawn
http://my.sterling.net/~bdeshawn