Jump to content

Recommended Posts

Posted

I recently wrote this lisp for Advance Steel but I would like to add an option to select multiple members using initget.

 

I've used initget before with conditions, but I'm stuck using it with entsel.

(defun c:AstFilletMember (/ ent1 ent2)
  (setq ent1 (entsel "\nSelect first member: "))
  (if (or (null ent1)
	  (/= (cdr (assoc 0 (entget (car ent1)))) "ASTBEAM")
      )
    (while (or (null ent1)
	       (/= (cdr (assoc 0 (entget (car ent1)))) "ASTBEAM")
	   )
      (princ "\nSelect first member: ")
      (setq ent1 (entsel "\nSelect first member: "))
    );while
  );if
  (setq ent2 (entsel "\nSelect second member: "))
  (if (or (null ent2)
	  (/= (cdr (assoc 0 (entget (car ent2)))) "ASTBEAM")
      )
    (while (or (null ent2)
	       (/= (cdr (assoc 0 (entget (car ent2)))) "ASTBEAM")
	   )
      (princ "\nSelect second member: ")
      (setq ent2 (entsel "\nSelect second member: "))
    );while
  );if
  (command "_AstM9CommTrimExtend" "" "S" ent1 "" ent2 "" "")
  (command "_AstM9CommTrimExtend" "" "S" ent2 "" ent1 "" "")
  (princ)
)   

 

Posted (edited)

Try the following code. You should allow the user to exit by the keyword or by just hitting ENTER. Only check for invalid selections.

NOTE: I could not test this completely.

(defun c:AstFilletMember (/ ent1 ent2)
   ; Intitialize keyword for next prompt.
   (initget "Exit")
   ; Loop if,
   (while
      (and
         ; entity is selected
         (setq ent1 (entsel "\nSelect first member or [Exit]: "))
         ; ent1 variable does not contain keyword.
         (/= ent1 "Exit")
         ; the entity is not an "ASTBEAM" object
         (/= (cdr (assoc 0 (entget (car ent1)))) "ASTBEAM")
      )
      ; promt selection is invalid
      (princ "\nInvalid Selection. ")
      ; Intitialize keyword for next prompt
      (initget "Exit")
   )

   ; Intitialize keyword for next prompt
   (initget "Exit")

   ; If ent1 exists and is not "Exit"
   (if (and ent1 (/= ent1 "Exit"))
      ; repeat loop for ent2
      (while
         (and
            (setq ent2 (entsel "\nSelect Second member or [Exit]: "))
            (/= ent2 "Exit")
            (/= (cdr (assoc 0 (entget (car ent2)))) "ASTBEAM")
         )
         (princ "\nInvalid Selection. ")
         (initget "Exit")
      )
   )
   ; if both ent1 and ent2 exist and are not "Exit",
   (if (and ent1 ent2 (/= ent1 "Exit")(/= ent2 "Exit"))
      (progn
         (setq ent1 (car ent1) ent2 (car ent2))
         (command "_AstM9CommTrimExtend" "" "S" ent1 "" ent2 "" "")
         (command "_AstM9CommTrimExtend" "" "S" ent2 "" ent1 "" "")
      )
   )

   (princ)
)

 

Edited by pkenewell
Posted (edited)

Since your two selections are the same, you can abstract the process into a separate function, e.g.:

(defun c:astfilletmember ( / ent1 ent2 )
    (if (and (setq ent1 (getmember "\nSelect 1st member: "))
             (setq ent2 (getmember "\nSelect 2nd member: "))
        )
        (command "_AstM9CommTrimExtend" "" "S" ent1 "" ent2 "" ""
                 "_AstM9CommTrimExtend" "" "S" ent2 "" ent1 "" ""
        )
    )
    (princ)
)
(defun getmember ( msg / ent )
    (while
        (progn
            (setvar 'errno 0)
            (setq ent (car (entsel msg)))
            (cond
                (   (= 7 (getvar 'errno))
                    (princ "\nMissed, try again.")
                )
                (   (null ent)
                    nil
                )
                (   (/= "ASTBEAM" (cdr (assoc 0 (entget ent))))
                    (princ "\nThe selected object is not an ASTBEAM.")
                )
            )
        )
    )
    ent
)
(princ)

I'm unsure how you wish to use initget in this program.

Edited by Lee Mac
  • Like 1
Posted

My idea is something like the following.

(defun c:astfilletmember (/ ent1 ent2)
(initget "Multiple")
(setq ent1 (entsel "\nSelect first member or [Multiple] "))

Now I'm stuck. I'm not sure where to go from here to create a loop.

 

Basically I'm trying to recreate the "FILLET" command with the multiple option.

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