Visual LISP, AutoLISP and General Customization

Reply
*discussion.autodesk.com
Message 1 of 13 (344 Views)

ssget "x" dynamic block

344 Views, 12 Replies
11-30-2007 12:28 AM
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
Distinguished Contributor
bnarum1
Posts: 169
Registered: ‎11-24-2003
Message 2 of 13 (344 Views)

Re: ssget "x" dynamic block

11-30-2007 04:30 AM in reply to: *discussion.autodesk.com
effective name is constant regardless if its been modified. Its how your filtering with group code 2. give me a minute to modify

B
Distinguished Contributor
bnarum1
Posts: 169
Registered: ‎11-24-2003
Message 3 of 13 (344 Views)

Re: ssget "x" dynamic block

11-30-2007 05:12 AM in reply to: *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
*Joe Burke
Message 4 of 13 (344 Views)

Re: ssget "x" dynamic block

11-30-2007 05:31 AM in reply to: *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
Distinguished Contributor
bnarum1
Posts: 169
Registered: ‎11-24-2003
Message 5 of 13 (344 Views)

Re: ssget "x" dynamic block

11-30-2007 05:52 AM in reply to: *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?
*Joe Burke
Message 6 of 13 (344 Views)

Re: ssget "x" dynamic block

11-30-2007 07:31 AM in reply to: *discussion.autodesk.com
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?
Distinguished Contributor
bnarum1
Posts: 169
Registered: ‎11-24-2003
Message 7 of 13 (344 Views)

Re: ssget "x" dynamic block

11-30-2007 08:01 AM in reply to: *discussion.autodesk.com
sorry, I guess I don't understand the code you posted.
I was just trying to help the user with clairification.
*Joe Burke
Message 8 of 13 (344 Views)

Re: ssget "x" dynamic block

11-30-2007 08:21 AM in reply to: *discussion.autodesk.com
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
Distinguished Contributor
bnarum1
Posts: 169
Registered: ‎11-24-2003
Message 9 of 13 (344 Views)

Re: ssget "x" dynamic block

11-30-2007 09:02 AM in reply to: *discussion.autodesk.com
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
*discussion.autodesk.com
Message 10 of 13 (344 Views)

Re: ssget "x" dynamic block

12-02-2007 09:16 AM in reply to: *discussion.autodesk.com
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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community