Please help.
I am attempting to automate the process of adding invisible attributes to all blocks in a dwg file. The goal is just to create the attribute definition for editing later in the routine. Is anyone willing/able to point me in the correct direction? Is AutoLISP the best option for this job?
Solved! Go to Solution.
Solved by ВeekeeCZ. Go to Solution.
Solved by john.uhden. Go to Solution.
Your timing is good. A similar topic was just recently discussed.
(defun c:AddAtts ( / ss i blk blks def AttObj) (and (setq ss (ssget '((0 . "INSERT")))) (setq i (sslength ss)) (while (> i 0) (setq blk (cdr (assoc 2 (entget (ssname ss (setq i (1- i))))))) (if (not (vl-position blk blks))(setq blks (cons blk blks))) ) ) (foreach blk blks (setq def (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blk)) (setq AttObj (vla-addattribute def 8 ;; height acAttributeModeInvisible "YOUR PROMPT" (vlax-3D-point 72 84) ;; location "YOUR TAG" "YOUR DEFAULT VALUE" ) ) (vlax-put AttObj 'Alignment acAlignmentmiddle) ;; 4 ;(command "_.attsync" "_N" blk) ) (princ) ) (vl-load-com) (princ)
John F. Uhden
Thank you,
I am having some issues getting this to work. "Automation Error. Invalid argument Tag in setting TagString" that I cant seem to clear up without creating more issues. I am sure it's simple to fix but i am new to VLA.
Your response has certainly pushed me in the right direction. Do you have a link to the similar topic you mentioned?
The help file seems to indicate -AddAttribure parameters should look more like:
Height = 8#
Mode = acAttributemodeinvisible
etc.
any additional nudge in the right direction would be greatly appreciated.
Yes, the help is instructing you as to what each argument is for, but you're not supposed to include any Basic-looking statement like "Mode = ."
I actually tested it in my 2002 and it works just fine (except for "attsynch" which I don't have.
What did you change in the code I gave you? You can't use empty strings "" for the tag, prompt, or value. Did you remember the quotation marks?
John F. Uhden
Also, if you want that height to be 8, do not use 8#. That would represent a symbol name (that probably hasn't been set).
Use just an integer, like 12, or a real, like 12.0.
Though if you want to use a symbol name for something you have set earlier in the program, that's ok too.
F'rinstance
(setq Ht (getvar "textsize"))
Then you could replace 8 with Ht.
John F. Uhden
When I copy paste the code provided above with no changes it loads fine and errors out when run:
load
Command: _appload tmp.lsp successfully loaded.
Run before selection:
Command: ADDATTS
Select objects: 1 found
Select objects: 1 found, 2 total
Select objects:
*Cancel*
Automation Error. Invalid argument Tag in setting TagString
select block(s) and run:
Command: Specify opposite corner or [Fence/WPolygon/CPolygon]:
Command: ADDATTS
1 found
*Cancel*
Automation Error. Invalid argument Tag in setting TagString
select non-block and run:
Command: ADDATTS
0 found
I started playing with a few things but if the code should work on its own then something must be wrong on my end. I am attempted to run in AutoCad 2014 and 2014 MEP
@Anonymous:
Looks like either you copied and pasted maybe not the whole thing, or maybe what works in 2002 doesn't work in 2014 MEP.
Are you sure that tmp.lsp is actually my code, as below again? It might be that you have another tmp.lsp that you are loading.
At the command prompt, enter (findfile "tmp.lsp") and see what folder it points to. Then open the file (in like NotePad) and see if it is the same as I have posted (ignore the blue color you see here as the color doesn't matter). I don't know what else to tell you.
@Kent1Cooper, @ВeekeeCZ, @dbroad: Could you please try my code and indicate what release(s) you used? Many thanks.
(defun c:AddAtts ( / ss i blk blks def AttObj) (and (setq ss (ssget '((0 . "INSERT")))) (setq i (sslength ss)) (while (> i 0) (setq blk (cdr (assoc 2 (entget (ssname ss (setq i (1- i))))))) (if (not (vl-position blk blks))(setq blks (cons blk blks))) ) ) (foreach blk blks (setq def (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blk)) (setq AttObj (vla-addattribute def 8 ;; height acAttributeModeInvisible "YOUR PROMPT" (vlax-3D-point 72 84) ;; location "YOUR TAG" "YOUR DEFAULT VALUE" ) ) (vlax-put AttObj 'Alignment acAlignmentmiddle) ;; 4 ;(command "_.attsync" "_N" blk) ) (princ) ) (vl-load-com) (princ)
John F. Uhden
Thanks again for all your help.
No luck so far on 3 machines but I have not tried any version older than 2014.
I am not able to find an issue but I first learned Lisp on R12 in high-school(i'm not that old but the school didn't update often) and I haven't used it much in the interim. Maybe something changed between 2002 and 2014
_$ (findfile "test.lsp")
"C:\\Users\\nicrfe\\Documents\\test.lsp"
Your code is perfect... on a much older version. I was able to find someone with autocad 2002 and I confirmed it. In other good news i was able to successfully run some of the code i wrote also!! It looks like we are both behind time times.
Can anyone chime in to point me in the direction of the changes that need to be made to make this code compatible with modern releases?
Can't find what you're looking for? Ask the community or share your knowledge.