Jump to content

Recommended Posts

Posted

HI all hope to not bother too much but i got a little problem...

 

What i want to do is to code something that calculates the area of a random close shape. I can ez use the area command BUT my problem that i have to use a loop so that i can keep cliking on points (the corners of the shape). so ill be someting like

 

(while

click on the first point

click on the next point etc....[end? Y/N?] ;;something that tell that this point is the last point

 

)

 

(print "the area is :" area )

Posted

Not sure where this code came from but it uses a selection set.

(DEFUN C:TOTAREA (/ tarea ss1 sn sn2 et) 
(setq cmdecho (getvar "cmdecho")) 
(setvar "cmdecho" 0) 
(setq tarea 0) 
(prompt "\nSelect only those entities you want for total area: ") 
(setq ss1 (ssget)) 
(while (> (sslength ss1) 0) 
 (setq sn (ssname ss1 0)) 
 (setq ent (entget sn)) 
 (setq et (cdr (assoc '0 ent))) 
 (command "area" "o" sn) 
 (setq tarea (+ tarea (getvar "area"))) 
 (ssdel sn ss1) 
) 
(setq tarea (/ tarea 144)) 
(alert (strcat "\nThe Total AREA of Selected Polylines is: " (rtos tarea 2 2))) 
(setvar "cmdecho" cmdecho) 
(princ) 
) 

Posted

Here is a loop example:

(defun c:test(/ ename pick)
 (setvar "errno" 0)               ; must pre set the errno to 0 
 (while (and (null (setq ename (entsel "\nSelect object.")))
              (= (getvar "errno") 7))
   (if (= (getvar "errno") 52) ; exit if user pressed ENTER
     (exit)
   )
   (prompt "\nMissed, Try again.")
 )
 (if ename  (setq pick  (cadr ename)
                   ename (car ename))
 )
)

Posted

A subroutine example:

(defun getEntity (msg enttype / picked ent return)
 ;;  enttype may be nil
 (setvar "ErrNo" 0) ; reset variable
 (while
   (not
     (cond
       ((and (null (setq picked (entsel msg)))
             (/= 52 (getvar "ErrNo")) ; <Enter> was not hit
        )
        (prompt "\nMissed, Try Again.")
       )
       ((null picked) t) ; [ENTER] pressed, exit loop, return nil
       ((progn
          (setq ent (car picked))
          (cond
            ((null enttype) (setq return ent))
            ((= (strcase enttype) (cdr (assoc 0 (entget ent))))
             (setq return ent)
            )
            (t (prompt "\nWrong entity type, Try Again."))
          )
        )
       )
     )
   )
 )
 return
)

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