Author Topic: Dynamic Blocks Only Selection Set.  (Read 8747 times)

0 Members and 1 Guest are viewing this topic.

Shade

  • Guest
Dynamic Blocks Only Selection Set.
« on: May 10, 2006, 10:13:33 AM »
I was wondering if there is a way to select only the dynamic blocks in a drawing.

I could not see any DXF code for only dynamic blocks. Is there a way of filtering the normal blocks from the dynamic blocks?

Any help would be appreciated.....

Shade
:mrgreen:

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Dynamic Blocks Only Selection Set.
« Reply #1 on: May 10, 2006, 11:46:07 AM »
For starters, you could iterate the Blocks collection and check the IsDynamicBlock property and add the names of DynBlocks to a string which can be used in the SS filter. But, that still won't get any Dyn.Block inserts that have been Dynamically altered. For thos, the best you can do do right now is to include the block names beginning with a "*" and then compare the EffectiveName to your list of Dynamic Blocks.

I've been meaning to write a function to do just this, but have not had time......

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Blocks Only Selection Set.
« Reply #2 on: May 10, 2006, 12:07:40 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Dynamic Blocks Only Selection Set.
« Reply #3 on: May 10, 2006, 06:41:09 PM »
Why does this not work?

Code: [Select]
(defun c:ddd (/ ename ss index obj)
  (vl-load-com)
  (setq
    ss   (ssget '((0 . "INSERT")))
    index -1
  )
  (while (< (setq index (1+ index)) (sslength ss))
    (setq ename (ssname ss index)
  obj (vlax-ename->vla-object ename)
    )
    (if
      (eq (vla-get-IsDynamicBlock Obj) :vlax-false)
       (ssdel ename ss)
    )
  )
  (sssetfirst nil ss)
)


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Blocks Only Selection Set.
« Reply #4 on: May 10, 2006, 06:59:47 PM »
When you remove an ename from the selection set you alter the order of the enames & therefore
corrupt your index.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Dynamic Blocks Only Selection Set.
« Reply #5 on: May 10, 2006, 07:49:42 PM »
Ron, as Alan said the counter messes things up if you remove an item AND increment the counter. Try this (untested):
Code: [Select]
(defun c:ddd (/ ename ss index obj)
  (vl-load-com)
  (setq
    ss   (ssget '((0 . "INSERT")))
    index 0
  )
  (while (and (setq ename (ssname ss index))
      (setq obj (vlax-ename->vla-object ename))
      )
    (if (eq (vla-get-IsDynamicBlock Obj) :vlax-false)
      (ssdel ename ss);;remove non-Dynamic block from ss, counter stays the same
      (setq index (1+ index));;it is Dynamic, increment counter
    )
  )
  (sssetfirst nil ss)
)

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Dynamic Blocks Only Selection Set.
« Reply #6 on: May 10, 2006, 08:27:44 PM »
Works like a champ Jeff :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Dynamic Blocks Only Selection Set.
« Reply #7 on: May 10, 2006, 08:47:09 PM »
Just for fun, here's another way to skin the cat --

Code: [Select]
(ssget
    (append
       '((0 . "insert")(-4 . "<or"))
        (mapcar
           '(lambda (name) (cons 2 name))
            (   (lambda ( / result )
                    (vlax-for block
                        (vla-get-blocks
                            (vla-get-activedocument
                                (vlax-get-acad-object)
                            )
                        )
                        (if (and
                                (eq :vlax-false (vla-get-islayout block))
                                (eq :vlax-true (vla-get-isdynamicblock block))
                            )   
                            (setq result
                                (cons (vla-get-name block)
                                    result
                                )
                            )
                        )
                    )
                    (if result result '(""))
                )
            )   
        )
       '((-4 . "or>"))
    )
)

Reow!

:P
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Dynamic Blocks Only Selection Set.
« Reply #8 on: May 10, 2006, 09:05:07 PM »
Michael, that's sort of what I suggested in my first response. Except you don't account for inserted blocks that have been dynamically altered. Once an alteration is done the insert becomes an Anonymous block, but is still linked back to the block definition by  the EffectiveName property.

Adesk sure didn't make it easy with these blocks......why not just include a DXF group that holds the Effective Name?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Dynamic Blocks Only Selection Set.
« Reply #9 on: May 10, 2006, 09:09:54 PM »
Guilty as charged -- didn't read all the responses. You're earlier response addresses the issue properly (e.g. I didn't know about the block names beginning with a "*" thing), but I'll leave my post, ignorant as it is rather than make your last one look out of place.

PS: I've never used dynamic blocks, does it show?

PS: As you note, dxf state flags, effective name etc. would have been nice; grrrr.

:ugly:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Dynamic Blocks Only Selection Set.
« Reply #10 on: May 10, 2006, 09:14:27 PM »
There was supposed to be an "apologies to Jeff / All" in that post.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Blocks Only Selection Set.
« Reply #11 on: May 10, 2006, 11:47:46 PM »
Here is a way to use no index.
Sorry, not tested. I need sleep. :-o
Code: [Select]
(defun c:ddd (/ ename ss ssnew)
  (vl-load-com)
  (setq ss   (ssget '((0 . "INSERT"))))
  (while (setq ename (ssname ss 0))
    (if (eq (vla-get-IsDynamicBlock (vlax-ename->vla-object ename)) :vlax-false)
      (if (null ssnew) (setq ssnew (ssadd ename))(ssadd ename ssnew))
    )
    (ssdel ename ss)
  )
  (sssetfirst nil)
  (and ssnew (sssetfirst nil ssnew))
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

FengK

  • Guest
Re: Dynamic Blocks Only Selection Set.
« Reply #12 on: May 11, 2006, 02:09:26 AM »

Adesk sure didn't make it easy with these blocks......why not just include a DXF group that holds the Effective Name?

I was quite upset about this when I found out this.  I was very supprised that autodesk didn't think of it or purposely ignored it.  but seems it is becoming typical now, for autodesk to deliver half baked product.  i still enjoy using autocad, only with more and more disappointment.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Dynamic Blocks Only Selection Set.
« Reply #13 on: May 11, 2006, 09:28:54 AM »
Here is a way to use no index.
Sorry, not tested. I need sleep. :-o
Code: [Select]
(defun c:ddd (/ ename ss ssnew)
  (vl-load-com)
  (setq ss   (ssget '((0 . "INSERT"))))
  (while (setq ename (ssname ss 0))
    (if (eq (vla-get-IsDynamicBlock (vlax-ename->vla-object ename)) :vlax-false)
      (if (null ssnew) (setq ssnew (ssadd ename))(ssadd ename ssnew))
    )
    (ssdel ename ss)
  )
  (sssetfirst nil)
  (and ssnew (sssetfirst nil ssnew))
)

CAB,

If you change the vlax-false to true it selects dynamic blocks :)

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Blocks Only Selection Set.
« Reply #14 on: May 11, 2006, 10:13:42 AM »
Oh good, you got it to work. :-)

Code: [Select]
;;  CAB 05/11/06
;;  returns a ss of user selected dynamic blocks or nil
(defun ssgetDynamicBlock (/ ename ss ssnew)
  (vl-load-com)
  (setq ss   (ssget '((0 . "INSERT"))))
  (while (setq ename (ssname ss 0))
    (if (eq (vla-get-IsDynamicBlock (vlax-ename->vla-object ename)) :vlax-true)
      (if (null ssnew) (setq ssnew (ssadd ename))(ssadd ename ssnew))
    )
    (ssdel ename ss)
  )
  (sssetfirst nil) ; un-highlight all
  (and ssnew (sssetfirst nil ssnew)) ; highlite remaining
  ssnew
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Dynamic Blocks Only Selection Set.
« Reply #15 on: May 11, 2006, 06:16:25 PM »
There was supposed to be an "apologies to Jeff / All" in that post.
No need for that, MP. I enjoy examining your code samples, whether completely applicable or not. :-D

CAB, in a drawing with 1000's of inserts and only a few of them DynamicBlocks yours may give a significant performance hit. So a combination of yours and MP's (with the addition of blocks named "`*U*") to select ONLY DynamicBlocks and Anonymous blocks should be somewhat quicker.

Another approach might be to use 2 selection sets, one with only unmodified DynamicBlocks (they still have their name intact) and a second ss of just anonymous blocks that can be checked for IsDynamic and add it to the first if it is.

In fact, I just got pulled off my current project due to some "minor revisions coming down" so I'll go do a bit of testing.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Dynamic Blocks Only Selection Set.
« Reply #16 on: May 11, 2006, 07:43:19 PM »
Well, I don't have a drawing handy with a number of Dynamicblocks, both altered & unaltered, with a mix of standard blocks, so I can't properly test this at the moment. But here are the two methods I described previously.

Code: [Select]
(defun ssDynBlk1 (/ ent fltrlist fltrstring idx ss)
  (setq fltrstring "`*U*")
  (vlax-for x (vla-get-blocks
(vla-get-activedocument
   (vlax-get-acad-object)))
    (if (and (eq (vla-get-IsLayout x) :vlax-false)
     (eq (vla-get-IsDynamicBlock x) :vlax-true)
     )
      (setq fltrstring (strcat fltrstring "," (vla-get-name x)))
      )
    ) 
  (if (setq ss (ssget "x" (list '(0 . "INSERT") (cons 2 fltrstring))))
    (progn
      (setq idx 0)
      (while (setq ent (ssname ss idx))
(if (eq (vla-get-isdynamicblock (vlax-ename->vla-object ent)) :vlax-false)
  (ssdel ent ss)
  (setq idx (1+ idx))
  )
)
      )
    )
  ss
  )

(defun ssDynBlk2 (/ ent fltrlist fltrstring idx ss1 ss2)
  (vlax-for x (vla-get-blocks
(vla-get-activedocument
   (vlax-get-acad-object)))
    (if (and (eq (vla-get-IsLayout x) :vlax-false)
     (eq (vla-get-IsDynamicBlock x) :vlax-true)
     )
      (if (not fltrstring)
(setq fltrstring (vla-get-name x))
(setq fltrstring (strcat fltrstring "," (vla-get-name x)))
)
      )
    )
  (if fltrstring
    (setq ss1 (ssget "x" (list '(0 . "INSERT") (cons 2 fltrstring))))
    )
  (or ss1
      (setq ss1 (ssadd))
      )
  (if (setq ss2 (ssget "x" (list '(0 . "INSERT") (cons 2 "`*U*"))))
    (progn
      (while (setq ent (ssname ss2 0))
(if (eq (vla-get-isdynamicblock (vlax-ename->vla-object ent)) :vlax-true)
  (ssadd ent ss1)
  )
(ssdel ent ss2)
)
      )
    )
  ss1
  )