Author Topic: Updating model space display extents  (Read 9992 times)

0 Members and 1 Guest are viewing this topic.

LE3

  • Guest
Re: Updating model space display extents
« Reply #30 on: March 24, 2010, 11:05:54 AM »
Luis, yours did not work for me either, when applied from a single command. I tried using other command flags but no go  :mrgreen:

could be.... got to go now.... will see it was working here  :-(

owenwengerd

  • Bull Frog
  • Posts: 439
Re: Updating model space display extents
« Reply #31 on: March 24, 2010, 01:28:52 PM »
If AutoCAD updates the needed internal state when a command ends, then there is your answer: execute a command to update the state.

shawndoe

  • Guest
Re: Updating model space display extents
« Reply #32 on: March 24, 2010, 04:55:07 PM »
Hi,

First Owen, your websight and your knowledge have been very helpful to me over the years, and I wanted to thank you.

I don't think AutoCAD is updating at the end of a command, but on the return to the command line.  It creates the buffer (for graphic related vars?) when you leave the command line for any LISP, VBA, or ARX/Native command.  AutoCAD will continue to get data from that buffer as long as any of these is open, even if it is in a separate drawing. 

In my case what this means is I have a batch routine I run from Drawing1.  AutoCAD creates a buffer as soon as you start the batch LISP in drawing1.  The LISP opens a set of drawings one at a time, and executes my LISP in S::StartUp. When the work drawing loads, the data has already been placed in a buffer for that drawing.  Normally AutoCAD would update the data in that buffer after AcadDoc.lsp etc. finish, and the drawing is ready for user input.  In my case, at this point focus shifts back to Drawing1 where we are still in LISP.

What I have found using vla-SendCommand and other tricks is that, while LISP execution has finished in the work drawing it continues in Drawing1, so the data in the buffers remains there for BOTH drawings.  If you save and close the work drawing before leaving LISP AutoCAD will save any changes you may have made to the database, but whatever changes occurred to that buffer data will be lost.  This means that while I can resize a drawing window, I can't get AutoCAD to acknowledge the change, or save it.  I had similar results with VBA.

Now you know why I am tackling an ARX project even though I still need to work on my C++ skills a bit more.  Still, I'm learning alot, working a difficult problem, while doing something useful, and that's the best kind of learning.  It sticks

Have a good one, and thanks again.
Shawn

owenwengerd

  • Bull Frog
  • Posts: 439
Re: Updating model space display extents
« Reply #33 on: March 24, 2010, 05:37:38 PM »
I appreciate the kind words.

Without spending more time understanding the problem I don't have any specific advice, but I would solve this problem by reverse engineering what triggers the cached data to be updated, then doing whatever needs to be done to flip the switch that triggers it. If the switch is "complete all pending commands", then that is what your code has to do (or at least simulate). It's possible that having the ObjectARX (and VBA) ability to run in the application context could prove useful, but I'd bet that it can be done just as well via lisp.

pkohut

  • Guest
Re: Updating model space display extents
« Reply #34 on: March 24, 2010, 06:21:29 PM »
Don't know if it's just me or what, but I have had a heck of a time trying to follow your descriptions.

It would probably be better to describe the work your trying to accomplish rather than side effects of Autocad and the interaction with your routine.

However, your latest description raises these questions (I'm confused and stepping aside) -
Are you trying to send data back and forth between drawings, with some sort of inter process communication?
What does the send command look like?
What is this mystery buffer?
Can't the data be persisted to a file instead of the mystery buffer?
Batch routine == lisp routine?
What about running a script instead of the batch (lisp) routine? Create on the fly if needed?

LE3

  • Guest
Re: Updating model space display extents
« Reply #35 on: March 25, 2010, 03:19:27 PM »
Quote
(I'm confused and stepping aside)


x2

shawndoe

  • Guest
Re: Updating model space display extents
« Reply #36 on: March 25, 2010, 08:19:42 PM »
Hi,

The Tririga publish to server function is at the root of why I need to change the window size.  The publish function zooms to extents in the drawing window, creates a DWF of the display, then attaches a bunch of database links to the DWF, and finally uploads it to our server.  At the root of this is a need to get the aspect ratio of the client window the same as my titleblock. I can't have any dead space around edges of the DWF throwing off the scale when the DWF printed out.  That is why I used that little test LISP that used SetWindow, and zoomed to extents, because that is what the publish function does before creating the DWF.

I hope this helps explain what I am trying to do, and why I'm fighting so hard with the window size setting.  I have only found 2 problems that I could not solve using a LISP at StartUp, the first is user input at the command line, and the second is this window issue.

The only data transfers are done using vl-bb-set/ref.  I don't send commands to the work drawing usually. I have experimented with doing so, to set the window size, after StartUp.  All attempts to use vla-SendCommand from the work drawing in StartUp, or from Drawing1 after the work drawing open and return, failed.  You can see verious attempts at it in the code below.

The desciption of a command in the MDI terminology is also descriptive of when updating the window size fails.  The "Mystery Buffer" is something that I think is created when AutoCAD executes a command as defined in the MDI terminology.  I'm honestly not sure what this buffer is called, but I'm certain it exists. 

I don't think AutoDesk would write a file everytime you run a command.  It just seems like a lot of effort for something done that often, and that could be held in memory with less overhead.

I have tried to avoid doing batch runs with scripts because it always felt like a kludge to me.

I will try to describe how my LISP routine works.  I'm going to post snippets of code because I don't think anybody wants to see dialogue box handling or string parsing.

(1) Start SDMU Batch LISP. (Code not shown)
    (1a) Start dialogue box.
        (1a.1) Set drawing directory and drawing name wildcard filters. (accepts .lnk)
        (1a.2) Select sub-directory processing mode. (Root, 1st Level, All)
        (1a.3) Select preset LISP files to be run. (radio buttons)
        (1a.4) Allow user to select a LISP from file dialogue if needed.
    (1b) Select directory for processing.

(2) Store collected LISP routines and aurgument data (vl-bb-set/ref)
   
(3) Collect Directory and FileList data.

(4) Begin processing directories.
    (4a) Supply directory, fileList, and savemode to DrawingActivator.
    (4b) DrawingActivator cycles through all drawings in the Filelist
    (4c) Drawings are opened but not set active.
    (4d) Drawings opened using the code snippet below
        (4d.1) Drawing open
        (4d.2) Windowresize experiments
        (4d.3) Close and save if set.
        (4d.4) Release drawing handle.

Code: [Select]
;
; *************************************  Open Drawing  **************************************
;
        (if (and
               (findfile FileString)
;               (<= (DwgFileVersion FileString) 18)
            );and
           (progn
;
; Normal Operation
;
;              (vl-bb-set 'BaseDwg (vla-get-activedocument (vlax-get-acad-object)));
              (vl-bb-set 'WrkDwg (setq WrkDwg (vla-open (vla-get-documents (vlax-get-acad-object)) FileString)));
;
; Other Operations on Work Drawing (window resizing)
;
              (princ "\nZoom Dwg1")(print)
;              (vla-zoomextents WrkDwg)
;              (princ "Zoom WrkDwg")(print)
;              (vla-sendcommand WrkDwg "Zoom Extents (vla-activate (vl-bb-ref 'BaseDwg))\r")
;              (vla-sendcommand WrkDwg "(ACADWindowSize 830 564 (vl-bb-ref 'WrkDwg)) (vla-activate (vl-bb-ref 'BaseDwg))\r")
              (princ "WindowResize")(print)
              (vla-put-width WrkDwg 1254)
              (vla-put-height WrkDwg 846)
;              (vla-sendcommand WrkDwg "Zoom Extents (vla-activate (vl-bb-ref 'BaseDwg))\r")
;              (vla-zoomextents WrkDwg)
;              (princ "Reset Zoom")(print)
;              (vla-sendcommand WrkDwg "(c:cipublish)(wait) (vla-activate (vl-bb-ref 'BaseDwg))\r")
;              (vla-sendcommand WrkDwg "Zoom Extents (vla-activate (vl-bb-ref 'BaseDwg))\r")
              (princ "Publish")(print)
;              (vla-sendcommand WrkDwg "(c:ciPublish) \r")
              (wait)
;
; ********************************  Save and Close Drawing  *********************************
;
              (if (and (= SaveMode T)
                       (/= (vl-bb-ref 'Error) File)
                  );and
                (progn
                   (vla-save WrkDwg)
                   (wait)
                   (vla-close WrkDwg :vlax-false)         ; If T save on close for batch republish
                   (princ "\nDrawing saved by SDMU. ")
                ); progn If
                (progn
                   (vla-close WrkDwg :vlax-false)        ; Else do not Save on close for batch republish
                   (princ "\nDrawing not saved by SDMU. ")
                ); progn else
        );if
        (wait) ; Wait for Active Commands to finish
      (vl-bb-set 'Error nil)
;
;  *******************************  Release Drawing Handle  *********************************
;
              (vlax-release-object WrkDwg) ; Release WrkDWG Object Pointer to complete close.
          (gc)
          (prompt "\nDrawing Complete.")(print)
       ); progn If
       (progn
          (write-line (strcat file " " (RawDate) ": Unable to open drawing.") BatchLog)
          (princ "\nInvalid Shortcut Path")
       ); Progn Else
        ); If FileString

(5) Focus shifts to newly opened drawing.
    (5a) Drawing goes through normal loading process.
    (5b) Execution reaches S::STARTUP

(6) S::STARTUP
    (6a) Set my default preferrences (Always runs, not part of Batch)
    (6b) Retrieve LispRunList using vl-bb-ref (may contain more then one LISP)
    (6c) Conditional check for which routines to run.
        (6c.1) Load and run selected preset LISP routines (Clean, Setlayers, Plot, etc.)
        (6c.2) Load and run any LISP choosen by the user from file dialogue. (Publish function run here)
    (6d) See code below for LISP loading and execution.
   
Code: [Select]
(defun-q BatchHandler ( / LispRunList   RunLisp   NewLaData   MainFunc)
(vl-load-com)
(setvar "REGENMODE" 1)
(setenv "CmdHistLines" "2048")
(setvar "LOGFILEMODE" 1)
;
; ********************************  If Drawing1 Load SDMU  **********************************
;
(if (= (getvar "dwgname") "Drawing1.dwg")
    (progn
       (load "g:\\SHS\\ENTERPRISES\\Housing Systems Initiatives\\Space_CAD\\cad\\cad drawings\\PHASE 3 CAD Planning\\HPPS Code\\Shawn's Routines\\Batch Routines Revised\\ODv4-7.lsp")
       (print)(prompt "Stanford Drawing Maintanence Utility Loaded: ")(print)
;       (command "._Point" '(0 0 0))
;       (command "._Erase" '(0 0 0) "")
;       (vl-bb-set 'Debug "Yes")
    ); progn
); if
;
; *********************************  Retrieve Run List  *************************************
;
(setq LispRunList (vl-bb-ref 'BPRun))
(DandD (reverse '("LispRunList")) "All Selected BP Lisps" "Yes")
;
; *****************************  Execute Run List If /= nil *********************************
;
(if (/= LispRunList nil)
  (command "._Model")
)
(foreach Routine LispRunList
  (setq RunLisp (car Routine))
  (cond ((= RunLisp "9Plot")
           
            (load "g:\\SHS\\ENTERPRISES\\Housing Systems Initiatives\\Space_CAD\\cad\\cad drawings\\PHASE 3 CAD Planning\\HPPS Code\\Shawn's Routines\\Batch Routines Revised\\Plot All.lsp")
            (print)(princ Routine)(Print)
;            (load "g:\\SHS\\ENTERPRISES\\Housing Systems Initiatives\\Space_CAD\\cad\\cad drawings\\PHASE 3 CAD Planning\\HPPS Code\\Shawn's Routines\\Batch Routines Revised\\Plot All Drawings.lsp")
            (PlotBatch (nth 1 Routine)(nth 2 Routine))
;            (PlotBatch (nth 1 (car (vl-bb-ref 'BPRun)))(nth 2 (car (vl-bb-ref 'BPRun))))
            (wait)(Print)(Prompt "Bible Sheet Printed. ")(print)
        )
        ((= RunLisp "8BlockCounter")
            (load "g:\\SHS\\ENTERPRISES\\Housing Systems Initiatives\\Space_CAD\\cad\\cad drawings\\PHASE 3 CAD Planning\\HPPS Code\\Shawn's Routines\\Block Counter.lsp")
            (C:CntBlk)
            (wait)(Print)(Prompt "BlockList: Complete")(print)
        )
        ((= RunLisp "7LayerList")
            (load "g:\\SHS\\ENTERPRISES\\Housing Systems Initiatives\\Space_CAD\\cad\\cad drawings\\PHASE 3 CAD Planning\\HPPS Code\\Shawn's Routines\\LayerList1-4.lsp")
            (setq NewLaData (C:lltest))
            (wait)
            (vl-bb-set 'MasterLayerData NewLaData)
            (Print)(Prompt "LayerList: Complete")(print)
        )
        ((= RunLisp "6SetLayer")
            (command "_.Layer" "Off" "*" "Thaw" "*" "Freeze" "Defpoints,A-SH-FLOR-FIN" "")
            (SetLayers (cadr Routine) 'LayerOn "True")
            (wait)(Print)(Prompt "Layers Set")(print)
;            (alert "waiting")
        )
        ((= RunLisp "5Select")
            (load (cdr Routine))
            (print)
            (prompt (setq MainFunc (nth 0 (reverse (princ (GetSubFuncs (cdr Routine)))))))
;            (print)(alert MainFunc)(Print)
            (eval (list (read MainFunc)))
            (wait)
            (Print)(Prompt "Selected LISP Run Complete. ")(print)
        )
        ((= RunLisp "4MspaceLayout")
            (load "g:\\SHS\\ENTERPRISES\\Housing Systems Initiatives\\Space_CAD\\cad\\cad drawings\\PHASE 3 CAD Planning\\HPPS Code\\Shawn's Routines\\Batch Routines Revised\\MspaceStdLayout-v31d.lsp")
            (C:MspaceStdLayout)
            (wait)
            (Print)(Prompt "TitleBlock Insertion. ")(print)
        )
        ((= RunLisp "3Purge")
            (Command "._Purge" "Blocks" "" "No")
            (Wait)
            (Command "._Purge" "Layers" "" "No")
            (Wait)
        )
        ((= RunLisp "2LayerScrub")
            (load "g:\\SHS\\ENTERPRISES\\Housing Systems Initiatives\\Space_CAD\\cad\\cad drawings\\PHASE 3 CAD Planning\\HPPS Code\\Shawn's Routines\\Layerscrubv1-1.lsp")
            (C:lscrub)
            (Print)(Prompt "Layer Scrub: Complete")(print)
        )
        ((= RunLisp "1BOtoL0")
            (load "g:\\SHS\\ENTERPRISES\\Housing Systems Initiatives\\Space_CAD\\cad\\cad drawings\\PHASE 3 CAD Planning\\HPPS Code\\Shawn's Routines\\botol0v2-2.lsp")
            (C:botol0)
            (Print)(Prompt "Block Entities to Zero Layer: Complete")(print)
         )
;        ((= RunLisp "Other Routines Here"))
  ); Cond
(wait)
); foreach
;(acad-pop-dbmod)
;
;
); BatchHandler

(7) User selected LISP publishes drawing to server using Tririga publish function.
    (7a) Prep drawing for publish (queries, titleblock changes, layer settings, etc.)
    (7b) Publish to server. (Tririga publish utility in ARX file, so no change or dissasembly possible.)
   
Code: [Select]

(defun Publish03-20 ()
(C:SpaceClassUpdate)
(Print)(princ "Space Class Updates Complete: ")
(TitleBlock)
(Print)(princ "Titleblock Updated: ")
(Apreuploaddata)
(Print)(princ "Square Footage for Upload Complete: ")
;
;
;
(C:lastd)
(Print)(princ "Layer Standards Enforced: ")
;
;  Window resize Experiments
;
;(setq Doc_ID (vla-get-ActiveDocument (vlax-get-Acad-Object)))
;(ACADWindowSize 1245 846 );1660 1059 +34 for Top and Bottom headers
;(ACADWindowSize 1038 705 );1660 1059 +34 for Top and Bottom headers
;
;
(if (dictsearch (namedobjdict) "Tririga")
   (progn
      (C:AllShareHatch)
      (Print)(princ "Tririga Hatches Updated: ")
      (C:CiPublish)
      (Print)(princ "Drawing Published: ")
   );progn
   (Princ "Drawing not Linked to Tririga")
;   (write-line (Princ "Drawing not Linked to Tririga") (vl-bb-ref 'BatchLog))
)
;
;
;
(Command "._Qsave")
;(Print)(princ "Drawing Saved: ")
); defun



(8) S::STARTUP finishes and control is returned to Drawing1. 

(9) Any operations for after drawing open are executed
    (9a) See Other Operations on Work Drawings in Example code for DrawingActivator.
   
(10) Work drawing is saved if flag is set.

(11) Work drawing is released.

(12) Next drawing is Opened.
    (12a) DrawingActivator will repeat cycle until all files in directory are done.
    (12b) SubDirectory Handler will repeat cycle as specified by sub-directory processing mode.


If you get any ideas let me know, but in the meantime, thanks again for all your help.  Even without success on my resizing the window I have learned so much my head hurts.  Also one other question, which ARX contains the zoom command?  Maybe there is something I can learn from that.

Have a good one.
Shawn

pkohut

  • Guest
Re: Updating model space display extents
« Reply #37 on: March 25, 2010, 10:37:56 PM »
Hey Shawn, thanks for clarifying the process.  Unless your able to write some key parts of this in ARX I'm leaning toward creating a script on the fly that is run when a drawing is opened. Even in ARX there are times that a .scr file is useful. For instance, I have a set of routines that opens a select batch of drawings, zooms to a table of revision histories, freezes and turns all layers off except for the revision histories, and validates the RH entries in a SQL database, saves the drawings. The initial goal was to have a single ARX program handle everything, but there was a blocking feature that could not be done in a secondary drawing from the main ARX routine. This was resolved by having the main ARX program do the equivalent of "acad somedrawing /b myscript.scp". myscript.scp is in charge of bootstrapping an addition ARX routine to process the drawing.  What I described was a wall I hit with ARX, under lisp/vlisp you'll hit some limitation sooner.

vl-bb-set/ref look like cool features. Don't know anything about them.

Does SDMU have to be a lisp program?  How about making it a batch process, or better yet Power Shell (and scripts to bootstrap your code).

I think you misunderstood persisting data, not talking about having Autocad do it, your routines would need to do it. Maybe it is a lot of effort, sometimes it's required.


shawndoe

  • Guest
Re: Updating model space display extents
« Reply #38 on: March 26, 2010, 03:20:32 PM »
Hi,

I do plan to rewrite this in ARX eventually.  The LISP code could be better, I wrote this 5 years ago, and my skills have improved quite a bit since then.  I haven't done it up to know, because of time restraints and SDMUs reliability.  Routines run using SDMU may fail on occasion, but SDMU itself is a very reliable program. 

vl-bb-set/ref is awesome, it allows for transfer of all variable types between namespaces.  I use it in error handling, Batch Runs and anything else where I need data to be accessible outside the drawing.  It also lets me collect data and close the drawing, which is helpful in my audit routines.

I think I might spend this weekend writing an ARX to take over the drawing opening process, but I think the entire program would have to be written in ARX for scripting to work. 

I wonder, can this info be written to the drawing file before the drawing is opened.  AutoCAD seems to remember the size of a window at open.  Maybe the trick is not to open the drawing and set the window, but set the window and open the drawing...  Hummm.

I'm going to see if that works.  Let me know if you think I'm wasting my time.

Have a good one.
Shawn

shawndoe

  • Guest
Re: Updating model space display extents
« Reply #39 on: March 26, 2010, 04:54:13 PM »
Just a note,

A DWG remembers the window settings when you save a drawing, but a DXF does not.

Have a good one.
Shawn