Jump to content

how to test the function successful running or not


Recommended Posts

Posted

Hi All,

 

I want to test the function successful running or not, any method to test it. Please give some suggestion. I saw some information from here, it record the entities before running the function and then compare the result after running the function.

(defun c:tt ()
(setq ss (ssget ":L:E"))
(setq c 0)
(repeat (sslength ss)
(setq i ( ssname ss c))
(setq aaa (entlast)
(function)
(setq bbb (entlast)
(if (not (equal aaa bbb)
 (alert "this function successful apply to object)
 (alert "not successful")
)
)
(setq c (1+ c))
);defun

But I found that, if this function successful apply on first the object, it can't get second object. Anything wrong or my concept not correct ? Forgive my poor English.

Posted

Simple example ...

 

(defun c:TesT (/ line)
 (if (and (setq line (car (entsel "\n Select line please : ")))
          (eq (cdr (assoc 0 (entget line))) "LINE")
     )
   (alert "Congratulations you selected a line ")
   (alert "Failed !! your selection is not a line ")
 )
 (princ)
)

Posted

Thank you ! In this case, would you use reactor to test the function sucessful apply on the objects or not ?

Posted

I am sorry , I do not know how to use reactor or its functions . :(

 

But certainly , lots of gentlemen here could help you with reactor .

Posted

It would depend upon the operation of the function you are evaluating. For example, if the function is performing various command calls to create objects, you can check the last entity added to the database before the command call (using entlast), then check this again after the command call to see whether the new entities have been successfully added.

 

This check may be different depending on the function you are evaluating, for example, various AutoLISP functions will return different values depending upon whether they have been successful or not. Most functions return nil if unsuccessful (for example entmake[x]).

 

Lee

Posted

Thank you Lee, I found in frist looping, when i use entlast to compare the new entities have been added or not is fine. But in second looping. the entlast will compare the first looping created entity. Any method to avoid it to compare the first round's entites. I try to reset the aaa and bbb to nil, but unsuccessful.

 

It would depend upon the operation of the function you are evaluating. For example, if the function is performing various command calls to create objects, you can check the last entity added to the database before the command call (using entlast), then check this again after the command call to see whether the new entities have been successfully added.

 

This check may be different depending on the function you are evaluating, for example, various AutoLISP functions will return different values depending upon whether they have been successful or not. Most functions return nil if unsuccessful (for example entmake[x]).

 

Lee

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