Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ssget "x" dynamic block

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
1013 Views, 12 Replies

ssget "x" dynamic block

Hi,

If I select a dynamic block it´s name can either be (2 . "*U65") or (2 .
"E_ARM0102") when it is actually the same block.

Now how can I filter the block E_ARM0102 in a way the altered ones wil also
be found.

(setq ss1 (ssget))
(ssget "x" (list (assoc 2 (entget (setq enm (ssname ss1 0)))))) ; Does not
find the dynamic altered block

(ssget "x" (list (cons 2 (vla-get-effectivename (vlax-ename->vla-object
(ssname ss1 0)))))) ; Only finds the unaltered blocks

I would like to be able to make a selectionset of both types of the same
block.

Hope someone can help.

M
12 REPLIES 12
Message 2 of 13
bnarum1
in reply to: Anonymous

effective name is constant regardless if its been modified. Its how your filtering with group code 2. give me a minute to modify

B
Message 3 of 13
bnarum1
in reply to: Anonymous

I know this isn't exactly what your looking for but this will get you a list of ename's for dyn blks with filtered name of your choice. If you want to filter all dyn blks simply modify to eliminate effname.

(defun C:filterDyn (/ ss1 ss2 effn cnt)
(setq ss1 (ssget))
(setq effn "DamperRated"
cnt 0)
(repeat (sslength ss1)
(if (and (vlax-property-available-p
(vlax-ename->vla-object (ssname ss1 cnt)) 'IsDynamicBlock)
(equal effn (vla-get-effectivename
(vlax-ename->vla-object (ssname ss1 cnt))))
)
(setq ss2 (cons (ssname ss1 cnt) ss2))
)
(setq cnt (1+ cnt))
)
(princ)
)

B
Message 4 of 13
Anonymous
in reply to: Anonymous

Here's a function by James Allen.

;;; Returns all names used for a dynamic block, including
;;; the actual block name and all anonymous instances.
;;;
;;; (setq names (MWE:GetDBlockNames (list bname)))
;;;
;;; bname = Str - Dynamic block name
;;; names = List - List of all inserted blocks whose
;;; EffectiveName = bname
;;;
;;; (setq names (MWE:GetDBlockNames '("TestDBlock")))
;;; ("TestDBlock" "*U4" "*U5" "*U6")
;;;
;;; James Allen - 26Apr07
;;; Malicoat-Winslow Engineers, P.C.
;;;
;;; Thanks to Joe Burke for pointing out code 331
;;; and to Tony Tanzillo for prodding in that direction.
;;;
(defun MWE:GetDBlockNames (arglst / blk edt enm ins name names)
(mapcar 'set '(name) arglst)
(setq names (list name)
name (strcase name)
)
(vl-load-com)
(vlax-for blk (vla-get-Blocks
(vlax-get (vlax-get-Acad-Object) 'ActiveDocument))
(if
(and
(setq enm (tblobjname "block" (vla-get-Name blk)))
(setq edt (entget enm))
(= (logand (cdr (assoc 70 edt)) 1) 1)
)
(if
(and
(setq edt (entget (vlax-vla-object->ename blk)))
(setq enm (cdr (assoc 331 edt)))
(setq ins (vlax-ename->vla-object enm))
(eq (vla-get-ObjectName ins) "AcDbBlockReference")
(wcmatch (strcase (vla-get-EffectiveName ins)) name)
)
(setq names (cons (vla-get-Name blk) names))
)
)
)
(reverse names)
) ;end

Pass what the above returns to this function.

;; Argument example: ("TestDBlock" "*U4" "*U5" "*U6")
;; Returns: "TestDBlock,`*U4,`*U5,`*U6,"
(defun BlockNamesFilter (strlst)
(apply 'strcat
(mapcar
'(lambda (x)
(if (eq "*" (substr x 1 1))
(strcat "`" x ",")
(strcat x ",")
)
)
strlst
)
)
) ;end

Example:
(setq str (BlockNamesFilter strlst))
(setq ss (ssget "X" (list '(0 . "INSERT") (cons 2 str))))

Joe Burke
Message 5 of 13
bnarum1
in reply to: Anonymous

this looks like it would work for any blocks dynamic or not.
I guess you can't have the same blk name in a dwg that is dynamic and not dynamic.
this also searches entire dwg for dynamic blk name, not a selection set?
Message 6 of 13
Anonymous
in reply to: Anonymous

I think you need to study the code I posted, rather than ask me to explain it.

Since you think you have a handle on the question asked, the code I posted should
make sense.

Joe Burke


wrote in message news:5789158@discussion.autodesk.com...
this looks like it would work for any blocks dynamic or not.
I guess you can't have the same blk name in a dwg that is dynamic and not dynamic.
this also searches entire dwg for dynamic blk name, not a selection set?
Message 7 of 13
bnarum1
in reply to: Anonymous

sorry, I guess I don't understand the code you posted.
I was just trying to help the user with clairification.
Message 8 of 13
Anonymous
in reply to: Anonymous

bnarum,

Try what I posted. I think you'll find it answers the original question.

An easy answer isn't possible because Autodesk failed to add a DXF code for effective
name. We are stuck with just the mame of a block, so we must dig deeper...

Joe Burke
Message 9 of 13
bnarum1
in reply to: Anonymous

yes, thank you.
I am able to filter object with my code but no way to pass to active selection set, only create a set of objects.
thanks again
Message 10 of 13
Anonymous
in reply to: Anonymous

Very usefull. Thanx!

"Joe Burke" schreef in bericht
news:5789090@discussion.autodesk.com...
Here's a function by James Allen.

;;; Returns all names used for a dynamic block, including
;;; the actual block name and all anonymous instances.
;;;
;;; (setq names (MWE:GetDBlockNames (list bname)))
;;;
;;; bname = Str - Dynamic block name
;;; names = List - List of all inserted blocks whose
;;; EffectiveName = bname
;;;
;;; (setq names (MWE:GetDBlockNames '("TestDBlock")))
;;; ("TestDBlock" "*U4" "*U5" "*U6")
;;;
;;; James Allen - 26Apr07
;;; Malicoat-Winslow Engineers, P.C.
;;;
;;; Thanks to Joe Burke for pointing out code 331
;;; and to Tony Tanzillo for prodding in that direction.
;;;
(defun MWE:GetDBlockNames (arglst / blk edt enm ins name names)
(mapcar 'set '(name) arglst)
(setq names (list name)
name (strcase name)
)
(vl-load-com)
(vlax-for blk (vla-get-Blocks
(vlax-get (vlax-get-Acad-Object) 'ActiveDocument))
(if
(and
(setq enm (tblobjname "block" (vla-get-Name blk)))
(setq edt (entget enm))
(= (logand (cdr (assoc 70 edt)) 1) 1)
)
(if
(and
(setq edt (entget (vlax-vla-object->ename blk)))
(setq enm (cdr (assoc 331 edt)))
(setq ins (vlax-ename->vla-object enm))
(eq (vla-get-ObjectName ins) "AcDbBlockReference")
(wcmatch (strcase (vla-get-EffectiveName ins)) name)
)
(setq names (cons (vla-get-Name blk) names))
)
)
)
(reverse names)
) ;end

Pass what the above returns to this function.

;; Argument example: ("TestDBlock" "*U4" "*U5" "*U6")
;; Returns: "TestDBlock,`*U4,`*U5,`*U6,"
(defun BlockNamesFilter (strlst)
(apply 'strcat
(mapcar
'(lambda (x)
(if (eq "*" (substr x 1 1))
(strcat "`" x ",")
(strcat x ",")
)
)
strlst
)
)
) ;end

Example:
(setq str (BlockNamesFilter strlst))
(setq ss (ssget "X" (list '(0 . "INSERT") (cons 2 str))))

Joe Burke
Message 11 of 13
Anonymous
in reply to: Anonymous

Thanks!

schreef in bericht news:5789143@discussion.autodesk.com...
I know this isn't exactly what your looking for but this will get you a list
of ename's for dyn blks with filtered name of your choice. If you want to
filter all dyn blks simply modify to eliminate effname.

(defun C:filterDyn (/ ss1 ss2 effn cnt)
(setq ss1 (ssget))
(setq effn "DamperRated"
cnt 0)
(repeat (sslength ss1)
(if (and (vlax-property-available-p
(vlax-ename->vla-object (ssname ss1 cnt)) 'IsDynamicBlock)
(equal effn (vla-get-effectivename
(vlax-ename->vla-object (ssname ss1 cnt))))
)
(setq ss2 (cons (ssname ss1 cnt) ss2))
)
(setq cnt (1+ cnt))
)
(princ)
)

B
Message 12 of 13
Anonymous
in reply to: Anonymous

You're welcome

Joe
Message 13 of 13
Anonymous
in reply to: Anonymous

Thanks!!!

I got what I needed.

I used ' instead of `

M

"discussion.autodesk.com" schreef in bericht
news:5789016@discussion.autodesk.com...
Hi,

If I select a dynamic block it´s name can either be (2 . "*U65") or (2 .
"E_ARM0102") when it is actually the same block.

Now how can I filter the block E_ARM0102 in a way the altered ones wil also
be found.

(setq ss1 (ssget))
(ssget "x" (list (assoc 2 (entget (setq enm (ssname ss1 0)))))) ; Does not
find the dynamic altered block

(ssget "x" (list (cons 2 (vla-get-effectivename (vlax-ename->vla-object
(ssname ss1 0)))))) ; Only finds the unaltered blocks

I would like to be able to make a selectionset of both types of the same
block.

Hope someone can help.

M

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost