Jump to content

Need small help, getting princs twice instead of 1


Recommended Posts

Posted

Hi All,

 

I'm doing a lisp and trying to display an error message on the screen to whats wrong and why it can not continue.

 

Here are my error message. It should only be one displayed. Currently its doing both of these. Can someone let me know why its doing this?

 

"*** Error *** Drawing unit is not Metric. Try Inch option"

"*** Error *** Drawing unit is not Inches. Try Metric option"

 

Please excuse my "NOT-SO-CLEAN" LISP coding method.

I have posted truncated LISP and some of the defun mentioned here are not attached.

 

Thanks,

 

 

 

 
(defun C:PRES2A (/ OIU Dunits)
         (setq OIU (getvar "insunits"))
         (initget "I M")
         (setq Dunits (getkword "\nIs this Inch template or Metric? (I,M) <Inches>:"))
         (if (= Dunits nil) (setq Dunits "I"))
  (if (and (= Dunits "I")
                  (= OIU 1)
           (not (tblsearch "LAYER" "FORMAT"))
              )                

            (progn      
       (Inch)
       (blkrem)
              (alert "\nblocks cleaning complete.")
            ); end progn
     (princ "\n*** Error *** Drawing unit is not Inches. Try Metric option")
         );end if 

  (if (and (= Dunits "M")
                  (= OIU 4)
           (not (tblsearch "LAYER" "FORMAT"))
              )
            (progn      
       (Metric)
       (blkrem)
              (alert "\nBlocks cleaning complete.")
             ); end progn
    (princ "\n*** Error *** Drawing unit is not Metric. Try Inch option")
         );end if 
(princ)
) ; end of program

Posted

Your choice for variable Dunits is either "I" or "M" so if Dunits is "I" then it cannot be "M" and vice versa. so one IF expression is enough.

 

Keep in mind that there are 20 possible values for insunits.

 

Also this expression (not (tblsearch "LAYER" "FORMAT")) should be at the start of the program since its a requirement regardless of the Dunits value.

Posted

Something like this? I'm guessing 'insunits in your drawing is neither 1 or 4. As said above; a little redundant, but I just added to your code.

 

(defun c:pres2a (du / iu)
   (setq iu (getvar 'insunits))
       (if
           (= iu (or 1 4))
           (progn
               (initget "i m")
                   (if
                       (= du nil)
                       (setq du "i")
                   )
                       (setq du (getkword (strcat "\nIs the drawing imperial or metric [i/m] <" du "> : ")))
                       (if
                           (and
                               (= du "i")
                               (= iu 1)
                               (not (tblsearch "LAYER" "FORMAT"))
                           )
                               (progn
                                   (Inch)
                                   (blkrem)
                                   (alert "\nblock cleaning complete")
                               )
                               (princ "\n*** Error *** Drawing unit not imperial, use metric option!")
                       )
                       (if
                           (and
                               (= du "m")
                               (= iu 4)
                               (not (tblsearch "LAYER" "FORMAT"))
                           )
                               (progn
                                   (metric)
                                   (blkrem)
                                   (alert "\nblock cleaning complete")
                               )
                               (princ "\n*** Error *** Drawing unit not metric, use imperial option!")
                       )
           )
           (princ "\nYou silly goose, units must be inches or millimeters!")
       )
 (princ)
)

Posted

Hi pBe

I think you are correct on this one. I need to add this in the starting lines.

Also this expression (not (tblsearch "LAYER" "FORMAT")) should be at the start of the program since its a requirement regardless of the Dunits value.

 

Hi CheSyn

The drawing units are always either Metric or Imperial nothing else than these two.

 

Something like this? I'm guessing 'insunits in your drawing is neither 1 or 4.

 

(princ "\nYou silly goose, units must be inches or millimeters!")
:) :)

 

Here is why I'm writing this lisp: The drawings are converted from Solidworks to AutoCAD .dwg format. Once in AutoCAD, I need to remove the whole sheet keeping just the inner object. Also delete the standard blocks that are no longer required. Since the template for Inches and Metric different in size, I need to get the unit information to verify if I'm not mistakenly running the wrong coordinates to erase.

 

The tblsearch is the safety feature for me which I recently added. If accidently or knowingly someone tries to run this utility on the standard AutoCAD drawing, the template contains a layer named "Format" which detect and terminates. I have seen some of my fellow users misuse my trial utilities but without knowing concequences. This is something that I have learned recently. But I do want them to mess with it so that I can further improve it step by step.

 

Thanks guys for your help.

Regards,

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