pman860507 Posted September 22, 2011 Posted September 22, 2011 from what i have read foreach works like this. Source: http://www.jefferypsanders.com/autolispintr_list.html#foreach Syntax : (foreach varName list yourFunctions) varName - Any valid variable name that you make up. list - Any valid list. yourFunctions - Any valid autolisp functions. (foreach a (list 1 2 3)(princ a)) prints 123 to the screen and returns 3 [same as (princ 1) (princ 2) (princ 3) except that it only returns the last value.] (foreach a (list 1 2 3)(princ (+ a 5))) prints 678 to the screen and returns 8 [same as (princ (+ 1 5)) (princ (+ 2 5)) (princ (+ 3 5)) except that it only returns the last value.] so why wont this work. (foreach a enlist (if (= 3 (car a)) (setq enlist (subst (strcase(cons 3 (cdr a)))(accoc 3 enlist)enlist)) ) ) I though it would go though every part of the dxf code. if the first part = 3 then a would = (3. "whatever is here") then it could run the other line making a capital text and placing it in back into the entity. Im trying to uppercase MTEXT that is over the character limit for (1 . "") i know you have the command _tcase and you can do it in the express tools but i want to do it like this. I can place my whole code if you need it. but this is just one part of it. It also converts attributes and text. Thanks. Quote
Lee Mac Posted September 22, 2011 Posted September 22, 2011 Other than the obvious that you have spelt 'assoc' as 'accoc': (foreach a enlist (if (= 3 (car a)) (setq enlist (subst (strcase(cons 3 (cdr a)))([color=red]accoc [/color]3 enlist)enlist)) ) ) The 'assoc' function will only return the first item with the associated key that it finds in the list, so in your case, always substituting for the first occurrence of the DXF 3 pair in the list. Consider this approach instead: (entmod (mapcar (function (lambda ( pair ) (if (member (car pair) '(1 3)) (cons (car pair) (strcase (cdr pair))) pair ) ) ) (entget <ename>) ) ) Quote
pman860507 Posted September 22, 2011 Author Posted September 22, 2011 another 2 function i really know nothing about mapcar and lambda. but it works thanks. but i also have a lower case command and i was thinking you just change this line. (cons (car pair) (strcase (cdr pair))) to (cons (car pair) (strcase (cdr pair)t)) but it doesnt work =( Quote
Lee Mac Posted September 22, 2011 Posted September 22, 2011 another 2 function i really know nothing about mapcar and lambda. but it works thanks. Maybe this will help with your understanding of mapcar/lambda. but i also have a lower case command and i was thinking you just change this line. (cons (car pair) (strcase (cdr pair))) to (cons (car pair) (strcase (cdr pair)t)) but it doesnt work =( That looks like it should work - what error are you receiving? Quote
pman860507 Posted September 22, 2011 Author Posted September 22, 2011 95% of the text is missing. And thanks for the link. Quote
Lee Mac Posted September 22, 2011 Posted September 22, 2011 95% of the text is missing. Are you dealing with Formatted MText? If so, this task is made 100x more difficult since the formatting codes are embedded in the text string. Quote
pman860507 Posted September 22, 2011 Author Posted September 22, 2011 Yeah i am. I was reading about that i figured it was part of the text string. Inside the entity. but it works fine to cap everything. Quote
Lee Mac Posted September 22, 2011 Posted September 22, 2011 but it works fine to cap everything. Sounds like you got lucky with that one Really, you would need to separate the content from the formatting codes, strcase the content, then reassemble - not an easy task. I toyed with formatting codes here and here. One possible route might be to use one of those functions to return the unformatted string, then use its content to strcase the correct parts of the formatted string. Quote
pman860507 Posted September 23, 2011 Author Posted September 23, 2011 Thanks for the links. might dig into it might not right now by looking at the code its way over my head! but i will look at it and try to figure it out. Quote
Lee Mac Posted September 23, 2011 Posted September 23, 2011 Thanks for the links. might dig into it might not right now by looking at the code its way over my head! but i will look at it and try to figure it out. I wouldn't hold it against you if you didn't pursue it... formatting codes are a PITA 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.