Strydaris Posted July 9, 2024 Posted July 9, 2024 Hey everyone, I am pretty sure this is fairly easy but I can't seem to figure it out. So I have a small LISP to change the text inside an attribute. I want to take it and modify it so that I can use a Tool Palette to add different default edits as buttons. Inside the LISP I know I would have to modify the.... (defun c:ModAtt ( /string ) to be (defun c:ModAtt ( string / ) The part I dont get is how do you set up the macro in the tool palette. I tried ModAtt Testing, (ModAtt Testing) and (c:ModAtt Testing) None seem to work. Anyone have some insight into this? Quote
Lee Mac Posted July 9, 2024 Posted July 9, 2024 (edited) It's difficult to advise whether your proposed solution of simply changing the local variable to a parameter is correct without seeing the code for the ModAtt function. Assuming that your change is valid, you can remove the "c:" prefix from the function symbol (since the function will no longer be able to be called from the command line as a single parameter is required); you can then call the function with the string parameter from your tool palette using: (ModAtt "Testing") Edited July 9, 2024 by Lee Mac Quote
Strydaris Posted July 9, 2024 Author Posted July 9, 2024 @Lee Mac Hi Lee, its a simple LISP solution. Basically I am hoping this update will be useful for quicker editing of items from consultants, but was also hoping to use the same lisp for manual edits that can be repeated. ie Hit the Tool Palette button for a preset default piece of text OR call the command for a custom edit. (defun newattval ( newstr / ) (if (= newstr nil) (setq newstr (Getstring "\nType new string: ")) ) (setq obj (vlax-ename->vla-object (car (nentsel "Pick attribute: ")))) (vla-put-textstring obj newstr) ) Quote
Lee Mac Posted July 9, 2024 Posted July 9, 2024 (edited) For your case, I might suggest the following code: (defun c:newattval ( ) (setattval (getstring t "\nSpecify new content: ")) ) (defun setattval ( str ) (if (setq ent (selectattrib "\nSelect attribute: ")) (vla-put-textstring (vlax-ename->vla-object ent) str) ) (princ) ) (defun selectattrib ( msg / ent ) (while (progn (setvar 'errno 0) (setq ent (car (nentsel msg))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null ent) nil ) ( (/= "ATTRIB" (cdr (assoc 0 (entget ent)))) (princ "\nThe selected object is not an attribute.") ) ) ) ) ent ) (princ) Then, you can either call newattval directly at the command line, or call setattval in your tool palette using: (setattval "Testing") Though, I would have expected your original code to still work when called with a string argument. Edited July 9, 2024 by Lee Mac Quote
Strydaris Posted July 9, 2024 Author Posted July 9, 2024 @Lee Mac Thanks very much. I was searching around and found something similar, but didnt know exactly how to apply it. I mean its a simple solution but something I need to learn more about. Thanks again. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.