How to combine 3 selections into one?

How to combine 3 selections into one?

Anonymous
Not applicable
1,165 Views
6 Replies
Message 1 of 7

How to combine 3 selections into one?

Anonymous
Not applicable

Hello.

This routine needs to many clicks. How to combine these 3 IF's into 1?

 

(DEFUN C:HAll ( / multiple hatch edit )

 (if (and (princ "\nSelect HatchPatterns to change their type and HatchScale")
	  (setq stone (ssget "_:L" '((0 . "HATCH") (2 . "ANSI31,_O") (41 . 1))))
     )
   (progn
     (initcommandversion)
	 (COMMAND "_-HATCHEDIT" stone "" "_Properties" "" "0.5" "")
     )
 )
 
  (if (and (princ "\nSelect HatchPatterns to change their type and HatchScale")
	(setq skimcoat (ssget "_:L" '((0 . "HATCH") (2 . "AR-SAND") (41 . 0.15))))
     )
   (progn
     (initcommandversion)
	 (COMMAND "_-HATCHEDIT" skimcoat "" "_Properties" "" "0.07" "")
     )
 )
 
  (if (and (princ "\nSelect HatchPatterns to change their type and HatchScale")
	  (setq gwb (ssget "_:L" '((0 . "HATCH") (2 . "AR-SAND") (41 . 0.3))))
   (progn
     (initcommandversion)
	 (COMMAND "_-HATCHEDIT" gwb "" "_Properties" "" "0.15" "")
     )
 )

  (princ);
)
0 Likes
1,166 Views
6 Replies
Replies (6)
Message 2 of 7

doaiena
Collaborator
Collaborator

I haven't tested the code, but it should work.

(defun c:hall ( / ss ssLen ctr ent ed name scale)

(prompt "\nSelect HatchPatterns to change their type and HatchScale")
(if (setq ss (ssget "_:L" '((0 . "HATCH") (-4 . "<OR") (2 . "ANSI31,_O") (2 . "AR-SAND") (-4 . "OR>"))))
(progn
(setq ssLen (sslength ss)
      ctr 0)

(repeat ssLen
(setq ent (ssname ss ctr)
      ed (entget ent)
      name (cdr (assoc 2 ed))
      scale(cdr (assoc 41 ed))
      )

(cond

((and (equal name "ANSI31,_O") (equal scale 1))
(initcommandversion)
(command "_-HATCHEDIT" ent "" "_Properties" "" "0.5" "")
)

((and (equal name "AR-SAND") (equal scale 0.15))
(initcommandversion)
(command "_-HATCHEDIT" ent "" "_Properties" "" "0.07" "")
)

((and (equal name "AR-SAND") (equal scale 0.3))
(initcommandversion)
(COMMAND "_-HATCHEDIT" ent "" "_Properties" "" "0.15" "")
)

);cond

(setq ctr (1+ ctr))
);repeat

));if ss

(princ)
);defun
Message 3 of 7

john.uhden
Mentor
Mentor

How about if you select all the hatches, then one-by-one get their entity data and run each through a list of conditions for the varying codes 2 and 41?

John F. Uhden

0 Likes
Message 4 of 7

doaiena
Collaborator
Collaborator

Is this what you meant @john.uhden?

(defun c:hall ( / ss ssLen ctr ctr1 ent ed name scale nameLst scaleLst propLst)

(prompt "\nSelect HatchPatterns to change their type and HatchScale")
(if (setq ss (ssget "_:L" '((0 . "HATCH"))))
(progn
(setq ssLen (sslength ss)
      ctr 0
      nameLst  (list "ANSI31,_O" "AR-SAND" "AR-SAND")
      scaleLst (list 1           0.15      0.3)
      propLst  (list 0.5         0.07      0.15)
      )

(repeat ssLen
(setq ent (ssname ss ctr)
      ed (entget ent)
      name (cdr (assoc 2 ed))
      scale (cdr (assoc 41 ed))
      )

(setq ctr1 0)
(repeat (length nameLst)
(if (and (equal name (nth ctr1 nameLst)) (equal scale (nth ctr1 scaleLst)))
(progn
(initcommandversion)
(command "_-HATCHEDIT" ent "" "_Properties" "" (rtos (nth ctr1 propLst)) "")
))
(setq ctr1 (1+ ctr1))
);repeat

(setq ctr (1+ ctr))
);repeat

));if ss

(princ)
);defun
0 Likes
Message 5 of 7

john.uhden
Mentor
Mentor

Perhaps better, but I think @doaiena got it best.  He used (cond ...)

John F. Uhden

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant

I would say that "ANSI31,_0" are two patterns.

 

Message 7 of 7

doaiena
Collaborator
Collaborator

Now that you brought it to my attention, i think you are right @ВeekeeCZ. Maybe this is a better solution?

(defun c:hall ( / ss ssLen ctr ctr1 ent ed name scale hatchLst)

(prompt "\nSelect HatchPatterns to change their type and HatchScale")
(if (setq ss (ssget "_:L" '((0 . "HATCH"))))
(progn
(setq ssLen (sslength ss)
      ctr 0
      hatchLst (list (list "ANSI31" 1 0.5)
		     (list "AR-SAND" 0.15 0.07)
		     (list "AR-SAND" 0.3 0.15)
		     (list "_O" 1 0.5)
		)
      )

(repeat ssLen
(setq ent (ssname ss ctr)
      ed (entget ent)
      name (cdr (assoc 2 ed))
      scale (cdr (assoc 41 ed))
      )

(foreach n hatchLst
(if (and (equal name (car n)) (equal scale (cadr n)))
(progn
(initcommandversion)
(command "_-HATCHEDIT" ent "" "_Properties" "" (rtos (caddr n)) "")
))
);foreach

(setq ctr (1+ ctr))
);repeat

));if ss

(princ)
);defun 

 

0 Likes