Author Topic: Run a LISP routine across all open drawings  (Read 4550 times)

0 Members and 1 Guest are viewing this topic.

rhino

  • Guest
Run a LISP routine across all open drawings
« on: December 30, 2009, 12:15:10 AM »
Hello all & Complements of the season!

I'm looking for a way that will let me run a LISP across all open drawings -

I like the way this routine works; but can't seem to get it to work for the purpose I need
http://www.theswamp.org/index.php?topic=30704.msg362918#msg362918

nivuahc

  • Guest
Re: Run a LISP routine across all open drawings
« Reply #1 on: December 30, 2009, 06:32:30 AM »
Will this work for you?

Code: [Select]
(defun c:sample ( / OpenDwgs eachDwg)
(setq OpenDwgs (vla-get-documents (vlax-get-acad-object)))
(vlax-for eachDwg OpenDwgs
(do_some_stuff)
    ) ;_ end vlax-for
) ;_ end defun

/it's early in the morning, I haven't had my coffee, and I haven't actually tested the above for correctness but I'm pretty sure it's what you're after

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Run a LISP routine across all open drawings
« Reply #2 on: December 30, 2009, 08:05:50 AM »
Example:

Code: [Select]
(defun atedit (blk lst / dwg lay obj att tag)
  (vl-load-com)

  (mapcar 'set '(blk lst)
          (list (strcase blk)
                (mapcar (function (lambda (x) (list (strcase (car x))
                                                    (cadr x) (caddr x)))) lst)))

  (vlax-for dwg (vla-get-Documents (vlax-get-acad-object))

    (vlax-for lay (vla-get-layouts dwg)

      (vlax-for obj (vla-get-Block lay)

        (if (and (eq "AcDbBlockReference" (vla-get-ObjectName obj))
                 (eq (vla-get-HasAttributes obj) :vlax-true))

          (foreach att (vlax-invoke obj 'GetAttributes)

            (if (and (setq tag (assoc (strcase (vla-get-TagString att)) lst))
                     (eq (vla-get-TextString att) (cadr tag)))

              (vla-put-TextString att (caddr tag)))))))

    (vla-regen dwg acAllViewports))

  (princ))


(defun c:test ( )

  (atedit "Block Name" '(("TAG1" "Old Value" "New Value")
                         ("TAG2" "Old Value" "New Value")))

  (princ))

rhino

  • Guest
Re: Run a LISP routine across all open drawings
« Reply #3 on: December 30, 2009, 11:15:15 AM »
Will this work for you?

Code: [Select]
(defun c:sample ( / OpenDwgs eachDwg)
(setq OpenDwgs (vla-get-documents (vlax-get-acad-object)))
(vlax-for eachDwg OpenDwgs
([color=red]command "_zoom" "e"[/color])
    ) ;_ end vlax-for
) ;_ end defun

/it's early in the morning, I haven't had my coffee, and I haven't actually tested the above for correctness but I'm pretty sure it's what you're after

unfortunately it does not cycle through the open drawings as its required to...

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Run a LISP routine across all open drawings
« Reply #4 on: December 30, 2009, 11:30:27 AM »
It does, but you cannot use "command" calls in documents other than the active one.

rhino

  • Guest
Re: Run a LISP routine across all open drawings
« Reply #5 on: December 30, 2009, 11:39:12 AM »
It does, but you cannot use "command" calls in documents other than the active one.

umm so whats the work around?

a call to lisp function? - can that have calls to "command"?
I need it to do simple batch plot thingy that plots all open drawings in modelspace with extents

appreciate the help :)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Run a LISP routine across all open drawings
« Reply #6 on: December 30, 2009, 11:50:47 AM »
The workaround is

Code: [Select]
(vla-ZoomExtents <app>)
But I believe this too will only work on the active Document. - a discussion here:

http://discussion.autodesk.com/forums/message.jspa?messageID=1184966



rhino

  • Guest
Re: Run a LISP routine across all open drawings
« Reply #7 on: December 30, 2009, 12:28:33 PM »
The workaround is

Code: [Select]
(vla-ZoomExtents <app>)
But I believe this too will only work on the active Document. - a discussion here:

http://discussion.autodesk.com/forums/message.jspa?messageID=1184966


I think i can use the code posted here:
http://discussion.autodesk.com/forums/thread.jspa?threadID=453185

rhino

  • Guest
Re: Run a LISP routine across all open drawings
« Reply #8 on: December 31, 2009, 04:35:10 AM »
unfortunately it does not seem to work  :-o

so what about the VB or .net code anyone have a solution?

The program I require is similar to this posted by Tim http://www.theswamp.org/index.php?topic=31091.msg366740#msg366740 - but required for printing from modelspace with extents selected.