CAD Forums > CAD General

Changing blocks globeally

<< < (3/3)

daron:
Either before or after:

--- Code: ---(vl-load-com)
(defun...()
(vl-load-com)
(rest of code here.)
)
--- End code ---

You wouldn't need to put it in both places and it only needs to be in one place as long as it occurs before any vl- functions are activated.

42:
iT WORKS Many thanks


--- Code: ---
(vl-load-com)
(defun attribute-list (x)
     (vlax-safearray->list
     (vlax-variant-value
          (vla-GetAttributes x)
     )
     )
)
(defun each-attribute (x string newval)
     (if (= (vlax-get-property x 'TagString) string)
     (vlax-put-property
          x
          'TextString
          (vlax-make-variant newval vlax-vbstring)
     )
     )
)
(defun ssget->vla-list (selection-set / index vla-list)
     (setq index (if selection-set
            (1- (sslength selection-set))
            -1
       )
     )
     (while (>= index 0)
     (setq   vla-list
          (cons
               (vlax-ename->vla-object
               (ssname selection-set index)
               )
               vla-list
          )
      index    (1- index)
     )
     )
     vla-list
)
;;;=====================================================================;
;;; increments level blocks globally                                 ;
;;;=====================================================================;
(defun c:cbg (/ objlist n incval atts)
  (setq objlist (ssget->vla-list (ssget '((0 . "INSERT") (66 . 1)))))
  (setq n nil)
  (initget 2)
  (setq incval (getreal "\nType the value to add to each string: "))
  (foreach item   objlist
    (setq atts (attribute-list item))
    (foreach val atts
      (each-attribute
   val
   "LEVEL"
   (+ (atof (vla-get-textstring val))
      incval
   )
      )
    )
  )
  (princ)
)
--- End code ---

daron:
You're highly welcome. Now, open the vlide and test each line. I wouldn't want you to just take off with code without understanding what makes it work. BTW, two of the functions were not written by me. I stole them too.

Trev:
How'd it go 42?
Sorry I havn't got back to you earlier. Been pretty busy lately &
no internet connection at work.  :shock:  hence why I have been a bit on the quite side.
been a bit side tracked so haven't got back to it.
The method I was doing (using lisp) was to select an attribute & from that selection
obtain the block name and the attribute tag. From there loop through the
the drawing table for each said block and add your addition to the value
of selected attribute. Including dialog box for ease of use.
(if that all makes sense)
The objective was so it could be used on any block with any attribute, that way it may have many uses in the future  :)  trying to think ahead really  :shock:
However I did hit a little snag, a major mental block.
I had 2 versions 1 would select the block and loop through finding all attributes. This was no good as I wanted it to be specific to the selected attribute.
The 2nd I could select the attribute and obtain tag & value, this was good but for some dumb reason I couldn't find the block name  :oops:
using nentsel for this but the assoc value 0 would return "insert" obviously
rather than the blockname if entsel was used.
I should do the VBA version. It would be a very similar program to the one I did for Daron (gatte.dvb)

Navigation

[0] Message Index

[*] Previous page

Go to full version