Author Topic: (Challenge) Create a barcode generator  (Read 7980 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
(Challenge) Create a barcode generator
« on: October 08, 2009, 08:21:20 AM »
Using PLINES create a barcode generator.

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

Good luck!! 8-)
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (Challenge) Create a barcode generator
« Reply #1 on: October 08, 2009, 09:06:46 AM »
Interesting read Mark.
Thanks 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) Create a barcode generator
« Reply #2 on: October 08, 2009, 10:09:34 AM »
Using PLINES create a barcode generator.

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

Good luck!! 8-)


Hello Mark! :)
You wished to tell, code in the width lwpolyline?
The program should make a columns of vertical polylines of different width?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (Challenge) Create a barcode generator
« Reply #3 on: October 08, 2009, 10:13:32 AM »
I found this interesting too. Although not the 128 code still a good read.
http://www.barcodeisland.com/code39.phtml
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: (Challenge) Create a barcode generator
« Reply #4 on: October 08, 2009, 10:16:33 AM »
This will give you an idea of options needing to be addressed.
http://www.morovia.com/free-online-barcode-generator/
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: (Challenge) Create a barcode generator
« Reply #5 on: October 08, 2009, 10:45:12 AM »
Using PLINES create a barcode generator.

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

Good luck!! 8-)


Hello Mark! :)
You wished to tell, code in the width lwpolyline?
The program should make a columns of vertical polylines of different width?
Yes, to both questions.
TheSwamp.org  (serving the CAD community since 2003)

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: (Challenge) Create a barcode generator
« Reply #6 on: October 08, 2009, 11:10:08 AM »
Well I played with this long enough. I actually have work to do this morning

****NOT FULLY TESTED***

Code: [Select]
;;; ------------------------------------------------------------------------
;;;    BARCODE.LSP
;;;
;;;    Copyright © October, 2009
;;;    Timothy G. Spangler
;;;
;;;    Permission to use, copy, modify, and distribute this software
;;;    for any purpose and without fee is hereby granted, provided
;;;    that the above copyright notice appears in all copies and
;;;    that both that copyright notice and the limited warranty and
;;;    restricted rights notice below appear in all supporting
;;;    documentation.
;;;
;;; Description:
;;; Creates a barcode from a piece of text

;;; ------------------------------------------------------------------------
(defun C:BARCODE (/ BarCodeText BarCodeList BarList TextLength Counter Char Bar OldLunits)

;; Set units to decimal
(setq OldLunits (getvar "LUNITS"))
(setvar "LUNITS" 2)
;; Get string to barcode
(if (= "" (setq BarCodeText (getstring "\n Enter text to barcode:<TEST>")))
(setq BarCodeText "TEST")
)
;; Set the barcode list 128B
(setq BarCodeList
(list
(cons "" 212222 )(cons "!" 222122)(cons "\"" 222221)(cons "#" 121223)
(cons "$" 121322)(cons "%" 131222)(cons "&" 122213)(cons "\'" 122312)
(cons "\(" 132212)(cons "\)" 221213)(cons "*" 221312)(cons "\+" 231212)
(cons "\," 112232)(cons "\-" 122132)(cons "\." 122231)(cons "\/" 113222)
(cons "0" 123122)(cons "1" 123221)(cons "2" 223211)(cons "3" 221132)
(cons "4" 221231)(cons "5" 213212)(cons "6" 223112)(cons "7" 312131)
(cons "8" 311222)(cons "9" 321122)(cons "\:" 321221)(cons "\;" 312212)
(cons "\<" 322112)(cons "\=" 322211)(cons "\>" 212123)(cons "\?" 212321)
(cons "@" 232121)(cons "A" 111323)(cons "B" 131123)(cons "C" 131321)
(cons "D" 112313)(cons "E" 132113)(cons "F" 132311)(cons "G" 211313)
(cons "H" 231113)(cons "I" 231311)(cons "J" 112133)(cons "K" 112331)
(cons "L" 132131)(cons "M" 113123)(cons "N" 113321)(cons "O" 133121)
(cons "P" 313121)(cons "Q" 211331)(cons "R" 231131)(cons "S" 213113)
(cons "T" 213311)(cons "U" 213131)(cons "V" 311123)(cons "W" 311321)
(cons "X" 331121)(cons "Y" 312113)(cons "Z" 312311)(cons "[" 332111)
(cons "\\" 314111)(cons "\]" 221411)(cons "^" 431111)(cons "_" 111224)
(cons "`" 111422)(cons "a" 121124)(cons "b" 121421)(cons "c" 141122)
(cons "d" 141221)(cons "e" 112214)(cons "f" 112412)(cons "g" 122114)
(cons "h" 122411)(cons "i" 142112)(cons "j" 142211)(cons "k" 241211)
(cons "l" 221114)(cons "m" 413111)(cons "n" 241112)(cons "o" 134111)
(cons "p" 111242)(cons "q" 121142)(cons "r" 121241)(cons "s" 114212)
(cons "t" 124112)(cons "u" 124211)(cons "v" 411212)(cons "w" 421112)
(cons "x" 421211)(cons "y" 212141)(cons "z" 214121)(cons "{" 412121)
(cons "|" 111143)(cons "}" 111341)(cons "~" 131141)    
)
)
;; Start Barcode
(setq BarList (cons 211214 BarList))
;; Start Counter
(setq Counter 1)
;; Step throught text and create barcode list from it
(repeat (strlen BarCodeText)
(setq Char (substr BarCodeText Counter 1))
(setq Bar (cdr(assoc Char BarCodeList)))
(setq BarList (cons Bar BarList))
(setq Counter (1+ Counter))
)
;; End Barcode
(setq BarList (cons 2331112 BarList))
;; Reverse bar list
(setq BarList (reverse BarList))
;; Draw Bar
(DRAW_BAR BarList)
;; Reet units
(setvar "LUNITS" OldLunits)
;; Echo to the command line
(princ (strcat "\n Bar Code create for \"" BarCodeText "\""))
;; Quiet exit
(princ)
)
(defun DRAW_BAR (BarList / StartPoint BarPoint Counter BarCodeGroup Loop DrawBar BarChr )

;; Define start pont for  barcode
(setq StartPoint (getpoint "\n Define starting point for barcode:"))
;; Start Counter
(setq Counter 0)
;; Step through barlist and draw barcodes
(repeat (length BarList)
;; Convert number to string
(setq BarCodeGroup (rtos (nth Counter BarList)2 0))
;; Start loop counter
(setq Loop 1)
;; Start with a bar
(setq DrawBar T)
;; Step through the bar code group
(repeat (strlen BarCodeGroup)
;; Break the bargroup down into bars
(setq BarChr (substr BarCodeGroup Loop 1))
;; Set the first point of charater
(setq BarPoint (polar StartPoint 0.0 (* 0.5 (atoi BarChr))))
(setq StartPoint (polar StartPoint 0.0 (atoi BarChr)))
;; Draw Bar
(if DrawBar
(progn
;; Draw the pline
(BAR_PLINE (list BarPoint (polar BarPoint (/ pi 2.0) 60.0)) (atoi BarChr))
;; Turn off draw bar
(setq DrawBar nil)
)
;; Turn on draw bar
(setq DrawBar T)
)
;; Add to the loop
(setq Loop (1+ Loop))
)
;; Add to the counter
(setq Counter (1+ Counter))
)
)
;; Draw pline for bar code
(defun BAR_PLINE (PointList Width / Group10List PolyLineList)

(setq PolyLineList
(list
(cons 0 "LWPOLYLINE")
(cons 100 "AcDbEntity")
(cons 100 "AcDbPolyline")
(cons 6 "Continuous")
(cons 8 "0")
(cons 43 Width) 
(cons 90 (length PointList))
(cons 70 0)
)
)
(setq Group10List (mapcar '(lambda (Coord) (cons 10 Coord)) PointList))
(setq PolyLineList (append PolyLineList Group10List))
(entmakex PolyLineList)
)
;;;
;;; Echos to the command line
(princ "\nBarCode v1.0© \n Timothy Spangler, \n  October, 2009....loaded.")
(print)
;;; End echo

*** Fixed Protected symbol error
   
« Last Edit: October 09, 2009, 07:48:03 AM by TimSpangler »
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: (Challenge) Create a barcode generator
« Reply #7 on: October 08, 2009, 11:22:43 AM »
Well I played with this long enough. I actually have work to do this morning

****NOT FULLY TESTED****
That is awesome Tim. 8-)
TheSwamp.org  (serving the CAD community since 2003)

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: (Challenge) Create a barcode generator
« Reply #8 on: October 08, 2009, 11:23:47 AM »
Just found that it only does single words, ie NO SPACES.

I will fix it later, after some other entries arrive   :evil:
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Andrea

  • Water Moccasin
  • Posts: 2372
Re: (Challenge) Create a barcode generator
« Reply #9 on: October 08, 2009, 11:52:27 AM »
Hi Tim...Nice one !

I just found an protected function error..

....(/ BarCodeText BarCodeList BarList TextLength Counter Chr Bar OldLunits)

I have change the variable names.. and it work great.


« Last Edit: October 08, 2009, 12:00:35 PM by Andrea »
Keep smile...

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: (Challenge) Create a barcode generator
« Reply #10 on: October 08, 2009, 12:02:05 PM »
Thanks Andrea,

Updated code above.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (Challenge) Create a barcode generator
« Reply #11 on: October 08, 2009, 12:04:50 PM »
my version:

Code: [Select]
(defun c:barcod ( / A I L S X Y)
 ;; By ElpanovEvgeniy
 ;; barcod-128
 (setq l '((32 . 212222) (33 . 222122) (34 . 222221) (35 . 121223) (36 . 121322)
           (37 . 131222) (38 . 122213) (39 . 122312) (40 . 132212) (41 . 221213)
           (42 . 221312) (43 . 231212) (44 . 112232) (45 . 122132) (46 . 122231) (47 . 113222)
           (48 . 123122) (49 . 123221) (50 . 223211) (51 . 221132) (52 . 221231) (53 . 213212)
           (54 . 223112) (55 . 312131) (56 . 311222) (57 . 321122) (58 . 321221) (59 . 312212)
           (60 . 322112) (61 . 322211) (62 . 212123) (63 . 212321) (64 . 232121) (65 . 111323)
           (66 . 131123) (67 . 131321) (68 . 112313) (69 . 132113) (70 . 132311) (71 . 211313)
           (72 . 231113) (73 . 231311) (74 . 112133) (75 . 112331) (76 . 132131) (77 . 113123)
           (78 . 113321) (79 . 133121) (80 . 313121) (81 . 211331) (82 . 231131) (83 . 213113)
           (84 . 213311) (85 . 213131) (86 . 311123) (87 . 311321) (88 . 331121) (89 . 312113)
           (90 . 312311) (91 . 332111) (92 . 314111) (93 . 221411) (94 . 431111) (95 . 111224)
           (96 . 111422) (97 . 121124) (98 . 121421) (99 . 141122) (100 . 141221) (101 . 112214)
           (102 . 112412) (103 . 122114) (104 . 122411) (105 . 142112) (106 . 142211) (107 . 241211)
           (108 . 221114) (109 . 413111) (110 . 241112) (111 . 134111) (112 . 111242) (113 . 121142)
           (114 . 121241) (115 . 114212) (116 . 124112) (117 . 124211) (118 . 411212) (119 . 421112)
           (120 . 421211) (121 . 212141) (122 . 214121) (123 . 412121) (124 . 111143) (125 . 111341)
           (126 . 131141) (0 . 211214) (128 . 2331112))
       s (apply
          (function strcat)
          (cons (itoa (cdr (assoc 0 l)))
                (reverse (cons (itoa (cdr (assoc 128 l)))
                               (reverse (mapcar (function (lambda (a) (itoa (cdr (assoc a l)))))
                                                (vl-string->list (getstring "\n Enter text:\t"))
                                        ) ;_  mapcar
                               ) ;_  reverse
                         ) ;_  cons
                ) ;_  reverse
          ) ;_  cons
         ) ;_  apply
       y (getpoint "\n Start point")
       x (car y)
       y (cadr y)
       i nil
 ) ;_  setq
 (while (/= (setq a (substr s 1 1)) "")
  (if (setq a (atoi a)
            i (not i)
      ) ;_  setq
   (entmakex (list '(0 . "LWPOLYLINE")
                   '(100 . "AcDbEntity")
                   '(100 . "AcDbPolyline")
                   (cons 43 a)
                   '(90 . 2)
                   (list 10 (+ x (/ a 2.)) y)
                   (list 10 (+ x (/ a 2.)) (+ y 50))
             ) ;_  list
   ) ;_  entmakex
  ) ;_  if
  (setq x (+ a x)
        s (substr s 2)
  ) ;_  setq
 ) ;_  while
)
« Last Edit: October 08, 2009, 12:17:51 PM by ElpanovEvgeniy »

Andrea

  • Water Moccasin
  • Posts: 2372
Re: (Challenge) Create a barcode generator
« Reply #12 on: October 08, 2009, 12:20:54 PM »
well....nice ElpanovEvgeniy ..and Tim..

but we got diffrent result on start code..
Keep smile...

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: (Challenge) Create a barcode generator
« Reply #13 on: October 08, 2009, 12:25:19 PM »
That is a differance in either 128A - Elpanov and 128B - Me
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: (Challenge) Create a barcode generator
« Reply #14 on: October 08, 2009, 12:27:54 PM »
From the Wiki

128A - ASCII characters 00 to 95 (0-9, A-Z and control codes) and special characters
128B - ASCII characters 32 to 127 (0-9, A-Z, a-z) and special characters
128C - 00-99 (double density encoding of numeric only data) and FNC1
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016