Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

combined ddedit & paste

10 REPLIES 10
Reply
Message 1 of 11
canuck7783
446 Views, 10 Replies

combined ddedit & paste

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.

10 REPLIES 10
Message 2 of 11
bhull1985
in reply to: canuck7783

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?

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 3 of 11
canuck7783
in reply to: bhull1985

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")
)

Message 4 of 11
bhull1985
in reply to: canuck7783

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..

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 5 of 11
canuck7783
in reply to: bhull1985

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.

Message 6 of 11
bhull1985
in reply to: canuck7783

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...

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 7 of 11
canuck7783
in reply to: bhull1985

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?

Message 8 of 11
canuck7783
in reply to: canuck7783

Just curious, is there a way to add coding to mock keystrokes in autolisp? 

Message 9 of 11
bhull1985
in reply to: canuck7783

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

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 10 of 11
canuck7783
in reply to: bhull1985

That works!!!  Thank you

Message 11 of 11
bhull1985
in reply to: canuck7783

You're welcome 🙂

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost