Author Topic: Batch automation of View files  (Read 2876 times)

0 Members and 1 Guest are viewing this topic.

cvcolomb

  • Guest
Batch automation of View files
« on: June 01, 2012, 03:38:08 PM »
Hello,
I'm trying to automate the updating of View files in a Project setting. My client has an extensive set of LISP routines to run VPLAYER in Viewports and set visibility & color for different scenarios. When the Model has been updated however, these View .dwgs need to be opened and have the LISP routines run again to make sure new objects are displayed.

I had thought to write a .NET routine in which the user picked a folder, I found all of the .dwg files, opened each .dwg, activated each Viewport in turn and ran the correct LISP routine. I've already updated their LISP so that as each routine is used it stores an Xrecord of it's name in a custom dictionary, keyed by the Viewport handle. I can present the dialog, find .dwg files in a selected folder, loop through layouts & Viewports just fine however...

...I can't seem to open .dwgs programmatically and have access to LISP commands. I have the LISP routines set to load in the Startup Suite of the AppLoad Dialog, and they're certainly available when you open the .dwg manually. I've tried 2 approaches to automating this:

AcadApplication.Invoke(args)
When this runs, the LISP command is not recognized "No function definition..". This is especially strange as a custom *error* message from my LISP library is displayed. The LISP must be loaded, other posts here seem to indicate that Invoke() (managed wrapper for acedInvoke() I believe) cannot operate outside the document the .NET routine was called from.

acadApp.GetType().InvokeMember("SendCommand",System.Reflection.BindingFlags.InvokeMethod, null,acadApp, acCommand);
This throws an error, "Unknown name. (Exception from HRESULT:0x80020006(DISP_E_UNKNOWNNAME))"

SentToCommand is obviously out as it only runs once the .NET has exited.

Anyone done anything similar? Am I missing something in the above, or is there a different approach possible?

Any help is appreciated,
cc

cvcolomb

  • Guest
Re: Batch automation of View files
« Reply #1 on: June 05, 2012, 06:37:19 PM »
OK, maybe I'll have more luck in the LISP forum ;-p

MexicanCustard

  • Swamp Rat
  • Posts: 705
Revit 2019, AMEP 2019 64bit Win 10

cvcolomb

  • Guest
Re: Batch automation of View files
« Reply #3 on: June 06, 2012, 10:11:42 AM »
Thanks for the input.

I'd found those posts, and I got TheMaster's code to work -- but only in the .dwg you call .NET from. In .dwg files you open from .NET, custom LISP commands are not recognized (even when declared with c: or registered with (vl-acad-defun ...)

Even stranger, i know my LISP routines are loaded into the newly opened .dwg because my custom *error* function is triggered when the function I call isn't recognized.

I also tried opening .dwgs and running my .NET routine with a script file, but this doesn't work. The .NET command I created works just fine if you open a .dwg, netload the .dll, and call the command. When done via scripting however, the command appears to run--however not all present viewports are updated (it's flawless when run by the user) and changes are not saved by QSAVE in the script.

Down to plan F or so, I think I'll have to define a LISP function to cycle through Viewports and update their layer states. Hopefully the LISP command will be recognized and run properly in a scripting scenario, then I can define a .NET routine to create the .scr from a directory selected by the user.

57gmc

  • Bull Frog
  • Posts: 367
Re: Batch automation of View files
« Reply #4 on: June 06, 2012, 11:57:28 AM »
Have you tried ScriptPro? It is designed to run a lisp on a batch of files. All you need a  lisp that works on a single file. Then you run ScriptPro, select a batch of files, specify the script to use and let it run. You can download ScriptPro from Autodesk Labs. I think you can even get the source code.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Batch automation of View files
« Reply #5 on: June 06, 2012, 03:46:18 PM »
What method are you using to open the files in .NET?
Revit 2019, AMEP 2019 64bit Win 10

cvcolomb

  • Guest
Re: Batch automation of View files
« Reply #6 on: June 06, 2012, 10:35:39 PM »
ScriptPro, news to me! I'll check it out.

Here's the snippet from where I open a .dwg from a file name, is there another way??

Code: [Select]
        public static int UpdateViewports(string fileName)
        {
            int numUpdated = 0;
           
            DocumentCollection acDocMgr = Application.DocumentManager;

            if (File.Exists(fileName))
            {



                acDocMgr.Open(fileName, false);
                Document acDoc = acDocMgr.MdiActiveDocument;
                Editor ed = acDoc.Editor;
.......
}


cvcolomb

  • Guest
Re: Batch automation of View files
« Reply #7 on: June 06, 2012, 10:43:29 PM »
Actually, after looking it up it appears that Script Pro from labs.autodesk.com runs a SCRIPT file on a set of .dwg files, not lisp functions. Also, I don't believe you can call LISP functions defined as (defun: c:<name>()...) in a scripting run, you can only call OOTB commands.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Batch automation of View files
« Reply #8 on: June 06, 2012, 11:12:51 PM »
Actually, after looking it up it appears that Script Pro from labs.autodesk.com runs a SCRIPT file on a set of .dwg files, not lisp functions. Also, I don't believe you can call LISP functions defined as (defun: c:<name>()...) in a scripting run, you can only call OOTB commands.

You CAN load lisp files from scripts.

You CAN run Lisp commands from scripts.
Code: [Select]
(LOAD "c:\\ScriptPro 2.0\\CodeFiles\\UpdatePaintSystem-X416-ref.lsp")
(UpdatePaintSystem-X416-ref)
(LOAD "c:\\ScriptPro 2.0\\CodeFiles\\Remove Bechtel Approval Stamps.lsp")
(Remove_Bechtel_Approval_Stamps)

Code - Auto/Visual Lisp: [Select]
  1. ;;(updatepaintsystem-x416-ref)
  2. ;; Rev 2011.08.07
  3.  
  4. (defun updatepaintsystem-x416-ref ()
  5.   (setq exprt (getvar "expert"))
  6.   (setvar "EXPERT" 5)
  7.   (command "-layer" "set" "0" "")
  8.   (command "Zoom" "All")
  9.   (repeat 3 (command "-PURGE" "ALL" "*" "N"))
  10.   ;;
  11.   (if (setq ss (ssget "X" '((2 . "PAINT SYSTEM 16"))))
  12.         (progn
  13.           (vl-cmdf "_.rename"
  14.                            "block"
  15.                            "PAINT SYSTEM 16"
  16.                            "PAINT SYSTEM 1"
  17.           )
  18.           (vl-cmdf
  19.                 "_.Insert"
  20.                 "PAINT SYSTEM 1=P:\\ProjBlocks\\PAINT SYSTEM 1.dwg"
  21.                 (list 0. 0. 0.)
  22.                 1
  23.                 1
  24.                 0
  25.           )
  26.           (vl-cmdf "_erase" (entlast) "")        
  27.         )
  28.   )
  29.   (vl-cmdf "_.Audit" "Y")
  30.   (repeat 3 (command "-PURGE" "ALL" "*" "N"))
  31.   (setvar "EXPERT" exprt)
  32.   (command "QSAVE")
  33.   (princ)
  34. )
  35.  
  36.  
  37.  

Code - Auto/Visual Lisp: [Select]
  1. ;;(Update_Bechtel_Approval_Stamps)
  2. ;; KDUB 2011-09-28
  3. ;; (update_bechtel_approval_stamps)
  4.  
  5. (defun update_bechtel_approval_stamps (/ *error*)
  6.   (defun *error* (msg)
  7.         (kdub:on-error msg)
  8.         ;;
  9.         (princ)
  10.   )
  11.   (vla-endundomark kglobal:activedoc)
  12.   (vla-startundomark kglobal:activedoc)
  13.   ;;-----------------------------------------------------------
  14.   (kdub:savesysvar
  15.         '(("CMDECHO" 0) ("OSMODE" 0) ("expert" 5) ("PLINEGEN" 1))
  16.   )
  17.   ;;-----------------------------------------------------------
  18.   (command "-layer" "set" "0" "")
  19.   (command "Zoom" "All")
  20.   ;;
  21.   (if (setq ss (ssget "X" '((2 . "Bechtel Approval Stamp*"))))
  22.         (progn
  23.           (setq obj                     (vlax-ename->vla-object (ssname ss 0))
  24.                         insertpoint     (vlax-get obj 'insertionpoint)
  25.                         insertscale     (vlax-get obj 'xscalefactor)
  26.                         blockname       (vlax-get obj 'name)
  27.           )
  28.           (cond
  29.                 ((or (= blockname "Bechtel Approval Stamp")
  30.                                    (= blockname "Bechtel Approval Stamp Rev 001")
  31.                          )
  32.                          (setq newblockname "Bechtel Approval Stamp Rev 002")
  33.                         )
  34.                         ((= blockname "Bechtel Approval Stamp Rev 002")
  35.                          (setq newblockname "Bechtel Approval Stamp Rev 003")
  36.                         )
  37.                         ((= blockname "Bechtel Approval Stamp Rev 003")
  38.                          (setq newblockname "Bechtel Approval Stamp Rev 004")
  39.                         )
  40.           )
  41.           (if (setq
  42.                         qualifiedblockname (findfile (strcat "P:\\ProjBlocks\\"
  43.                                                                                                  newblockname
  44.                                                                                                  ".dwg"
  45.                                                                                  )
  46.                                                            )
  47.                   )
  48.                   ;; if found
  49.                 (progn (vl-cmdf "_.erase" ss "")
  50.                            (vl-cmdf     "_.Insert"                qualifiedblockname
  51.                                                 insertpoint               insertscale
  52.                                                 insertscale               ""
  53.                                            )
  54.                            (vl-cmdf "_.CHPROP" (entlast) "" "LA" "ST-BLOCKS" "")
  55.                 )
  56.                 ;; else
  57.                 (progn
  58.                   (prompt
  59.                         (strcat "\n Can't find required Block ; "
  60.                                         (strcat "P:\\ProjBlocks\\" newblockname ".dwg")
  61.                         )
  62.                   )
  63.                   (alert "ooooooooooooooooooooooooooooooooops")
  64.                 )
  65.           )
  66.         )
  67.   )
  68.   (command "QSAVE")
  69.   (*error* nil)
  70.   (princ)
  71. )
  72.  
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Batch automation of View files
« Reply #9 on: June 06, 2012, 11:14:43 PM »


If the lisp command is defined
(defun c:xxxx () (princ) )

it can be called in the script or lisp using (c:xxxx)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

BlackBox

  • King Gator
  • Posts: 3770
Re: Batch automation of View files
« Reply #10 on: June 07, 2012, 01:54:22 AM »
Code - Auto/Visual Lisp: [Select]
  1. ;; ...
  2. (alert "oooooooooooooooooooops!")
  3. ;; ...
  4.  

 :lmao:
"How we think determines what we do, and what we do determines what we get."

cvcolomb

  • Guest
Re: Batch automation of View files
« Reply #11 on: June 07, 2012, 10:53:54 AM »
Interesting, so having my LISP routine in the StartupSuite is not enough, I have to load it explicitly in the script.

Possible, but pretty messy. My client stores each routine as a separate file -- I think I'll keep the script approach around for a hail Mary.

In the meantime, there seems to be some confusion on the LISP issue, check out the discussion there if you're interested:

http://www.theswamp.org/index.php?topic=41930.0

Or take a look at this brief sample, how do you call a LISP function when your function name is stored in a string variable? The code below is an example, it doesn't work giving both "no function definition" and "/FUN1bad argument..."

Code: [Select]
(defun c:test1()
  (princ "Test 1 ran")
  )

(defun c:runTest(/ fun1 )
(setq fun1 "c:test1")

(eval (read fun1))

)

cvcolomb

  • Guest
Re: Batch automation of View files
« Reply #12 on: June 07, 2012, 12:17:38 PM »
FYI Gents, RenderMan, irneb & Lee Mac straightened me out on getting a function call from a variable.

Previously I had (eval (read fun1))

Should be ((eval (read fun1)))

Swamp rules ;-}