Jump to content

Recommended Posts

Posted

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 o:)

  • Replies 105
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    41

  • alanjt

    30

  • JeepMaster

    15

  • kalarpu

    11

Posted
Nice idea Alan - hadn't thought of it... but then I did say "lazy man's way"... o:)

 

 

His question about removing a suffix made me think of it. Seemed a pretty good method to me, minus the while. :)

Posted
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.

Posted
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

Posted
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-" :(

Posted

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.:huh: I have no idea what's going on. Does this happen to you guys???

Posted
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.:huh: 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.

Posted

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

Posted

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

Posted
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?

Posted

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.:oops: So I tried it on blank dwg and everything works like it's suppose to. Thanks. Alan for the help.:shock:

Posted
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.:oops: So I tried it on blank dwg and everything works like it's suppose to. Thanks. Alan for the help.:shock:

That makes sense. I'm sure that's the main reason Lee put a vl-catch-all-apply on the rename portion.

Posted

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 o:)

Posted
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 o:)

 

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.

Posted

Thanks for all the help Alan and Lee. You guys are great. I'm happy now.:D

Posted

No sweat. :)

We don't have anything better to do than rag on each others code. :twisted:

Posted
No sweat. :)

We don't have anything better to do than rag on each others code. :twisted:

 

hehe true o:)

Posted
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...

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...