Author Topic: Trivia: Object Management Selection Group  (Read 1297 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Trivia: Object Management Selection Group
« on: August 21, 2012, 09:08:46 AM »
Hello to all,
I've always used the following code to manage individual objects group selection:

Code: [Select]
  (setq selez (ssget))
  (setq n 0)
  (setq ent1 (ssname selez n))
  (while (/= ent1 nil)
    (progn
      (command "_chprop" ent1 "" "_c" "1" "")
      ;--
      (setq n (+ n 1))
      (setq ent1 (ssname selez n))
    )
  )

I'm not sure but I think there is a cleaner way to do the same thing.
Is there a function like "foreach", but that use groups selection instead of  lists?

How do you?
Thanks in advance
« Last Edit: August 21, 2012, 09:53:10 AM by Lupo76 »

Faster

  • Guest
Re: Curiosità: gestione degli oggetti dei gruppi di selezione
« Reply #1 on: August 21, 2012, 09:16:08 AM »
Code - Auto/Visual Lisp: [Select]
  1. (if (setq selez (ssget)) (command "_chprop" selez "" "_c" "1" ""))

Lupo76

  • Bull Frog
  • Posts: 343
Re: Curiosità: gestione degli oggetti dei gruppi di selezione
« Reply #2 on: August 21, 2012, 09:21:07 AM »
You are right!
I used a bad example. :ugly:

Here is another example:
Code: [Select]
  (setq selez (ssget))
  (setq n 0)
  (setq ent1 (ssname selez n))
  (while (/= ent1 nil)
    (progn
      (entdel ent1)
      ;--
      (setq n (+ n 1))
      (setq ent1 (ssname selez n))
    )
  )


Please do not answer me to use (command "_erase" ....)
I want to use must entdel or any other function that acts on a single object.
I hope it is now clearer.

Faster

  • Guest
Re: Curiosità: gestione degli oggetti dei gruppi di selezione
« Reply #3 on: August 21, 2012, 09:35:13 AM »
Code - Auto/Visual Lisp: [Select]
  1. ;;define a function such as:
  2. (defun SSMapcar (ss Fun / nn rtn)
  3.   (if ss
  4.   (repeat (setq nn (sslength ss))
  5.   (setq rtn (cons (apply Fun (list (ssname ss (setq nn (1- nn))))) rtn))
  6.     )
  7.     )
  8.   )
  9. ;test
  10. (ssmapcar(ssget) 'entdel)
  11.  
« Last Edit: August 21, 2012, 09:39:04 AM by Faster »

Lupo76

  • Bull Frog
  • Posts: 343
Re: Curiosità: gestione degli oggetti dei gruppi di selezione
« Reply #4 on: August 21, 2012, 09:52:20 AM »
thanks for the reply.

If with the single object I have to do more operations, how can I do?
With my code:

  (setq selez (ssget))
  (setq n 0)
  (setq ent1 (ssname selez n))
  (while (/= ent1 nil)
    (progn
      (entdel ent1)
      (other operation... ent1)
      (other operation... ent1)
      (etc.)
      ;--
      (setq n (+ n 1))
      (setq ent1 (ssname selez n))
    )
  )

Maybe "Fun" may be a separate function but I do not really like having to enter another defun
Could you give me an example of this type?

Faster

  • Guest
Re: Trivia: Object Management Selection Group
« Reply #5 on: August 21, 2012, 10:26:39 AM »
The function like this:
(defun operationfun (ent )
  (entdel ent)
   (other operation... ent1)
...
   )
(ssmapcar ss 'operationfun)