Jump to content

bad function: "0"


gS7

Recommended Posts

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))
		)
	)
)
)

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

:excited: Thank you so much

Link to comment
Share on other sites

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

Link to comment
Share on other sites

....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

:excited: 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

Link to comment
Share on other sites

 

Tharwat, somehow you did not manage to spot the error,

 

I left it behind for some other experienced people :D

 

that is why a point in the right direction is warranted. ;)

 

Correct . :P

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...