Author Topic: Correct me if I'm wrong...but strcase sets case  (Read 262 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 228
Correct me if I'm wrong...but strcase sets case
« on: July 28, 2021, 04:51:00 PM »
Code - Auto/Visual Lisp: [Select]
  1. (setq tagname1 "DESIGNER")
  2. (setq ss1 (ssget "x" '((2 . "TBLK_ATT_CTL")(66 . 1))))
  3. (repeat (setq x (sslength ss1))
  4. (setq obj1 (vlax-ename->vla-object (ssname ss1 (setq x (- x 1) ))))
  5. (if  (= (vla-get-hasattributes obj) :vlax-true)
  6. (foreach att1 (vlax-invoke obj1 'getattributes)
  7. (if (= tagname1 (strcase (vla-get-tagstring att1)))
  8. (vla-put-textstring att1 (substr (getvar "loginname") 1 3))
  9. )
  10. )
  11. )
  12. )

In this code I'm setting the case of tagname1 to lower case. Correct?

I've tested 4 different users and tagname1 gets filled in with lowercase in all cases but mine. I checked their actual LogInName with
Code - Auto/Visual Lisp: [Select]
and all were indeed lowercase except mine.

So it seems that I need to update their LogInName to be uppercase as the variable LogInName is read only. Or change the result of tagname1 after it's populated.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9718
Re: Correct me if I'm wrong...but strcase sets case
« Reply #1 on: July 28, 2021, 06:08:33 PM »
(strcase "Sample" T)

Specifying the witch as true will convert the string to lower case.

...click on the strcase function in your code block above to get the help for the function.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

jlogan02

  • Bull Frog
  • Posts: 228
Re: Correct me if I'm wrong...but strcase sets case
« Reply #2 on: July 28, 2021, 06:17:14 PM »
I did exactly that before I wrote the OP. It's clear to me, I read the help wrong.

Thanks for pointing that out,.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: Correct me if I'm wrong...but strcase sets case
« Reply #3 on: July 30, 2021, 01:03:46 PM »
Note that you are applying strcase to the attribute tag as returned by vla-get-tagstring in order to use a case-insensitive match between the attribute tag and the value held by the variable tagname1, not to the value that is used to populate the attribute.

I might suggest the following changes:
Code - Auto/Visual Lisp: [Select]
  1. (setq tag "DESIGNER")
  2. (if (setq sel (ssget "_X" '((0 . "INSERT") (2 . "TBLK_ATT_CTL") (66 . 1))))
  3.     (repeat (setq idx (sslength sel))
  4.         (setq idx (1- idx)
  5.               obj (vlax-ename->vla-object (ssname sel idx))
  6.         )
  7.         (vl-some
  8.            '(lambda ( att )
  9.                 (if (and (= tag (strcase (vla-get-tagstring att))) (vlax-write-enabled-p att))
  10.                     (not (vla-put-textstring att (strcase (substr (getvar 'loginname) 1 3) t)))
  11.                 )
  12.             )
  13.             (vlax-invoke obj 'getattributes)
  14.         )
  15.     )
  16. )

Here:
  • (0 . "INSERT") is included in the ssget filter list
  • vl-some will cease evaluation of the attributes when the target attribute is found
  • An if statement is used to verify that a valid selection exists
  • vlax-write-enabled-p checks that the attribute can be modified (i.e. does not reside on a locked layer) prior to modification