Hey all, been busy with client work for the last few weeks but i've still been tinkering with code when I can.
Recently we've made a change to remove spaces from our instrument bubble attribute defaults.
For whatever reason (perhaps an indent, or perhaps an extra tab, or software issues) there are leading spaces in each of the 4 attribute VALUES that i've removed from the new bubbles coming in, but i'm trying to find the best way to go back and remove all of those spaces from the instrument bubbles that are already within dwgs.
Simply doing a (command "insert" "ce001=") followed by an attsync does not work, unfortunately.
Here , let me show the problem.
So quite simply I just wish to remove those leading spaces (that you can tell are there by the blue bar in the value field, that's from spaces, as if it's been selected by ctrl+a from within the attribute editor. A count of left-arrow move-overs tells me that there are 6 spaces in these fields, but the code should be able to handle a variable amount of spaces.....in fact i think telling it an amount of spaces as in (eq " " attval) probably is not the best way, only problem is i need someone to show me what the better method would be 🙂
(vl-load-com) (if (setq ss (ssget "x" (list (cons 0 "INSERT") (cons 2 "ce001")))) (progn (setq ind (sslength ss)) (repeat ind (setq ind (1- ind) ent (ssname ss ind) obj (vlax-ename->vla-object ent) attval (mapcar '(lambda (x) (vla-get-TextString x)) (vlax-invoke (vlax-ename->vla-object ent) 'GetAttributes)))
This is as far as I've gotten, and it returns the attval variable as the following, on my sample block shown in the image above:
("FE" "" " " " ")
so i've got a list with all of the values assigned to a var. Just need to know the best way to remove spaces. I've looked into Lee Mac's functions but just nothing seems to work with varying amounts of empty strings (well, strings of only spaces). The logic would be....
If an element contained within the list of attribute values does not have an actual letter/number text value and is only spaces, then to replace that value with an empty string i.e. "", just as if it's been created but has not had any information put into it, INCLUDING SPACES.
I've tried varying methods such as...
(if (eq " " att)(lm:vl-setattributevalue obj (vla-get-tagstring att)))
(if (eq " " (nth 1 attval))(lm:vl-setattributevalue obj "TAG10" ""))
(if (eq " " (nth 2 attval))(lm:vl-setattributevalue obj "TAG20" ""))
(if (eq " " (nth 3 attval))(lm:vl-setattributevalue obj "TAG30" ""))
that just aren't working too well and rather than bang my head i thought i'd just ask for clues.
Thanks!
Solved! Go to Solution.
Solved by Gary_J_Orr. Go to Solution.
True, but I was hoping to just run a lisp by clicking a button each time I incidentally go into the dwgs, this isn't a huge priority.
Q:
Once i have the values (vl-trimmed),
how do I actually set them?
(defun test (/ )
(vlax-for Obj
(vla-item
(vla-get-blocks
(vla-get-ActiveDocument
(vlax-get-acad-object))) "ce001")
(setq lst (cons Obj lst))) lst)
(foreach att lst
(setq attd (vl-string-trim " \t" att))(vla-put-textstring att attd))
returns nil and doesn't change the attributes on block ce001 😞
bhull,
You posted different attempts... your original post that searched for a specific block name, thenyou were trying to get all blocks (but you went the wrong way with that one by searching the blocks table...)
Here is what you are trying to get at I believe:
(vl-load-com) (defun RemoveSpacesFromAttributes (BlockName / ss ind ent obj AttbCol Textstr) (if (= nil BlockName) (setq ss (ssget "_X" (list (cons 0 "INSERT")))) (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 BlockName)))) ) (setq ind (sslength ss)) (if (> ind 0) (repeat ind (setq ind (1- ind)) (setq ent (ssname ss ind)) (setq obj (vlax-ename->vla-object ent)) (setq AttbCol nil) (if (= :vlax-true (vla-get-hasattributes obj)) (progn (setq AttbCol (vlax-safearray->list (vlax-variant-value (vla-getattributes obj))) ) (foreach AttObj AttbCol (setq Textstr (vla-get-textstring AttObj)) (setq Textstr (vl-string-trim " \t" Textstr)) (vla-put-textstring AttObj Textstr) );foreach );progn );if has attributes (vla-update obj) );repeat ) );defun
With this function you can call it two different ways:
process all blocks (inserts)
(RemoveSpacesFromAttributes nil)
process specific blocks (inserts)
(RemoveSpacesFromAttributes "BlockName")
If you will notice, I spread all of the functions out into a "line-by-line" approach. This allows me to work out the issues one at a time. AFTER I get the function to work, then I'll start in on Lambda and mapcar and apply to optimize the function if need be for speed or whatever other concerns.
The "(setq AttbCol...)" call was actually created one line at a time while I was building the function so I could inspect each return value for what was needed on the next call but I ended up combining them in this solution, shame on me.... but I left the rest so you could see how it steps into the required subfunctions.
Happy "Lisping"
Gary
Thank you very much.
I had pieces of it correct but wasn't able to pull it together.
Much appreciated!