Author Topic: GUID generator  (Read 3202 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
GUID generator
« on: July 28, 2009, 02:15:21 PM »
Hi all..

I did not found any lisp GUID generator on theswamp...
so there is my version contribution to improve theswamp database.

enjoy ! :)

Code: [Select]
(defun GUIDGEN (/ Scriptlet GUID)
  (vl-load-com)
  (setq Scriptlet (vlax-create-object "Scriptlet.TypeLib"))
  (setq GUID (vlax-get Scriptlet 'GUID))
  (vlax-release-object Scriptlet)
  (substr GUID 2 (1- (vl-string-search "}" GUID))) 
)
(guidgen)

« Last Edit: July 28, 2009, 03:01:24 PM by Andrea »
Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: GUID generator
« Reply #1 on: July 28, 2009, 03:37:04 PM »
Here's one a couple years old that's mostly similar although it returns the value c/w the curly braces:

Code: [Select]
(defun CreateGUID ( / typelib result )

    (setq
        typelib (vlax-create-object "Scriptlet.TypeLib")
        result  (vlax-get typelib 'GUID)
    )

    (vlax-release-object typelib)
   
    [color=green];;  trim the trailing \000u artifact[/color]

    (substr result 1 38)

)

(CreateGUID) => "{EF34336E-96C8-4309-AE53-E897435E84C9}"

My start-up routine performs a vl-load-com, ergo it's absence from the defun above.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Andrea

  • Water Moccasin
  • Posts: 2372
Re: GUID generator
« Reply #2 on: July 28, 2009, 04:01:12 PM »
Is a GUID always have 38 caracter ?
Keep smile...

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: GUID generator
« Reply #3 on: July 28, 2009, 05:10:00 PM »
I had to find out what on earth this thing was... some great info here:

http://en.wikipedia.org/wiki/GUID

VVA

  • Newt
  • Posts: 166
Re: GUID generator
« Reply #4 on: May 05, 2011, 05:23:36 AM »
Quote
;;  trim the trailing \000u artifact
(vlax-get-property typelib 'Guid) return GUID without artifact
Code: [Select]
(defun CreateGUID ( / typelib result )

    (setq
        typelib (vlax-create-object "Scriptlet.TypeLib")
        result  (vlax-get-property typelib 'Guid)
    )
    (vlax-release-object typelib)
  result
)

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: GUID generator
« Reply #5 on: May 05, 2011, 12:41:55 PM »
sort of homemade guid generator :)
Code: [Select]
(defun vk_RandNum (/ Mod Mult Inc Rand)
    (or *vk_RandSeed* (setq *vk_RandSeed* (getvar "DATE")))
    (setq Mod           65536
          Mult          25173
          Inc           13849
          *vk_RandSeed* (rem (+ (* Mult *vk_RandSeed*) Inc) Mod)
          Rand          (/ *vk_RandSeed* Mod)
    )
)
(defun vk_Dec2Hex (Dec /)
    (if (< Dec 10)
        (itoa Dec)
        (if (> Dec 15)
            (strcat (vk_Dec2Hex (/ Dec 16)) (vk_Dec2Hex (rem Dec 16)))
            (chr (+ Dec 55))
        )
    )
)
(defun vk_GenerateString (String Len / OutString)
    (setq OutString "")
    (repeat Len (setq OutString (strcat OutString String)))
    OutString
)
(defun vk_StringPadLeft (String NewLen Char /)
    (strcat (vk_GenerateString Char (- NewLen (strlen String))) String)
)
(defun vk_GenGUID (/)
    (apply
        'strcat
        (mapcar (function
                    (lambda (f)
                        (if f
                            (vk_StringPadLeft
                                (vk_Dec2Hex
                                    (fix (* (1- (expt 2 (* 4 f))) (vk_RandNum)))
                                )
                                f
                                "0"
                            )
                            "-"
                        )
                    )
                )
                '(4 4 nil 4 nil 4 nil 4 nil 4 4 4)
        )
    )
)