Trying to make a simple lisp program but I am really new to this. Any help would be greatly appreciated. My goal is to type EE on my keyboard in autocad (version 2014) and it combines the ddedit command and paste command all in one. Thank you if anyone can help me.
That is somewhat difficult to understand your intentions there..
Are you wanting to PASTE(clip) a block into the dwg and then immediately ddedit the same object?
Right now I have to go into hundreds of drawings and change a job number. So I'm doing that by using DDEDIT and then hitting ctrl+v. When doing this so many times, i was wondering if i can just combine the two commands. So when I use a new quick key command like "EE" and click on the text i want to change it will automatically DDEDIT and then paste what i currently have on my clipboard.
This is what i have so far. It's not much
; ---------------------------EDIT PASTE--------------------------
; EDIT A TEXT AND PASTE WHATEVER'S IN CLIPBOARD
; ----------------------------------------------------------------
(Defun C:EE ()
(command "DDEDIT")
)
So you're just modifying the attribute value of a block?
That'd be accomplished in another method than ddedit+pasteclip, what you can do instead is get the dxf group codes for the attributed block, find the correct att tag, modify it!
Can you upload a title block empty save for the attribute you're modifying?
This would allow me to show you how to do that..
Unfortunately the text is not part of a block (it was never set up like that at the beginning). It is a single line text that has to be manually selected to edit for the new job number.
Oh that's rough, I see.
Well you'd still (entget ent) where ent is your text object, find the dxf that has the value, subst for your new string value and entmod or entupdate.
Here's a similar example.
(defun c:Test (/ ss l sset str e) (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) (repeat (setq l (sslength ss)) (setq sset (ssname ss (setq l (1- l)))) (setq str (cdr (assoc 1 (setq e (entget sset))))) (entupd (cdr (assoc -1 (entmod (subst (cons 1 (strcat str "cm")) (assoc 1 e) e)) ) ) ) ) (princ) ) (princ) )
Tharwat created this routine for someone, to add "CM" to their text.
If you locate the portion where the code goes (entmod (subst (cons 1 (strcat str "CM"))...this is the portion you'd want to modify.
Actually, this routine is built for multiple text strings to change them all at once but I think with 1 item it'd do the same. Just a bit longer way to go about it, but was the first one I've found 😛
Where it goes (strcat str "cm") you can just add your string like "Here is what I need it to read now" after the (cons 1...
This is close. Except it doesn't delete/replace the original text. It just adds to it. This code will work if i can replace the CM within the coding with the job number I need. Is there a way to modifiy the code to delete the original?
Just curious, is there a way to add coding to mock keystrokes in autolisp?
Try this
(defun c:Test (/ ss l sset str e) (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) (repeat (setq l (sslength ss)) (setq sset (ssname ss (setq l (1- l)))) (setq str (cdr (assoc 1 (setq e (entget sset))))) (entupd (cdr (assoc -1 (entmod (subst (cons 1 "your drawing number goes here") (assoc 1 e) e)) ) ) ) ) (princ) ) (princ) )
untested
You're welcome 🙂