gS7 发表于 2022-7-6 07:06:42

bad function: "0"

Hello CadTutor
 
My Program showingbad function: "0"please help me to find the error
Pls
Pls
 

(defun err (msg)   (if    (not           (member msg '("Function cancelled" "quit / exit abort")                )        )        (progn                (princ (strcat "\nError Found * * < "   msg" > * *"))                (princ "\nSystem Variables restored")        ))       (setvar 'clayer lay)    (setvar 'osmode osm)        (setvar 'cmdecho cmh)        (setvar 'nomutt mutt)    (princ))(defun c:Export_Text()   (setq cmh (getvar 'cmdecho)      osm(getvar 'osmode)          mutt(getvar 'nomutt)          lay(getvar 'clayer))(setvar 'osmode 0)(setvar 'cmdecho 0)(setq olderr *error* *error* err)(prompt "\nSelect Text Entites To Export Coordinates::")(setvar 'nomutt 1)(if (setq sset(ssget '((0 . "TEXT,MTEXT"))))    (progn          (setq file(open "C:\\Coords.csv" "w"))                (setq hdr(strcat "S.No" "," "Easting" "," "Northing" "," "String"))                (write-line hdr file)          (lay "Point_Number" 2)          (setq Num 1)          (setq i (sslength sset))                (repeat i                     (setq ssnm(ssname sset (setq i(1- i)))                             Point(TextJustp ssnm)                                   Omit(strcat (rtos num 2 0) "," (rtos (car point) 2 3) "," (rtos (cadr point) 2 3) "," (cdr (assoc 1 (entget ssnm))))                          )                          (write-line omit file)                          (_MakeText point (rtos num 2 0) 2 (getvar 'TEXTSTYLE) "Point_Number")               (setq num(1+ num))                )                (close file)        )        (princ "\nNo Text /MText Selected:"))(setvar 'osmode osm)(setvar 'nomutt mutt)(setvar 'cmdecho cmh)(setvar 'clayer lay)(setq *error* olderr)(princ))                                                                                                                (defun Lay(name col)   (if (not (Tblsearch "LAYER" name))    (command "_LAYER" "n" name "c" col name "")        (command "_LAYER" "t" name "ON" name "c" col name "")))(defun _MakeText(Inter String HT STYLE LAYER)   (entmake (list (cons 0 "TEXT")               (cons 10 Inter)                           (cons 1 String)                           (cons 40 Ht)                           (cons 7 STYLE)                           (cons 8 Layer)               )))(defun TextJustp(data)   (setq ent(entget data))(if (= "MTEXT" (cdr (assoc 0 ent)))   (cdr (assoc 10 ent))   (progn       (if (and (= 0 (cdr (assoc 72 ent)))                    (= 0 (cdr (assoc 73 ent)))                        )                        (cdr (assoc 10 ent))                        (cdr (assoc 11 ent))                )        )))

Lee Mac 发表于 2022-7-6 07:11:09

Follow this tutorial to debug your code:
 
http://lee-mac.com/debugvlide.html

Tharwat 发表于 2022-7-6 07:16:00

Localize the variables and open the drawing and run the code .

gS7 发表于 2022-7-6 07:18:10

Tharwat i Localized Variables but also getting same problem which i mentioned inabove post

pBe 发表于 2022-7-6 07:25:23

Hint:
 
What islay
 
variable where the name ofcurrent layer is saved?
or
a sub function that creates a layer?
 
HTH

Tharwat 发表于 2022-7-6 07:27:52

 
Although your code did not throw any error at all , try it this way ...
 

(defun c:Export_Text (/ *error* _MakeText TextJustp file hdr i num omit point sset ssnm) (defun *error* (x) (if file (close file))(princ "\n *Cancel*") (princ))(if (not (Tblsearch "LAYER" "Point_Number")) (command "_LAYER" "n" "Point_Number" "c" 2 "Point_Number" "") (command "_LAYER" "t" "Point_Number" "ON" "Point_Number" "c" 2 "Point_Number" "")) (defun _MakeText (Inter String HT STYLE)   (entmake (list (cons 0 "TEXT")                  (cons 10 Inter)                  (cons 1 String)                  (cons 40 Ht)                  (cons 7 STYLE)                  (cons 8 "Point_Number")            )   ) ) (defun TextJustp (data / ent)   (setq ent (entget data))   (if (= "MTEXT" (cdr (assoc 0 ent)))   (cdr (assoc 10 ent))   (progn (if (and (= 0 (cdr (assoc 72 ent))) (= 0 (cdr (assoc 73 ent))))            (cdr (assoc 10 ent))            (cdr (assoc 11 ent))            )   )   ) ) (prompt "\nSelect Text Entites To Export Coordinates::") (if (and (setq sset (ssget '((0 . "TEXT,MTEXT"))))          (setq file (open "C:\\Coords.csv" "w"))   )   (progn (setq hdr (strcat "S.No" "," "Easting" "," "Northing" "," "String"))          (write-line hdr file)          (setq Num 1)          (setq i (sslength sset))          (repeat i            (setq ssnm(ssname sset (setq i (1- i)))                  Point (TextJustp ssnm)                  Omit(strcat (rtos num 2 0)                              ","                              (rtos (car point) 2 3)                              ","                              (rtos (cadr point) 2 3)                              ","                              (cdr (assoc 1 (entget ssnm)))                        )            )            (write-line omit file)            (_MakeText point (rtos num 2 0) 2 (getvar 'TEXTSTYLE))            (setq num (1+ num))          )          (close file)   )   (princ "\nNo Text /MText Selected:") ) (princ))

gS7 发表于 2022-7-6 07:31:11

Tharwat
 
Thank you for your Support Also revising my codes ..

gS7 发表于 2022-7-6 07:36:41

@ Leemac I found the errorthrough Your Guide Lines from your site
 
Thank you

gS7 发表于 2022-7-6 07:40:06

pBe i tried to create A A Layer Using Sub function

pBe 发表于 2022-7-6 07:44:00

gS7,
 
I have given you the answer to your query on my post.
 
 
(setq lay (getvar 'clayer));;
 
(lay "Point_Number" 2);;
 
Why you may ask?...
 
("0" "Point_Number" 2);;;
 
A simple modification on your code will "fix" the problem...
 
its either this:
(setq layr (getvar 'clayer))....?
or
(defun LayerM` (name col)....
 
Your code defines lay as a layer maker when loaded.When you run the routinelay becomes the name of the current layer and not the layer maker sub you define when loaded. got it?
 
I pointed out the problem with your code so that way you will learnto debug.
 
How else will you will learn if i've thrown in another codefor you to use.
 
Cheers
页: [1] 2
查看完整版本: bad function: "0"