Author Topic: Dynamic Blocks Names vs. Non Dynamic Block names  (Read 7466 times)

0 Members and 1 Guest are viewing this topic.

BuckoAk

  • Newt
  • Posts: 69
Dynamic Blocks Names vs. Non Dynamic Block names
« on: November 16, 2010, 03:37:09 PM »
I have situations where I need to know what titleblocks are inserted so certain lisp programs can run.
I am currently using this statement to locate the titleblocks but when it comes to dynamic blocks it retrieves "(2 . *U52)".
If you list the titleblock it comes back a normal name, is it possible to retrieve the true block name from an anonymous name.
Or possibly add additional code that can gather this info?

Any help would greatly be appreciated.

Code: [Select]
(setq $CLIENT#2 nil)
;;;********** Check For CLIENT#2
(setq BrdrList (list '"CLIENT2_8x11" '"CLIENT2_22X34"))

(foreach Item BrdrList
      (if (= $CLIENT#2 nil)
(setq $CLIENT#2 (ssget "X" (list (cons 0 "INSERT") (cons 2 Item) ))))
       );_end foreach
)

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #1 on: November 16, 2010, 03:38:45 PM »
Perhaps use a SelectionSet of:

Code: [Select]
(cons 2 (strcat Item ",`*U*"))
Then, when iterating through the SelectionSet, test:

Code: [Select]
(if (eq Item (vla-get-EffectiveName (vlax-ename->vla-object <entity>)))
...

Oh BTW, quotes are not needed, use

Code: [Select]
(setq BrdrList (list "CLIENT2_8x11" "CLIENT2_22X34"))
or:

Code: [Select]
(setq BrdrList '("CLIENT2_8x11" "CLIENT2_22X34"))

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #2 on: November 16, 2010, 03:49:59 PM »
You could use this sub in place of the ssget call:

Code: [Select]
(defun GetBlockSelectionSet ( name / ss ) (vl-load-com)

  (if (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 (strcat name ",`*U*")))))
    (
      (lambda ( i / e )
        (while (setq e (ssname ss (setq i (1+ i))))
          (if (not (eq name (vla-get-EffectiveName (vlax-ename->vla-object e))))
            (ssdel e ss)
          )
        )
        ss
      )
      -1
    )
  )
)

Then in your code:

Code: [Select]
(foreach item '("CLIENT2_8x11" "CLIENT2_22X34")
  (if (setq ss (GetBlockSelectionSet item))
  ...
  )
)

BuckoAk

  • Newt
  • Posts: 69
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #3 on: November 16, 2010, 10:58:24 PM »
Thank you very much Lee Mac

I added it to the rest of my code and It works great!

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #4 on: November 17, 2010, 10:11:13 AM »
Thank you very much Lee Mac

I added it to the rest of my code and It works great!


Good to hear mate  :-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #5 on: November 17, 2010, 10:30:46 AM »
I would study Lee's code and try and implement the procedure, rather than just issuing the sub. Right now, you are executing ssget on every `*U* block for each given name - extremely inefficient. Use his method, make one selection with ssget, then filter accordingly and use cond to make appropriate modifications.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #6 on: November 17, 2010, 10:45:50 AM »
I would study Lee's code and try and implement the procedure, rather than just issuing the sub. Right now, you are executing ssget on every `*U* block for each given name - extremely inefficient. Use his method, make one selection with ssget, then filter accordingly and use cond to make appropriate modifications.

Completely agree - minimise the number of iterations through the same items.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #7 on: November 17, 2010, 10:49:28 AM »
I would study Lee's code and try and implement the procedure, rather than just issuing the sub. Right now, you are executing ssget on every `*U* block for each given name - extremely inefficient. Use his method, make one selection with ssget, then filter accordingly and use cond to make appropriate modifications.

Completely agree - minimise the number of iterations through the same items.
Precisely.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BuckoAk

  • Newt
  • Posts: 69
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #8 on: December 20, 2010, 10:39:28 PM »
I would study Lee's code and try and implement the procedure, rather than just issuing the sub. Right now, you are executing ssget on every `*U* block for each given name - extremely inefficient. Use his method, make one selection with ssget, then filter accordingly and use cond to make appropriate modifications.

I understand what your saying, Now only if I could count on my users to implement the tool the way is was originally intended (by selection).
It gets to be a hassle at submittal time when things are not printing correctly, the main code is only being seen on certain times.
As it stands the code is saving me a lot of hassle and barley puts a dent in processor overhead.

Harrie

  • Guest
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #9 on: February 03, 2011, 04:55:02 AM »
You could use this sub in place of the ssget call:

Code: [Select]
(defun GetBlockSelectionSet ( name / ss ) (vl-load-com)

  (if (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 (strcat name ",`*U*")))))
    (
      (lambda ( i / e )
        (while (setq e (ssname ss (setq i (1+ i))))
          (if (not (eq name (vla-get-EffectiveName (vlax-ename->vla-object e))))
            (ssdel e ss)
          )
        )
        ss
      )
      -1
    )
  )
)

Then in your code:

Code: [Select]
(foreach item '("CLIENT2_8x11" "CLIENT2_22X34")
  (if (setq ss (GetBlockSelectionSet item))
  ...
  )
)
Thank you very much Lee Mac

I added it to the rest of my code and It works great!

Dear Lee Mac and BuckoAk,

What is wrong, when I do a test in the drawing DynBlkTest.dwg I get a wrong result.

Regards Harrie.

Code: [Select]
(defun GetBlockSelectionSet ( name / ss ) (vl-load-com)

  (if (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 (strcat name ",`*U*")))))
    (
      (lambda ( i / e )
        (while (setq e (ssname ss (setq i (1+ i))))
          (if (not (eq name (vla-get-EffectiveName (vlax-ename->vla-object e))))
            (ssdel e ss)
          )
        )
        ss
      )
      -1
    )
  )
)
(defun C:test(/ )
(princ "\n***************************Test*********************************************")
(princ "\n*******In drawing DynBlkTest.dwg I count 12 Cars and 6 Trees****************")
(princ "\n****************************************************************************\n")
(princ "\n****************************************************************************")
(princ "\n************************Test Results****************************************")
(setq S nil S (GetBlockSelectionSet "Car"))
(setq SL (sslength s))
(If (= SL 12)
(princ "\nThis result is good, because the selection set for the block 'Car' Counts 12")
(princ (strcat "\nThis result is wrong, because the selection set for the block 'Car' Counts " (itoa SL)))
)
(princ "\n****************************************************************************")
(setq S nil S (GetBlockSelectionSet "Tree"))
(setq SL (sslength s))
(If (= SL 6)
(princ "\nThis result is good, because the selection set for the block 'Tree' Counts 6")
(princ (strcat "\nThis result is wrong, because the selection set for the block 'Tree' Counts " (itoa SL)))
)
(princ "\n****************************************************************************")
(textpage)
(princ)
)
« Last Edit: February 03, 2011, 06:43:02 AM by Harrie »

fixo

  • Guest
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #10 on: February 03, 2011, 05:56:58 AM »
Try this
Code: [Select]
(defun getblocksbyname (bname / ss)
  (vl-load-com)
  (if (setq ss (ssget "_X"
      (list (cons 0 "INSERT") (cons 2 (strcat bname ",`*U*")))))
    (vl-remove-if
      '(lambda (blk) (not (eq bname (vla-get-effectivename blk))))
      (mapcar 'vlax-ename->vla-object
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
    )
  )


;;;Use:
(alert (strcat " Selected: "(itoa (length(getblocksbyname "Car")))" blocks \"Car\""));<-case-sensitive

Harrie

  • Guest
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #11 on: February 03, 2011, 06:49:35 AM »
Try this
Code: [Select]
(defun getblocksbyname (bname / ss)
  (vl-load-com)
  (if (setq ss (ssget "_X"
     (list (cons 0 "INSERT") (cons 2 (strcat bname ",`*U*")))))
    (vl-remove-if
      '(lambda (blk) (not (eq bname (vla-get-effectivename blk))))
      (mapcar 'vlax-ename->vla-object
     (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
    )
  )


;;;Use:
(alert (strcat " Selected: "(itoa (length(getblocksbyname "Car")))" blocks \"Car\""));<-case-sensitive
Thanks Fixo,

Code: [Select]
(alert (strcat " Selected: "(itoa (length(getblocksbyname "Car")))" blocks \"Car\""))and
Code: [Select]
(alert (strcat " Selected: "(itoa (length(getblocksbyname "Tree")))" blocks \"Tree\""))gives a good result in DynBlkTest.dwg.

Regards Harrie.
« Last Edit: February 03, 2011, 08:23:49 AM by Harrie »

fixo

  • Guest
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #12 on: February 03, 2011, 07:06:47 AM »
Glad, if so
Cheers :)

Harrie

  • Guest
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #13 on: February 03, 2011, 07:10:17 AM »
Dear Fixo,

But how I get the selection set?
I want to change the Visibility State in PROPERTIES.
Is this the correct way:
Code: [Select]
(defun GetBlocksByName2 (bname / ss)
  (vl-load-com)
  (if (setq ss
    (ssget "_X"
   (list (cons 0 "INSERT") (cons 2 (strcat bname ",`*U*")))
    )
      )
    (progn
      (setq SSLst
    (vl-remove-if
      '(lambda (blk)
 (not (eq (strcase bname) (strcase (vla-get-effectivename blk))))
)
      (mapcar 'vlax-ename->vla-object
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      )
    )
      )
      (setq i  0
   ss nil
   ss (ssadd)
      )
      (repeat (length SSLst)
(setq ss (ssadd (vlax-vla-object->ename (nth i SSLst)) ss))
(setq i (1+ i))
      )
    )
  )
ss
)
and for drawing DynBlkTest.dwg with dynamic block Tree
Code: [Select]
(alert (strcat " Selected: "(itoa (sslength (GetBlocksByName2 "Tree")))" blocks \"Tree\""))and
Code: [Select]
(command "_.SELECT" (GetBlocksByName2 "Tree"))and
Code: [Select]
(command "_.PSELECT" (GetBlocksByName2 "Tree") "")Regards Harrie.
« Last Edit: February 04, 2011, 06:58:24 AM by Harrie »

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Dynamic Blocks Names vs. Non Dynamic Block names
« Reply #14 on: February 03, 2011, 10:39:43 AM »
Look into sssetfirst:

Code: [Select]
(defun getblocksbyname2 (bname / obj ss ss2)
  (vl-load-com)
  (setq ss2 (ssadd))
  (if (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 (strcat bname ",`*U*")))))
    (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq obj (vlax-ename->vla-object blk))
      (and (eq (strcase bname) (strcase (vla-get-effectivename obj))) (setq ss2 (ssadd blk ss2)))
    )
  )
  (sssetfirst nil ss2)
)
« Last Edit: February 03, 2011, 10:42:54 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC