Jump to content

Selection Set from block entities... what am I doing wrong...


Steven P

Recommended Posts

I'm wanting to get a selection set from a blocks entities... but going round in circle and think I need fresh eyes... so what am I doing wrong?

 

The plan - loop through the drawing database to pick up the block names, for each block make a selection set from its constituent entities, do stuff with this selection set, move on to the next block.

 

As a fall back I could bedit each block, ssget 'X' in the block, do stuff, bclose, more on.. but that is too slow.

 

 

So below is where I am struggling... it works except the SSADD line, Ent returns the entity names (and 'type is 'ename').. but it is not adding anything to MySS

 

 

Happy to be called an idiot for a simple mistake of course.

 

(defun c:BlockEnts ( / MyBlocks Blk MySS Ent)
  (setq MyBlocks (tablesearch "block"))      ;; Get all blocks
  (foreach Blk MyBlocks
    (setq MySS nil)                          ;; Clear MySS
    (setq MySS (ssadd))                      ;; Blank SS
    (setq Ent (tblobjname "block" Blk))      ;; Block definition entitiy name
    (while (setq Ent (entnext Ent))          ;; Loop block entities
      (ssadd Ent MySS)                       ;; Add Ent to selection set

(princ Ent) ;; Check that it found an entity

    )


;;Do stuff here;;
(princ " ")(princ (sslength MySS))(princ " : ") ;; Check SS length

  ) ; end foreach
  (princ)
)

 

 

Edited by Steven P
Link to comment
Share on other sites

Like this, perhaps...

 

(defun c:BlockEnts ( / Blk MyBlocks MySS Ent )
  (while (setq Blk (tblnext "block" (not Blk)))    ;; Get all blocks
    (setq MyBlocks (cons (cdr (assoc 2 Blk)) MyBlocks))
  )
  (foreach Blk MyBlocks
    (setq MySS (ssadd))                      ;; Blank SS
    (setq Ent (tblobjname "block" Blk))      ;; Block definition entitiy name
    (while (setq Ent (entnext Ent))          ;; Loop block entities
      (ssadd Ent MySS)                       ;; Add Ent to selection set
      (princ Ent) ;; Check that it found an entity
    )
    ;;Do stuff here;;
    (princ " : ") ;; Check SS length
    (princ (sslength MySS))
    (princ "\n")
  ) ; end foreach
  (princ)
)

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, marko_ribar said:

Like this, perhaps...

 

 

Unfortunately the same as I am getting - I am getting the list of block entities but these are not being added to the selection set and I have no clue just now

Link to comment
Share on other sites

1 hour ago, pkenewell said:

@Steven P Why use a Selection set? Why not just build a list of entity names for each block and iterate through them?

 

Thanks PKEnewell, this started out from a drawing 3500 messy blocks to tidy up (95mB drawing which is a bit too big for the laptop) - starting with the usual suspects, purge, audit, overkill the main drawing. In the blocks most appear to be 3 or 4 copies on top of each other - overkill sorts that so this started to see if I can do an overkill without entering the block editor (the slow part) - and that needs a selection set really (I don't think I can do a while loop in a command? Actually maybe possible I think I have an example somewhere to look at)).

 

Anyway, experiments with overkill later - frustrating that this part doesn't work

 

 

I have a quick LISP there to go into each block and overkill but opening and closing 3500 blocks is time consuming (and there are other errors so this crashes every 200 blocks anyway)

Edited by Steven P
Link to comment
Share on other sites

You are itterating the block definitions? Not sure you can built a selectionset from this. You can make a block name list first and use that as a base for ssget filter. Between processing the different blocks set ss to nil and call garbage collection (GC) a few times before moving on to next block. This can release memory and prevent crashing. First wblock * (entire drawing) copies valid objects only in case there are a few gremlins in there, sort of audit.

When going through ssget list per block , you could save IP in list (reset list for next block name) and if IP is member of list (maybe with fuzz) , you know this block is hanky panking on top of (or under)  another block and you can entdel this block.

 

What do you do when you have a big wife , euh problem : you split it up in smaller problems (not talking about children here because they only make your problem bigger haha) , anyways you could split up your drawing into lets say 4 drawings first so each drawing is easier to handle. After processing rejoin & rejoyce.

 

just a few thoughts...

 

ps.

 

Just remebered a while back I wrote a lisp to wblock all blocks (from all drawings in a folder I think) to another folder so I could see what blocks a vendor was using. Then go through them and change if needed and redefine / re-insert them back into the drawings. Not sure if this is the right lisp but you're welcome to try it (on a copy so you can't blame the dragon). Maybe you can use overkill in a script to clean the blocks first. It still may be a big job but if the drawing is worth it...

 

RlxDbxWblock.lsp

Edited by rlx
  • Like 1
Link to comment
Share on other sites

Cheers RLX, it is a tricky one, not as straight forward as I first thought. I can get lists all OK but not selection sets (OK I can bedit each block to make the selection set but that goes against trying not to go into the block editor to start with)

 

 

I'll look at the LISP later - 'they' want other work this morning

Link to comment
Share on other sites

So there are differences between BricsCAD and AutoCAD... I've tested my code in BricsCAD V23 and it created sel.sets with entities from block definitions... Tested only with normal blocks - not dynamic...

  • Like 1
Link to comment
Share on other sites

Maybe it does also work in AutoCad Marko , I'm just not sure , I have no test material , certainly not 95Mb 😱 , are you sure its an AutoCad drawing and not a dirty movie?

 

Maybe another usefull link (haven't tried it yet)

 

 

 

Edited by rlx
Link to comment
Share on other sites

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