TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pochrist on June 09, 2005, 11:46:42 AM
-
This Routine (Match Text) Allows me to match text strings like Match Properties does with colors. It works with/on Dtext, Mtext and Attributes.
It however does not work with the New Tables that Autocad has introduced in 2005. While updating some drawings I decided to convert our Schedules to Tables, but this routine doesn't work on Tables. I would like to Modify / update this routine to Include the editing of Tables into its capabilities. After studying the code I can't however determine where or how it can distinguish from Mtext, Dtext or Attibuted text. I thought I'd atleast find a Variable calling out (If you select an Mtext entity do Such and Such). Anyway if some could point me in the right direction I'd appreciate it.
**********************************************************
(defun C:Matchtxt (/ ent enttxt ent2)
(while (not ent)
(setq ent (ENTGET (CAR (NENTSEL "\nSelect needed text!"))))
)
(setq enttxt (cdr (assoc 1 ent)))
(setq ent2 T)
(while ent2
(cond
((setq ent2 (CAR (NENTSEL "\nSelect text to be changed!")))
(SETQ SAVENAME ENT2)
(SETQ ENT2 (ENTGET ENT2))
(setq ent2 (subst (cons 1 enttxt) (assoc 1 ent2) ent2))
(entmod ent2)
(ENTUPD SAVENAME)
)
((= (getvar "errno") 7)
(princ " Missed Selection. ")
(setq ent2 T)
)
(T (setq ent2 nil))
)
)
(princ)
)
***********************************************************
(Edit: MP fixed code formatting per this (http://www.theswamp.org/phpBB2/viewtopic.php?t=4429) post).
-
If you change the data the table is referencing can't you just update the table to reflect the change?
-
Table isn't "Referanceing" or linked to another file. It is a Indvidual enity filled with strings of Mext. We don't use Schedules that constantly get changed this schedule is Simply just Text in Boxes I re did it to make it easier to format.
-
oh, ok.
-
This will return the text string.
(if (setq ent (car (nentsel "\nSelect Table: ")))
(progn
(setq obj (vlax-ename->vla-object ent))
(princ (vla-get-Textstring obj))
)
)
-
Thanks Mark, I added the code to the Routine, and I can get to work in one direction ( I can pick the Text in the Table and "transfer" it another Text Entity, But I can't do the reverse (ie Mtext or Dtext to the Table).
Did I put it in the wrong spot or did I forget something. TIA
(defun C:Matchtxt (/ ent enttxt ent2)
(while (not ent)
(setq ent (ENTGET (CAR (NENTSEL "\nSelect needed text!"))))
)
(setq enttxt (cdr (assoc 1 ent)))
(setq ent2 T)
(while ent2
(cond
((setq ent2 (CAR (NENTSEL "\nSelect text to be changed!")))
(SETQ SAVENAME ENT2)
(SETQ ENT2 (ENTGET ENT2))
(setq ent2 (subst (cons 1 enttxt) (assoc 1 ent2) ent2))
(entmod ent2)
(ENTUPD SAVENAME)
)
(if (setq ent (car (nentsel "\nSelect Table: ")))
(progn
(setq obj (vlax-ename->vla-object ent))
(princ (vla-get-Textstring obj))
)
)
((= (getvar "errno") 7)
(princ " Missed Selection. ")
(setq ent2 T)
)
(T (setq ent2 nil))
)
)
(princ)
)
-
(if (setq ent (car (nentsel "\nSelect Table: ")))
(progn
(setq obj (vlax-ename->vla-object ent))
(vla-put-TextString obj "<string>")
(vla-update obj)
)
)
Try that.
-
Well I hate to report that the new code didn't change anything, which is kinda good cause It still does more then it did before. I'd assume that all these functions use the Clipboard to tranfer/duplicate the text. I know that the table supports Clipbord function between fields, which is why I'd like to use this Routine on them, it be much faster to click twice then do all the extra Crtl-C, Ctrl-V. TIA
-
Try a regen after you change the text.
I'd assume that all these functions use the Clipboard
Nope. You can however with DOSLib.
-
Ok this is what the Routine looks like:
(defun C:Matchtxt (/ ent enttxt ent2)
(while (not ent)
(setq ent (ENTGET (CAR (NENTSEL "\nSelect needed text!"))))
)
(setq enttxt (cdr (assoc 1 ent)))
(setq ent2 T)
(while ent2
(cond
((setq ent2 (CAR (NENTSEL "\nSelect text to be changed!")))
(SETQ SAVENAME ENT2)
(SETQ ENT2 (ENTGET ENT2))
(setq ent2 (subst (cons 1 enttxt) (assoc 1 ent2) ent2))
(entmod ent2)
(ENTUPD SAVENAME)
)
(if (setq ent (car (nentsel "\nSelect Table: ")))
(progn
(setq obj (vlax-ename->vla-object ent))
(vla-put-TextString obj "<string>")
(vla-update obj)
)
)
((= (getvar "errno") 7)
(princ " Missed Selection. ")
(setq ent2 T)
)
(T (setq ent2 nil))
)
)
(princ)
)
I tried regenerating after wards and here's what I get:
If I try to "Match text" from an Mtext Entity - After the regen the Value in the Field I pick changes to <string>
If I try to "Match text" from Field to Field - After the regen I get No change.
Maybe I formated it wrong? TIA
-
It seems to have slipped in the It has been fixed or the It Can't be Done catagory. :?:
-
I was hoping you'd fixed it. :)
try something like this; still need a regen after change text in a table.
(defun c:MatchText (/ GetText PutText copy_txt)
(defun GetText (/ ent)
(if (setq ent (car (nentsel "\nSelect text needed: ")))
(cdr (assoc 1 (entget ent)))
)
)
(defun PutText (cp_txt / ent entlst)
(if (setq ent (car (nentsel "\nSelect text tp be changed: ")))
(progn
(setq entlst (entget ent))
(setq entlst (subst (cons 1 cp_txt) (assoc 1 entlst) entlst))
(entmod entlst)
)
)
)
(if (setq copy_txt (GetText))
(PutText copy_txt)
)
(princ)
)
-
Try this:
; ReplaceText.lsp by J.J.Damstra
;
; 10-01-02 first release
; 15-04-05 UNDO GROUPING
(defun c:RT (/ TXT_STR ENTITY ENTITY_NAME ENTITY_LIST OLD_VALUE NEW_VALUE NEW_ENTITY_LIST BLOCKOBJ)
(command ".undo" "begin")
(setq ENTITY (nentsel "\nSelect source text: ")
ENTITY_NAME (car ENTITY)
ENTITY_LIST (entget ENTITY_NAME))
(if (and (= (cdr (assoc 0 ENTITY_LIST)) "MTEXT")(/= (cdr (assoc 3 ENTITY_LIST)) nil))
(progn (alert "Error: This string is to long.") (exit)); max. 250
)
(setq TXT_STR (cdr (assoc 1 ENTITY_LIST)))
(while (setq ENTITY (nentsel "\nSelect text to change: ")) ; NIL > WEND
(if (> (length ENTITY) 3)(setq BLOCKOBJ (car (last ENTITY)))(setq BLOCKOBJ nil))
(setq ENTITY_NAME (car ENTITY)
ENTITY_LIST (entget ENTITY_NAME)
OLD_VALUE (assoc 1 ENTITY_LIST)
NEW_VALUE (cons 1 TXT_STR))
(if (and (= (cdr (assoc 0 ENTITY_LIST)) "MTEXT")(/= (cdr (assoc 3 ENTITY_LIST)) nil))
(alert "Strange but true: This string is to long!\n(max. length = 250)")
(progn
(setq NEW_ENTITY_LIST (subst NEW_VALUE OLD_VALUE ENTITY_LIST))
(entmod NEW_ENTITY_LIST)
(if (setq ENTITY (cdr (assoc -1 ENTITY_LIST))) (entupd ENTITY))
)
)
(if BLOCKOBJ (entupd BLOCKOBJ))
)
(command ".undo" "end")
(princ)
)
-
Tried Both the Modified code by Mark and the Routine by Crank.
Mark
The code you had prior to this June 10th version did was half way there
From:
Dtext to Dtext, Attribute or Mtext = Fine
Attribute to Dtext, Attribute or Mtext = Fine
Mtext to Dtext, Attribute or Mtext = Fine
Table to Dtext, Attribute or Mtext = No Go
(Worked in the june 10th version TO Dtext, Attribute or Mtext but not from Table to Dtext, Attribute or Mtext.
When I try to take text from say an Mtext object I get "Missed Pick" and No change after regen either.
Crank same problem
Same problem minus the "Missed Pick" message
-
:?:
Are you sure? It works for me.
The only tables I have problems with are in (dynamic) blocks.
To edit those tables you can use BEDIT and then the function also works.
-
Are you sure? It works for me.
I think I see the problem...
I loaded a bland profile in Acad (ADT 2005) inserted a Standard Table put some text in the a field. Added some mtext and it does copy the text in or out of the table.
So does Marks.
So now I have to find out what is causing it. Thanks I'll report back When I figure it out.
-
1st I'm doing this all from a New Drawing in a Generic Profile - Then I try to use them in my Normal dwgs.
1) Both Marks & Cranks do the same things in the following areas. :arrow:
Yes the Text does copy from outside into a Table, But ONLY if the Font style in the table is set to "Standard". :?:
Here's where it gets interesting, If I Match / Replace text from a Mtext, Dtext, etc. source to a field in The table the text will only remain until I go to edit the field or the Table - then all the text that was changed gets undone back to what it was before. :shock:
Example (If I put a "X" in all the blank fields, I I Match / Replace to various text stings, if I try to edit ANY part of the table - ALL fields revert back to "X") Its Almost a Tease :wink:
At one point I Matched / Replaced text from 12 Mtext entities to 12 fields, I then tried edit the Table by right click - The whole table was selected but I couldn't get the Right click menu to come up. I Then went to the format menu and Modified the Font Style in the Table to my desired font style (Arial) and all the chnages were gone. :cry:
It Seems like some where its not saving the change to the Field but its kind of Temporary.
Thanks for all the Help, I hope this only a minor fix. TIA
-
Here's where it gets interesting, If I Match / Replace text from a Mtext, Dtext, etc. source to a field in The table the text will only remain until I go to edit the field or the Table - then all the text that was changed gets undone back to what it was before.
I experienced this as well....
-
I'd love to be able fix this routine myself or even Cranks for that matter,
I stand a much better chance solveing the problem if I can understand why its Not working....
Remeber I did ask for help not a hand out, I do try to follow it's command progression :?, but unlike most of my other routines its rather complex and or maybe most of my routines have text break downs explaing what each function is doing...
I really think its close to working, if the text would autually stay in the Table after I've accessed it would be nice... :wink:
Any help would be greatly appreciated.
-
Well I've spent about an hour trying to solve the problem. It seems you have to access the table via ActiceX in order to save changes. I haven't had any luck at this as of yet.
-
The same error happens when you try to change a dimension: it seems fine until you stretch that dimension.
In both cases the problem is that somehow the displayed MTEXT is changed, but not the real dimension or table. For a dimension you can use NEWTEXT to modify the value.
When I tried to change the DXF-codes of the table, I found out that it's almost impossible to find the right cell data, so I wanted to try a different approach:
Because you know the position of the selected mtext you can also edit the cell on that location:
(setq p1 (cadr (nentsel))); Find position of text in table
(command ".tabledit" p1 "New_text"); place the new string
The problem with this is that I had no luck with removing the existing text. The new string is placed before the existing string, so the cell must be cleared first.
If you first can add CTRL+A or SHIFT+END in the keyboard buffer it should work, but I didn't have any luck with that.
Of course you can make some sort of 'work around':- First add a unique string before the cell text with tabledit.
- Then you can seach in the dxfcodes for a string that contains this unique part and replace this text with the new text.
- ENTUPD on the table
[/list:u]
I know: this isn't pretty, but it should work.
Perhaps someone else has a better idea.
-
; ReplaceText.lsp by J.J.Damstra - Copyright ©2005.
; Replaces any selected string for another
; 21-06-05 first release
; 09-07-05 tableindicator
(defun c:rt (/ ch_txt ENTITY ENTITYLIST TXT_STR OBJECT pickpnt E-TYPE n ti)
(defun ch_txt (TXT_STR ENTITY / ENTITYLIST OLD NEW ENT)
(setq ENT (car ENTITY)
ENTITYLIST (entget ENT)
OLD (assoc 1 ENTITYLIST)
NEW (cons 1 TXT_STR)
ENTITYLIST (subst NEW OLD ENTITYLIST))
(entmod ENTITYLIST)
(entupd ENT)
)
(command ".undo" "begin")
(setq ti (getvar "TABLEINDICATOR"))(setvar "TABLEINDICATOR" 0)
(setq ENTITY (nentsel "\nSelect source text: ")
ENTITYLIST (entget (car ENTITY))
TXT_STR (cdr (assoc 1 ENTITYLIST)))
(while (setq ENTITY (nentsel "\nSelect text to change: ")) ; NIL > WEND
(if (> (length ENTITY) 3) ; insert/dimension/table
(progn
(setq OBJECT (car (last ENTITY))
ENTITYLIST (entget OBJECT)
pickpnt (cadr ENTITY)
E-TYPE (cdr (assoc 0 ENTITYLIST)))
(cond
((= E-TYPE "INSERT")
(ch_txt TXT_STR ENTITY)
)
((wcmatch E-TYPE "*DIMENSION")
(command ".dim1" "newtext" TXT_STR OBJECT "")
)
((= E-TYPE "ACAD_TABLE")
(command ".tabledit" pickpnt "@#@")
(setq ENTITYLIST (entget OBJECT))
(foreach n ENTITYLIST
(if (eq (car n) 1)
(if (eq (substr (cdr n) 1 3) "@#@")
(entmod (subst (cons 1 TXT_STR) n ENTITYLIST))
)
)
)
)
)
(entupd OBJECT)
)
; else
(ch_txt TXT_STR ENTITY) ; text/mtext/attribute
)
)
(setvar "TABLEINDICATOR" ti)
(command ".undo" "end")
(princ)
)
-
Crank you Nailed it! :dood:
That's Exactly what I was looking for, :D
As for copying text into an empty field 1st, No problem, that's easy, its what you did with the routine that's the hard thing.
Even does Dimensions, that's impressive I've wanted that ability for a while, but I never thought it a real "Need" so I lived without. Thanks alot this is some Nice code. It should be placed in the "Show your stuff section" IMHO
-
Made some minor changes to it.
[...]
As for copying text into an empty field 1st, No problem, that's easy[...]
You can also click on the border of an empty cell to place the new text in it.
[...]
Even does Dimensions, [...]
It also works on a nested attribute or (m)text in a block.