gS7 Posted January 5, 2013 Posted January 5, 2013 Hello CadTutor My Program showing bad 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)) ) ) ) ) Quote
Lee Mac Posted January 5, 2013 Posted January 5, 2013 Follow this tutorial to debug your code: http://lee-mac.com/debugvlide.html Quote
Tharwat Posted January 5, 2013 Posted January 5, 2013 Localize the variables and open the drawing and run the code . Quote
gS7 Posted January 6, 2013 Author Posted January 6, 2013 Tharwat i Localized Variables but also getting same problem which i mentioned in above post Quote
pBe Posted January 6, 2013 Posted January 6, 2013 Hint: What is lay variable where the name of current layer is saved? or a sub function that creates a layer? HTH Quote
Tharwat Posted January 6, 2013 Posted January 6, 2013 Tharwat i Localized Variables but also getting same problem which i mentioned in above post 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) ) Quote
gS7 Posted January 6, 2013 Author Posted January 6, 2013 Tharwat Thank you for your Support Also revising my codes .. Quote
gS7 Posted January 6, 2013 Author Posted January 6, 2013 @ Leemac I found the error through Your Guide Lines from your site Thank you Quote
gS7 Posted January 6, 2013 Author Posted January 6, 2013 pBe i tried to create A A Layer Using Sub function Quote
pBe Posted January 6, 2013 Posted January 6, 2013 gS7, I have given you the answer to your query on my post. ...My Program showing bad function: "0" please help me to find the error..... (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 routine lay 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 learn to debug. How else will you will learn if i've thrown in another code for you to use. [or revising it for you] Cheers Quote
gS7 Posted January 6, 2013 Author Posted January 6, 2013 I am very sorry pbe for Posting late reply to you I pointed out the problem with your code so that way you will learn to debug. Yes Absolutely Right pBe .... For that i am very thank full to you Your code defines lay as a layer maker when loaded. When you run the routine lay becomes the name of the current layer and not the layer maker sub you define when loaded. got it? Yes i got that point where i have done mistake and i am sure for my Other programs i will take care about that point Thank you so much Quote
Tharwat Posted January 6, 2013 Posted January 6, 2013 Tharwat Thank you for your Support Also revising my codes .. Did the revise of the code worked for you ? Quote
gS7 Posted January 6, 2013 Author Posted January 6, 2013 How else will you will learn if i've thrown in another code for you to use. [or revising it for you] Cheers Before That i Tried to learn How to Debug Lisp Programs from Lee Mac's Website Site Which Lee Posted in #2 while i found Last Break Source on(lay "Point_Number" 2) but I could Figure out the error Quote
gS7 Posted January 6, 2013 Author Posted January 6, 2013 @ Tharwat Yes Its working Perfectly Thank You So Much For Your Support Quote
Tharwat Posted January 6, 2013 Posted January 6, 2013 @ Tharwat Yes Its working Perfectly Thank You So Much For Your Support You're welcome , I just re-kneaded the code , that's it . Quote
pBe Posted January 6, 2013 Posted January 6, 2013 ....Yes i got that point where i have done mistake and i am sure for my Other programs i will take care about that point Thank you so much no problem, this is CAD Tutor after all. ......Although your code did not throw any error at all..... Tharwat, somehow the you did not manage to spot the error, thats is why a point in the right direction is warranted. Cheers Quote
Tharwat Posted January 6, 2013 Posted January 6, 2013 Tharwat, somehow you did not manage to spot the error, I left it behind for some other experienced people that is why a point in the right direction is warranted. Correct . Quote
Recommended Posts
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.