TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ELOQUINTET on February 06, 2004, 04:06:43 PM

Title: equal dimension lisp needed
Post by: ELOQUINTET on February 06, 2004, 04:06:43 PM
hey guys i was wondering if anyone has a lisp that will replace the dimension text <> of a selected dimension with eq.

thanks
Title: equal dimension lisp needed
Post by: CADaver on February 06, 2004, 04:13:09 PM
Code: [Select]

(defun C:DTX  () (command ".dim1" "newtext" "EQ"))
Title: equal dimension lisp needed
Post by: ELOQUINTET on February 06, 2004, 04:37:19 PM
thanks cadaver works great
Title: equal dimension lisp needed
Post by: CADaver on February 06, 2004, 06:32:29 PM
Glad to have been of service.  I'm sure there's a much more elegant way to do it that some of the magicians around are working on as we speak...  er... write...  um.... type?
Title: equal dimension lisp needed
Post by: daron on February 09, 2004, 09:56:48 AM
Nope! Why make it harder than what he's asked for and you've given.
Title: equal dimension lisp needed
Post by: ELOQUINTET on February 09, 2004, 11:03:06 AM
yeah no need to reinvent the wheel
Title: equal dimension lisp needed
Post by: Columbia on February 09, 2004, 12:30:23 PM
But then again, if you like to reinvent, here's another way to do it that doesn't use the command pipeline, but rather the VL/Active-X pipeline.

Code: [Select]

(defun c:eqdim (/ ss o i)
  (vl-load-com)
  (while
    (progn
      (princ "\nSelect dimension(s) to override text with EQ...")
      (setq ss (ssget "X" (list (cons 0 "DIMENSION")))) ;; build the selection set
    )
    (setq i 0) ;; setup a counter
    (repeat (sslength ss) ;; repeat for as many is in the selection set
      (setq o (vlax-ename->vla-object (ssname ss i)) ;; setup the Active-X object
            i (1+ i) ;; increment counter
      )
      (vla-put-TextOverride o "EQ") ;; override the text using the TextOverride property
(vlax-release-object o) ;; done with the object go ahead and release it...
    )
  )
  (princ)
)
Title: equal dimension lisp needed
Post by: Matt Stachoni on February 09, 2004, 07:56:45 PM
Referring back to a post I made in the "Show Yer Stuff" forum, here's a generic function that applies a function across all objects in a selection set
Code: [Select]
(defun ent:SSObjApply (fun ss / i)
  ;|Description:
      Process a function on each vla-object in a selection set.
    Example:
      (ent:SSObjApply '(lambda (VlaObj) (..Do sonething to VlaObj...)) ss)
  |;
  (setq i -1)
  (if (= 'PICKSET (type ss))
    (repeat (fix (sslength ss))
      (apply fun
        (list
          (vlax-ename->vla-object
            (ssname ss (setq i (1+ i)))
          )
        )
      )
    )
  )
)
It's kind of like a foreach for selection sets. Implementing it in a "EQ." macro, you simply do this:
Code: [Select]
(defun c:EQ ()
  ;|Description:
      Replace dimension text with "EQ."
  |;
  (prompt "\nEQ. Dimension.")
  (ent:SSObjApply
   '(lambda (DimObj)
      (vla-put-TextOverride DimObj "EQ.")
    )
    (ssget '((0 . "DIMENSION")))
  )
  (princ)
)
I like this approach because it filters for Dimensions in the selection set process. Using a simpler macro would mean it would error out if you didn't pick the right kind of entity.
Alaso, using the generic function in this way, it's very easy to write tens of macros using almost the same code.