Lisp Function fails, although working previously (Draft Sight, SVG to CAD) -


we trying implement draft sight/autocad script transform svg file cad drawing.

the principal idea read file line line (performed readsvgdata), split svg definitions spaces (readhtmlitemdata), read individual html attributes list , based on type of svg item draw cad element. in regards principal...

the unususal part is, whenever html attributes, "id="box_8_0"" sent findchar function, attrlis function, script fails, although same arrangement went before

does have hint mistake hidden?

(defun findchar (findchar text)       (setq         ;current location in string         coord 1         ;init return coordinate         returncoord 0         ;length of searched item, enable string searching         findcharlen (strlen findchar)         ;nil count: requires regular expressions (/t) identified 2 times ascii char 9         nilcnt 0         ;storage of last char ascii identify regular expressions         lastcharasci -1     )      ;iterate string , break in case of first occurence     (while (and (<= coord (strlen text) ) (= returncoord 0))         ;current character         (setq curchar (substr text coord findcharlen))          ;find searched string         (if (= findchar curchar)             (setq returncoord coord)         )          ;check regular expression         (if (and (= lastcharasci 9) (= (ascii curchar) 9))             (setq nilcnt (+ nilcnt 1))         )          ;update string position , string         (setq lastcharasci (ascii curchar))         (setq coord (+ coord 1))     )     ;return variable     (- returncoord nilcnt) )   (defun attrlis (htmlattr)     (setq koordi 0)         (progn         (setq charloc (findchar "<" htmlattr))          (princ htmlattr)         (terpri)     )      (+ koordi 1) )  (defun readhtmlitemdata(htmlitem)      (setq          coord 1         htmlitmbgn 1         attributes 0         curchar 0         dictionary 0      )      ;(princ htmlitem)     ;(terpri)     (while (<= coord (strlen htmlitem))          (setq curchar (substr htmlitem coord 1))         (if (or (= (ascii curchar) 32) (= (ascii curchar) 62))             (progn                 (if (> (- coord htmlitmbgn) 0)                     (progn                         (setq htmlattr (substr htmlitem htmlitmbgn (- coord htmlitmbgn)))                          (setq result (attrlis htmlattr))                          (princ result)                          (setq htmlitmbgn (+ coord 1))                     )                 )             )         )         (setq coord (+ coord 1))     ) )   (defun readlinecontents(line)     (if (/= line nil)         (progn             ;(princ line)             ;(terpri)              (setq                   bgn (findchar "<" line)                 end (findchar ">" line)                 itemdef (substr line (+ bgn (strlen "<"))  end)             )              (readhtmlitemdata itemdef)         )     ) )    (defun c:readsvgdata()     (setq svgfile (open (getfiled "select file" "" "svg" 0) "r"))      (setq line 1)     (while (/= line nil)          (setq line (read-line svgfile))         (readlinecontents line)     )      (close svgfile)      (princ "done") ) 

reading following file:

<svg class="boxview" id="boxview" style="width:1198.56px; height:486.8004px; display:block;" viewbox="0 0 1198.56 486.8004"> <g id="bd_box">     <rect class="box" id="box_8_0" x="109.21" y="394.119" width="58.512" height="62.184" box="4047"></rect> </g> </svg> 

edit

change of substring index, based on satraj's answer

the problem lies in way "substr" autolisp function used. start index of substr starts index 1 (not 0). code must changed such start index initialized 1. following lines in code fails.

(setq curchar (substr htmlitem coord 1))  (setq htmlattr (substr htmlitem htmlitmbgn (- coord htmlitmbgn))) 

since coord , htmlitembgn variables initialized 0, substr function fails.

also, why not use "vl-string-search" function if want find position of text in string? can rid of findchar function.

an example:

(setq charloc (vl-string-search "<" htmlattr)) 

in general, if want debug failures in autolisp, add following function lisp file , print stack trace in case of failures, enable locate exact place error occured.

(defun *error* (msg) (vl-bt) ) 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -