Jump to content

extracting LOGINNAME to place in to a drawing title


Recommended Posts

Posted
Since you're in turbo mode.. write one for (vlax-get-or-create-object "VBScript.RegExp") for the fun of it ;)

 

Just for the fun of it :)

 

(defun test ( str / regex )
   (if (setq regex (vlax-get-or-create-object "VBScript.RegExp"))
       (progn
           (setq str
               (vl-catch-all-apply
                   (function
                       (lambda ( )
                           (vlax-put-property regex 'pattern "^(.)[^.]*\\.(.*)$")
                           (vlax-invoke-method regex 'replace str "$1.$2")
                       )
                   )
               )
           )
           (vlax-release-object regex)
           (if (null (vl-catch-all-error-p str))
               (strcase str)
           )
       )
   )
)
(vl-load-com)

_$ (test "Daniel.Williams")
"D.WILLIAMS"

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • dannywi77iams

    7

  • pBe

    6

  • MSasu

    5

  • Lee Mac

    3

Top Posters In This Topic

Posted
Just for the fun of it :)

_$ (test "Daniel.Williams")
"D.WILLIAMS"

 

Cool beans :thumbsup:

 

Thanks Lee

 

Cheers

Posted

Here is my finished code for now. I'll may end up changing it someday.

 

(defun c:l2t ()
 (setq usernm (strcase (getvar "Loginname")));"Daniel.Williams"
 (setq fstin (strcat (substr usernm 1 1)); Split usernm to find first name inital "D"
surnm (last (fnsplitl usernm)); Split usernm to find surname ".Williams"
surin (strcat (substr surnm 1 2))); Splits the surnm to find the surname inital ".W"
;;;  ********    Create names:    ********
 (setq tilnm (strcat fstin surnm)); Create title name ("D.WILLIAMS")
 (setq revin (strcat fstin surin ".")); Create inital name ("D.W.")
 
 ); end

Posted

You may define the variables that aren't needed outside your routine as local to avoid interference with other codes:

 

(defun c:l2t ( / [color=blue]usernm fstin surnm surin[/color] )
 (setq usernm (strcase (getvar "Loginname")));"Daniel.Williams"
 (setq fstin (strcat (substr usernm 1 1)); Split usernm to find first name inital "D"
surnm (last (fnsplitl usernm)); Split usernm to find surname ".Williams"
surin (strcat (substr surnm 1 2))); Splits the surnm to find the surname inital ".W"
;;;  ********    Create names:    ********
 (setq tilnm (strcat fstin surnm)); Create title name ("D.WILLIAMS")
 (setq revin (strcat fstin surin ".")); Create inital name ("D.W.")
 
 ); end

 

Are you going to use this on command prompt or inside an AutoLISP routine? For the second case I suggest to define a function instead of a command.

 

Regards,

Mircea

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