Is there a way to programatically set a visual style before a drawing actually opens?
We have some huge models and people seem to forget to change their visual styles back to 2D wireframe before saving and exiting drawings. Some models will crash on some workstations when trying to open in a rendered mode.
I found a lisp with a function that looked to set view port visual styles. But it does not seem to be supported anymore. --> (vla-put-VisualStyle vport 1)
Any suggestions?
Thanks
It seems to me that all you would need to do is add a line of code to an acaddoc.lsp:
(command "vscurrent" 2)
VSCURRENT sets the visual style in the current viewport. The "2" option corresponds to 2-D wireframe.
Acaddoc.lsp runs just prior to regenerating the opening DWG.
Correction: I was too quick to reply. It looks like the command runs after the drawing has regenerated (with the saved visual style), so I'm afraid it will not work for you. I apologize. I will investigate further.
By running a "command" in the acaddoc lisp, Autocad is still wanting to open the drawing in a rendered mode prior to changing the visual style. It seems this function I desire needs to be changed in the drawing database just prior to actually opening the drawing.
Below is my text window. I set the VSCURRENT command as you suggested in my acaddoc lisp. Doing so changed the viusal style just after the xref's were loaded.
Resolve Xref "CIVILBASE_60FT_RACK_MODULE_FND_LCCE": O:\LC Clean Energy\130103\DWGS\Civ_Struc\Civ_Strucbase\CIVILBASE_60FT_RACK_MODULE_FND_LCCE.d wg "CIVILBASE_60FT_RACK_MODULE_FND_LCCE" loaded.
[2dwireframe/Wireframe/Hidden/Realistic/Conceptual/Shaded/shaded with Edges/shades of Gray/SKetchy/X-ray/Other] <Realistic>: 2 Regenerating model.
Command:
Autodesk DWG. This file is a TrustedDWG last saved by an Autodesk application or Autodesk licensed application.
Command:
"It seems this function I desire needs to be changed in the drawing database just prior to actually opening the drawing"
Yes. A bit of a "catch-22". (How do you know which DWG to run the change on before a user opens it?)
I don't think there's any way to suppress that initial regen.
Just "noodling" here: Maybe a more feasible approach would be to do something "special" when files are closed. For example, assuming it's the regen of the model space that's causing the problem, produce a custom "close" command that switches to a layout tab before closing.
@dmfrazier wrote:
Just "noodling" here: Maybe a more feasible approach would be to do something "special" when files are closed. For example, assuming it's the regen of the model space that's causing the problem, produce a custom "close" command that switches to a layout tab before closing.
Or simpler still, simply hook the CommandWillStart event and make the desired change(s) to each Layout programmatically, so that these changes are saved with the Drawing at CLOSE, and the initial regen issue would be mitigated altogether.
If one absolutely needed to perform this task at Drawing open, then you might consider stepping up to the .NET API, and manipulate Viewport.VisualStyleId Property... Having not tried this before, one may still need to account for ApplicationContext, etc. if it is possible to perform these changes prior to initial regen.
HTH
"How we think determines what we do, and what we do determines what we get."
Opening every drawing in a 2D Wireframe mode would not hurt anything in our drawing world.
I thought about trying some settings upon closing, but I do not know how I would do this without redefining the qsave command or even save command. Then there is still the "exit" command, where as someone would X out of a drawing.
How do I cover all the bases of closing drawings and adding a custom setting?
And just to note, this is not a huge problem with layouts and viewports. It is more of a problem dealing with large working models being designed in model space.
"...I do not know how I would do this without redefining the qsave command or even save command"
I agree that such an approach could work, but I think redefining just the "close" (and maybe "quit") command would be sufficient (assuming it's possible). Changing the visual style during every save during an editing session would probably not be very popular.
"Then there is still the "exit" command, where someone would X out of a drawing..."
This actually runs the "close" command (_close), so I think redefining it would cover you there as well.
"How do I cover all the bases of closing drawings and adding a custom setting?"
You probably will never "cover all the bases", but catching the majority of them may still be worth the effort.
And don't neglect training. In some cases there is no substitute.
@dmfrazier wrote:
....
"Then there is still the "exit" command, where someone would X out of a drawing..."
This actually runs the "close" command (_close), so I think redefining it would cover you there as well.
....
Exit is the same as Quit [it's defined in acad.pgp as an alias that invokes Quit], not the same as Close. Exit/Quit take you out of AutoCAD; Close leaves you in it. It would be simple enough to redefine Close to change the visual style before closing, since it operates only on the current drawing. But it sounds like a real challenge [if it's possible] to redefine Quit or CloseAll to do so, since they can operate on multiple drawings. If you have multiple drawings open and have made changes in any of them, in any of those commands you will be asked, for each drawing, whether to save the changes. I expect it may not be possible for an AutoLisp routine to "catch" each drawing in the process and change its visual style, since I don't think they can work in any drawing other than the one in which they are invoked. But maybe it could be done with a Script [I haven't used them much, and never involving multiple drawings]. And if so, maybe Quit and CloseAll can be redefined to call Scripts, but I'm not sure whether a Script can work with an indeterminate number of open drawings. There are many threads here that suggest using ScriptPro to work on multiple files, but I haven't used it, and don't even know whether that can be invoked from inside a drawing, as would be necessary for it to be called from within a redefined Quit or CloseAll command. I expect someone out there can at least answer that much.
Valid (and appreciated) as your comments may be, just to clarify: when I wrote "This actually runs the "close" command (_close)..." I was directly addressing the OP's comment: "where someone would X out of a drawing...", and I took this to mean "clicking the X in the upper-right of the document window (not the application window). When I do this, it executes _close (not closeall), so I assumed it would do the same for the OP.
@Kent1Cooper wrote:
I expect it may not be possible for an AutoLisp routine to "catch" each drawing in the process and change its visual style, since I don't think they can work in any drawing other than the one in which they are invoked.
Correct.
However, as suggested above, a Command reactor can be registered via AcadDoc.lsp, which will handle each Document accordingly... Just filter for CLOSE in lieu of SAVE as desired.
What I've done also, is to make the appropriate change(s) at SAVE (read QSAVE), and then hook the CommandCancelled, CommandEnded, and CommandFailed events to restore... This yields the desired result of the saved file being in the target style, yet the active session seemingly unchanged. Paired with pop/push DBMOD, CLOSE will not require a supplementary save, as no changes will be shown (from this specific task that is).
I'd have to do some testing for CLOSEALL, as I do not use this Command personally... The iDwgTab 'tabbed' interface I use includes several functions that I use instead:
"How we think determines what we do, and what we do determines what we get."
@dmfrazier wrote:Valid (and appreciated) as your comments may be, just to clarify: when I wrote "This actually runs the "close" command (_close)..." I was directly addressing the OP's comment: "where someone would X out of a drawing...", and I took this to mean "clicking the X in the upper-right of the document window (not the application window). When I do this, it executes _close (not closeall), so I assumed it would do the same for the OP.
This reminds me of a guy I helped recently who had users that would repeatedly hit X (QUIT) when in Block Editor, which has negative affect on production to put it simply... To help, I developed a .NET plug-in for them, that while in Block Editor would 'Veto' any call to QUIT, and then invoke BCLOSE Command instead (only while in Block Editor, of course).
"How we think determines what we do, and what we do determines what we get."