Author Topic: Help getting block lookup, or, finding the block(s) in a drawing.  (Read 1602 times)

0 Members and 1 Guest are viewing this topic.

Rabbit

  • Guest
I need to set the lookup parameter of a dynamic block.

I can get the block using (and if anyone can tell me how to get an selection set without zooming, I'd be very grateful)
Code - Auto/Visual Lisp: [Select]
  1. (command "_Zoom" "C" (list 271.5 1124.0 0.0) 400.0)
  2. (setq SSet (ssget "_C" (list 160.0 1052.0 0.0) (list 525.00 1200.0 0.0)))
  3. (CHGDYNPROP (ssname SSet 0) "Lookup1" Lookup)
  4.  
and then run it through the routine
Code - Auto/Visual Lisp: [Select]
  1. (defun CHGDYNPROP (Ename propname newval / obj v vval sal tot i)
  2.     ;; Changes a given variable in your block
  3.     ;; Passed: Ename, Property Name, New value for Property
  4.     ;;
  5.     (setq obj (if (= (type Ename) 'vla-object)
  6.                 Ename
  7.                 (vlax-ename->vla-object Ename))
  8.           v (vla-getdynamicblockproperties obj)
  9.           vval (vlax-variant-value v)
  10.           sal (vlax-safearray->list vval)
  11.           tot (length sal)
  12.           i 0)
  13.     (while (< i tot)
  14.       (if (= (vlax-get-property (nth i sal) "PropertyName") propname)
  15.         (progn
  16.           (vlax-put-property (nth i sal) "Value" newval)
  17.           (setq i tot)
  18.         )
  19.         (setq i (1+ i))
  20.       )
  21.     )
  22.   )

This all work great as long as the block is in a location I can zoom to and then grab.  The problem is when it has been moved to a different location on the screen.

This doesn't work because the block's name has changed to an anonymous block name:
Code - Auto/Visual Lisp: [Select]
  1. (SSGET "X" '((2 . "BLOCKNAME")))

I've tried this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.    (if
  3.      (and
  4.        (= :vlax-false (vla-get-islayout block))
  5.        (= :vlax-false (vla-get-isxref block))
  6.        (not (wcmatch (setq name (vla-get-name block)) "`**"))
  7.        (= :vlax-true (vla-get-IsDynamicBlock block))
  8.        (wcmatch (setq name (vla-get-name block)) "BLOCKNAME")
  9.      )
  10.      (CHGDYNPROP block "Lookup1" Lookup)
  11.    );if
  12.  );vlax-for
  13. );defun
  14.  

I can find the block okay, I think.  When I inspect the variable "block" it says its a VLA-OBJECT |AcadBlock.  I try to get info on different parts and I get errors.  Since the subroutine will accept enames, I tried (vlax-vla-object->ename block) and it returns the ACAD BLOCK_RECORD.  I don't know how to handle this.

What is the way to get this block in a form that I can use the CHGDYNPROP subroutine to set the lookup parameter?

Thanks,
Rabbit

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Help getting block lookup, or, finding the block(s) in a drawing.
« Reply #1 on: February 21, 2013, 11:06:36 AM »
If the dynamic block is modified, you have to look for the effectivename of the block. Perhaps the snippits below will shed some light :)

Code - Auto/Visual Lisp: [Select]
  1. (defun _getblockname (o)
  2.   (and (= (type o) 'ename) (setq o (vlax-ename->vla-object o)))
  3.   (cond ((vlax-property-available-p o 'effectivename) (vla-get-effectivename o))
  4.         ((vlax-property-available-p o 'name) (vla-get-name o))
  5.   )
  6. )
  7.  
  8. (defun _getblockss (name / e i ss)
  9.   (setq i -1)
  10.   (if (setq ss (ssget "_X" (list (cons 2 (strcat name ",`**")))))
  11.     (while (setq e (ssname ss (setq i (1+ i))))
  12.       (if (not (eq (strcase (_getblockname e)) (strcase name)))
  13.         (progn (ssdel e ss) (setq i (1- i)))
  14.       )
  15.     )
  16.   )
  17.   ss
  18. )
  19. (_getblockss "blockname")
  20.  

Here is a filter that will get a block in the current space that has an insertion point within two specified points.

Code - Auto/Visual Lisp: [Select]
  1. (setq bl '(0 0)
  2.       ur '(1 1)
  3. )
  4. (ssget "_X"
  5.        (list '(0 . "insert")
  6.              (cons 410 (getvar 'ctab))
  7.              '(-4 . "<AND")
  8.              '(-4 . ">=,>=")
  9.              (cons 10 bl)
  10.              '(-4 . "<=,<=")
  11.              (cons 10 ur)
  12.              '(-4 . "AND>")
  13.        )
  14. )
  15.  
« Last Edit: February 21, 2013, 11:35:37 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Rabbit

  • Guest
Re: Help getting block lookup, or, finding the block(s) in a drawing.
« Reply #2 on: February 26, 2013, 11:49:04 AM »
Sorry for taking so long to get back.  There's thing I have to do sometimes to pay the bills, it's called work.

The _getblockss routine did great with one exception, it was getting stuff other than blocks.  So I changed the SSGET section to this
Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 (strcat name ",`**")))))
Works perfectly.  Thanks for posting it.  I picked up a some new ways of thinking with this.

Thank you,
Rabbit

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Help getting block lookup, or, finding the block(s) in a drawing.
« Reply #3 on: February 26, 2013, 12:03:24 PM »
Glad you got the filter sorted out and it gave some ideas. :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC