Author Topic: How to avoid duplicate in selection?  (Read 1163 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
How to avoid duplicate in selection?
« on: July 11, 2023, 03:12:26 AM »
Hi All

while select blocks using ssget

in some cases, the blocks with the same name selected more than one time.

Code: [Select]
(setq ss (ssget (list (cons 0 "INSERT"))))
(sslength ss)
6

So I am wondering, How to avoid selecting block without douplicate in name?

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: How to avoid duplicate in selection?
« Reply #1 on: July 11, 2023, 06:53:41 AM »
ssget is obtaining a selection set of entities, independent of any distinct properties they may possess.

To obtain a selection set of block references with distinct block names, you will need to iterate over the set obtained with ssget and remove/ignore block references whose block names have already been encountered in a previous iteration.

ribarm

  • Gator
  • Posts: 3310
  • Marko Ribar, architect
Re: How to avoid duplicate in selection?
« Reply #2 on: July 11, 2023, 09:34:11 AM »
What do you want to do with blocks?
get definition - redefine them...

rename them...
redefine them by import same named block from another drawing...
delete them...

I suppose you don't want to copy them as you have more than you want present in as you satated your selection...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to avoid duplicate in selection?
« Reply #3 on: July 11, 2023, 09:58:20 AM »
What I want is modify the block nested entities. to be bycolor or bylayer
Today evening I'll try
Thanks in advance
« Last Edit: July 11, 2023, 10:55:54 AM by HasanCAD »

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: How to avoid duplicate in selection?
« Reply #4 on: July 11, 2023, 10:56:53 AM »
What I want is modify the block nested entities. to be bycolor or bylayer

In that case you'll need to iterate over the block component entities found within the block definition; if you still want the user to select the blocks that are to be modified, I would suggest iterating over the selection and, if the block hasn't previously been encountered, process the block definition and add the block name to a list of processed blocks.

I think there are quite a few examples of this to be found on the forums - for example, this will change the colour of block entities (and nested block entities).

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: How to avoid duplicate in selection?
« Reply #5 on: July 13, 2023, 02:05:49 AM »
What I want is modify the block nested entities. to be bycolor or bylayer

In that case you'll need to iterate over the block component entities found within the block definition; if you still want the user to select the blocks that are to be modified, I would suggest iterating over the selection and, if the block hasn't previously been encountered, process the block definition and add the block name to a list of processed blocks.

I think there are quite a few examples of this to be found on the forums - for example, this will change the colour of block entities (and nested block entities).

Thanks for great example. It is very good as a start.