Lee Mac Posted October 1, 2009 Posted October 1, 2009 It should remove it if the suffix is there - only drawback is if you have it duplicated, i.e. (vl-string-right-trim "Mac" "LeeMacMac") "Lee" But it seems to remove it fine for me It is case-sensitive though Quote
alanjt Posted October 1, 2009 Posted October 1, 2009 Nice idea Alan - hadn't thought of it... but then I did say "lazy man's way"... His question about removing a suffix made me think of it. Seemed a pretty good method to me, minus the while. Quote
Lee Mac Posted October 1, 2009 Posted October 1, 2009 His question about removing a suffix made me think of it. Seemed a pretty good method to me, minus the while. True - I wanted to filter bad characters, but the snvalid means that no spaces can be used - perhaps take out the while. Quote
alanjt Posted October 1, 2009 Posted October 1, 2009 True - I wanted to filter bad characters, but the snvalid means that no spaces can be used - perhaps take out the while. I just don't like that the user is forced to hit escape. I'd just rather use and and if the user types in crap, it just exits. (defun c:laysuff (/ suff doc) (vl-load-com) (cond ((and (setq suff (getstring "\nSpecify Suffix for all layers: ")) (snvalid suff) ) ;_ and (vla-StartUndoMark (setq doc (vla-get-ActiveDocument (vlax-get-acad-object) ) ;_ vla-get-ActiveDocument ) ;_ setq ) ;_ vla-StartUndoMark (vlax-for lay (vla-get-layers doc) (or (wcmatch (strcase (vla-get-name lay)) (strcase (strcat "*" suff))) (vl-catch-all-apply 'vla-put-Name (list lay (strcat (vla-get-Name lay) suff)) ) ;_ vl-catch-all-apply ) ;_ or ) ;_ vlax-for (vla-EndUndoMark doc) ) ) ;_ cond (princ) ) ;_ defun Quote
JeepMaster Posted October 1, 2009 Posted October 1, 2009 True - I wanted to filter bad characters, but the snvalid means that no spaces can be used - perhaps take out the while. I think my problem is when the character is "-". So if I want to remove "-EXST" it doesn't work, but it works if I remove "EXST". Then my layers will be like this "E-TEXT-" Quote
JeepMaster Posted October 1, 2009 Posted October 1, 2009 Ok, I've been doing some testing and result is very weird. Let say layers are as follows: "Layer1" "Layer11" "Layer111" Then I add suffix "-1" to all of them. It works fine. "Layer1-1" "Layer11-1" "Layer111-1" Now if I try to remove the suffix "-1" and the result is this: "Layer" "Layer11-1" "Layer111-1" It removed the "1-1" from the first layer and ignored the other two layers. I have no idea what's going on. Does this happen to you guys??? Quote
alanjt Posted October 1, 2009 Posted October 1, 2009 Ok, I've been doing some testing and result is very weird. Let say layers are as follows: "Layer1" "Layer11" "Layer111" Then I add suffix "-1" to all of them. It works fine. "Layer1-1" "Layer11-1" "Layer111-1" Now if I try to remove the suffix "-1" and the result is this: "Layer" "Layer11-1" "Layer111-1" It removed the "1-1" from the first layer and ignored the other two layers. I have no idea what's going on. Does this happen to you guys??? Yeah, I just noticed the same thing. I tried to remove "-TEXT" on several layers and it worked, but it also removed the T from layers that just ended in T. Quote
alanjt Posted October 1, 2009 Posted October 1, 2009 What about something like this? (defun c:RemSuff (/ suff doc name) (vl-load-com) (while (not (and (setq suff (getstring "\nSpecify Suff to Remove: ")) (snvalid suff) ) ;_ and ) ;_ not (princ "\n** Invalid Suffix **") ) ;_ while (vla-StartUndoMark (setq doc (vla-get-ActiveDocument (vlax-get-acad-object) ) ;_ vla-get-ActiveDocument ) ;_ setq ) ;_ vla-StartUndoMark (vlax-for lay (vla-get-layers doc) (if (wcmatch (strcase (setq name (vla-get-name lay))) (strcase (strcat "*" suff)) ) ;_ wcmatch (vl-catch-all-apply 'vla-put-Name (list lay (substr name 1 (vl-string-position (ascii suff) name nil T) ) ;_ substr ) ;_ list ) ;_ vl-catch-all-apply ) ;_ if ) ;_ vlax-for (vla-EndUndoMark doc) (princ) ) ;_ defun Quote
JeepMaster Posted October 1, 2009 Posted October 1, 2009 I'm still getting the same problem...Actually not quite the same. You did solve my Layer1-1 problem I showed earlier. But it doesn't remove others like when I have mix of "-DEMO" "-NEWW" layers Quote
alanjt Posted October 1, 2009 Posted October 1, 2009 I'm still getting the same problem...Actually not quite the same. You did solve my Layer1-1 problem I showed earlier. But it doesn't remove others like when I have mix of "-DEMO" "-NEWW" layers Really? I added a suffix of "-DEMO" to all the layers, then was able to remove it from all layers. What are you getting when you try that? Quote
JeepMaster Posted October 1, 2009 Posted October 1, 2009 Oh...sorry, it's my mistake. I tried to test it with our company's standard layers, which have a mix of all the layers we use. When I tried to remove "-DEMO" from layer "E-TEXT-DEMO" It didn't work because layer "E-TEXT" already exist. So I tried it on blank dwg and everything works like it's suppose to. Thanks. Alan for the help. Quote
alanjt Posted October 1, 2009 Posted October 1, 2009 Oh...sorry, it's my mistake. I tried to test it with our company's standard layers, which have a mix of all the layers we use. When I tried to remove "-DEMO" from layer "E-TEXT-DEMO" It didn't work because layer "E-TEXT" already exist. So I tried it on blank dwg and everything works like it's suppose to. Thanks. Alan for the help. That makes sense. I'm sure that's the main reason Lee put a vl-catch-all-apply on the rename portion. Quote
Lee Mac Posted October 1, 2009 Posted October 1, 2009 Thanks Alan - I didn't think vl-string-right-trim was the best way to do it - very unpredictable. That makes sense. I'm sure that's the main reason Lee put a vl-catch-all-apply on the rename portion. Yeah... that and I'm too lazy to check all the other things that would cause an error Quote
alanjt Posted October 1, 2009 Posted October 1, 2009 Thanks Alan - I didn't think vl-string-right-trim was the best way to do it - very unpredictable. Yeah... that and I'm too lazy to check all the other things that would cause an error It's generally the best option. Why waste checks with tblsearch, etc. when the catch will take care of everything. I would have done the same thing. Quote
JeepMaster Posted October 1, 2009 Posted October 1, 2009 Thanks for all the help Alan and Lee. You guys are great. I'm happy now. Quote
alanjt Posted October 1, 2009 Posted October 1, 2009 No sweat. We don't have anything better to do than rag on each others code. Quote
Lee Mac Posted October 1, 2009 Posted October 1, 2009 No sweat. We don't have anything better to do than rag on each others code. hehe true Quote
Lee Mac Posted October 1, 2009 Posted October 1, 2009 LoL:geek:... Just noticed your links to your programs in the sig.... seems like everyone followed me on that one :wink: Buzzard, Freerefill... now you... 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.