Delete Using Coordinates w/ Options

Delete Using Coordinates w/ Options

jarredmonday
Collaborator Collaborator
1,290 Views
6 Replies
Message 1 of 7

Delete Using Coordinates w/ Options

jarredmonday
Collaborator
Collaborator

Hello again,

 I've done the best i can with understanding  what I've read. i am attempting to have keywords appear and depending on what you choose the opposite will be deleted.

 Attached is the cad file for reference that include a generic template. Also, I've attached the two codes that are broken. I did the best I could to my knowledge.

 

First, "FFF" is to choose LEFT or RIGHT.  If I choose RIGHT then the LEFT should be erased and vice versa. I was able to write the code to erase the first command but i cannot figure out how to skip the command if the opposite is chosen.

Second, the "DDD" code is the same concept but with multiple combinations. There should only be one choice and the others should be erased. This one, doesn't work at all.

 

(defun C:FFF (/ LR RR)
(initget 1 "Left Right") (setq LR (getkword "\nPick Garage Left or Garage Right? [Left/Right]"))
(if (eq "Left" LR) (setq LR "LH" RR "RH") (setq RR "RH" LR "LH"))
(if (setq LR (ssget "_C" '(24 24) '(0 0)))
(command "_.erase" RH "")
);if
(if (setq RR (ssget "_C" '(59 24) '(35 0)))
(command "_.erase" LH "")
);if
);defun

;;;
(defun C:DDD (/ Aa Bb Cc)
(initget 1 "ElevA ElevB") (setq Aa (getkword "\nWhat Elevation Opt You Want? [ElevA/ElevB/ElevC]"))
(if (eq "ElevA" Aa) (setq Aa "A" Bb "B" Cc "C"))
(if (setq Aa (ssget "_C" '(59 -44) '(0 -102)))
(command "_.erase" B "")
);if
);defun
Please mark Accept as Solution if your question is answered. Kudos gladly accepted. ⇘
0 Likes
Accepted solutions (3)
1,291 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Here is very simple FFF:

 

(defun C:FFF (/ ss)
  (initget 1 "Left Right")

  (if (setq ss (if (= "Right" (getkword "\nPick Garage Left or Garage Right? [Left/Right]: "))
		 (ssget "_C" '(24 24) '(0 0))
		 (ssget "_C" '(59 24) '(35 0))))
    (command "_.erase" ss ""))
)

 

Or a bit different concept for ddd:

(defun C:DDD (/ key ss)
  (initget 1 "ElevA ElevB ElevC")
  (setq	key (getkword "\nWhat Elevation Opt You Want? [ElevA/ElevB/ElevC]"))

  (if (/= key "ElevA")
    (if (setq ss (ssget "_C" '(59 -44) '(0 -102)))
      (command "_.erase" ss "")))

  (if (/= key "ElevB")
    (if (setq ss (ssget "_C" '(0 0) '(10 10)))
      (command "_.erase" ss "")))

  (if (/= key "ElevC")
    (if (setq ss (ssget "_C" '(10 10) '(20 20)))
      (command "_.erase" ss "")))

  )

 

Or kinda visual version of DDD:

(defun C:DDD (/ key sa sb sc)
  (initget 1 "ElevA ElevB ElevC")
  (setq	key (getkword "\nWhat Elevation Opt You Want? [ElevA/ElevB/ElevC]"))

  (setq sa (ssget "_C" '(59 -44) '(0 -102)))
  (setq sb (ssget "_C" '(59 -44) '(0 -102))) ; adjust coords
  (setq sc (ssget "_C" '(59 -44) '(0 -102))) ; adjust coords

  (cond ((= key "ElevA")
	 (if sb (command "_.erase" sb ""))
	 (if sc (command "_.erase" sc ""))
	 )

	((= key "ElevB")
	 (if sa (command "_.erase" sa ""))
	 (if sc (command "_.erase" sc ""))
	 )

	((= key "ElevC")
	 (if sa (command "_.erase" sa ""))
	 (if sb (command "_.erase" sb ""))
	 )))

 ...many ways to do that.

0 Likes
Message 3 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

How about something without even needing variables in the first one, like:

(defun C:FFF ()
  (initget 1 "Left Right")
(if (= (getkword "\nPick Garage Left or Garage Right? [Left/Right]") "Left") (command "_.erase" "_c" '(59 24) '(35 0) ""); then {erase right side}
  (command "_.erase" "_c" '(24 24) '(0 0) ""); else {erase left side} );if
); defun

For the second, (cond) would be the key, and I would put the ABC at the front  of the choices, so the User needs to type only the one letter, not the entire ElevX word:

(defun C:DDD (/ opt)
(initget 1 "Aelev Belev Celev")
(setq opt (getkword "\nWhat Elevation Opt You Want? [Aelev/Belev/Celev]"))
(cond
((= opt "Aelev") (command "_.erase" "_c" '(xB1 yB1) '(xB2 yB2) "_c" '(xC1 yC1) '(xC2 yC2) ""))
;; Crossing-window selections of B and C areas; other combinations below:
  ((= opt "Belev") (command "_.erase" "_c" '(xA1 yA1) '(xA2 yA2) "_c" '(xC1 yC1) '(xC2 yC2) ""))
  ((= opt "Celev") (command "_.erase" "_c" '(xA1 yA1) '(xA2 yA2) "_c" '(xB1 yB1) '(xB2 yB2) ""))
); cond
); defun

Of course, you would replace all those pale blue entries with the appropriate actual numerical values.

 

Kent Cooper, AIA
0 Likes
Message 4 of 7

jarredmonday
Collaborator
Collaborator

Thank you very much for the help. After running this, each elevation opt erases all but ElevA. Attached is the code i've added the Coordinates and additional elevations.

 

The other Left Right is working .

 

(defun C:DDD (/ key sa sb sc sd ss su)
  (initget 1 "ElevA ElevB ElevC ElevD ElevS ElevU")
  (setq	key (getkword "\nWhat Elevation Opt You Want? [ElevA/ElevB/ElevC/ElevD/ElevS/ElevU]"))

  (setq sa (ssget "_C" '(993 -1451) '(-48 -7079)))
  (setq sb (ssget "_C" '(2193 -1451) '(1152 -7079)))
  (setq sc (ssget "_C" '(3393 -1451) '(2352 -7079)))
  (setq sd (ssget "_C" '(4593 -1451) '(3552 -7079)))
  (setq ss (ssget "_C" '(5793 -1451) '(4752 -7079)))
  (setq su (ssget "_C" '(6993 -1451) '(5952 -7079)))

  (cond ((= key "ElevA")
	 (if sb (command "_.erase" sb ""))
	 (if sc (command "_.erase" sc ""))
	 (if sd (command "_.erase" sd ""))
	 (if ss (command "_.erase" ss ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "ElevB")
	 (if sa (command "_.erase" sa ""))
	 (if sc (command "_.erase" sc ""))
	 (if sd (command "_.erase" sd ""))
	 (if ss (command "_.erase" ss ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "ElevC")
	 (if sa (command "_.erase" sa ""))
	 (if sb (command "_.erase" sb ""))
	 (if sd (command "_.erase" sd ""))
	 (if ss (command "_.erase" ss ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "ElevD")
	 (if sa (command "_.erase" sa ""))
	 (if sb (command "_.erase" sb ""))
	 (if sc (command "_.erase" sc ""))
	 (if ss (command "_.erase" ss ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "ElevS")
	 (if sa (command "_.erase" sa ""))
	 (if sb (command "_.erase" sb ""))
	 (if sc (command "_.erase" sc ""))
	 (if sd (command "_.erase" sd ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "ElevU")
	 (if sa (command "_.erase" sa ""))
	 (if sb (command "_.erase" sb ""))
	 (if sc (command "_.erase" sc ""))
	 (if sd (command "_.erase" sd ""))
	 (if ss (command "_.erase" ss ""))
	 )))
Please mark Accept as Solution if your question is answered. Kudos gladly accepted. ⇘
0 Likes
Message 5 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

The issue are those Keywords. As Kent already pointed out, those works just when you use the whole words.

Just try this line paste into command-line and try to type/pick/type-just-partially some key-word.

 

(progn (initget 1 "ElevA ElevB ElevC")  (getkword "\nWhat Elevation Opt You Want? [ElevA/ElevB/ElevC]"))

Then do the same with low e's... 

(progn (initget 1 "elevA elevB elevC")  (getkword "\nWhat Elevation Opt You Want? [elevA/elevB/elevC]"))

 

 

Following code should be fixed. Also added the Undo wrapper, which makes all erase commands one undo record.

(vl-load-com)

(defun C:DDD (/ key sa sb sc sd ss su)

  (initget 1 "elevA elevB elevC elevD elevS elevU")
  (setq	key (getkword "\nWhat Elevation Opt You Want? [elevA/elevB/elevC/elevD/elevS/elevU]"))

  (setq sa (ssget "_C" '(993 -1451) '(-48 -7079)))
  (setq sb (ssget "_C" '(2193 -1451) '(1152 -7079)))
  (setq sc (ssget "_C" '(3393 -1451) '(2352 -7079)))
  (setq sd (ssget "_C" '(4593 -1451) '(3552 -7079)))
  (setq ss (ssget "_C" '(5793 -1451) '(4752 -7079)))
  (setq su (ssget "_C" '(6993 -1451) '(5952 -7079)))

  (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
  
  (cond ((= key "elevA")
	 (if sb (command "_.erase" sb ""))
	 (if sc (command "_.erase" sc ""))
	 (if sd (command "_.erase" sd ""))
	 (if ss (command "_.erase" ss ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "elevB")
	 (if sa (command "_.erase" sa ""))
	 (if sc (command "_.erase" sc ""))
	 (if sd (command "_.erase" sd ""))
	 (if ss (command "_.erase" ss ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "elevC")
	 (if sa (command "_.erase" sa ""))
	 (if sb (command "_.erase" sb ""))
	 (if sd (command "_.erase" sd ""))
	 (if ss (command "_.erase" ss ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "elevD")
	 (if sa (command "_.erase" sa ""))
	 (if sb (command "_.erase" sb ""))
	 (if sc (command "_.erase" sc ""))
	 (if ss (command "_.erase" ss ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "elevS")
	 (if sa (command "_.erase" sa ""))
	 (if sb (command "_.erase" sb ""))
	 (if sc (command "_.erase" sc ""))
	 (if sd (command "_.erase" sd ""))
	 (if su (command "_.erase" su ""))
	 )

	((= key "elevU")
	 (if sa (command "_.erase" sa ""))
	 (if sb (command "_.erase" sb ""))
	 (if sc (command "_.erase" sc ""))
	 (if sd (command "_.erase" sd ""))
	 (if ss (command "_.erase" ss ""))
	 ))
  
  (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
  (princ)
  )

 

0 Likes
Message 6 of 7

jarredmonday
Collaborator
Collaborator

Yes, this corrected it and the undo function is a nice touch. I appreciate everything and hope this is helpful to other people. Thank you again.

Please mark Accept as Solution if your question is answered. Kudos gladly accepted. ⇘
0 Likes
Message 7 of 7

ВeekeeCZ
Consultant
Consultant

You're welcome. Keep on learning! 😉

0 Likes