Intercepting Commands or Starting New Dwg with Template

Intercepting Commands or Starting New Dwg with Template

Anonymous
Not applicable
281 Views
2 Replies
Message 1 of 3

Intercepting Commands or Starting New Dwg with Template

Anonymous
Not applicable
I added the /t "acad.dwt" parameter to the icon target field, but all the
NEW drawings do not use the template file. I need to start NEW dwgs with
the acad.dwt template. If this can be done easily, please let me know.

Otherwise, I'd like to know how to use reactors in VBA which would let me
open a new drawing with a specific template. I have the BeginCommand event
set up to display a message if the command is "NEW", so I have the structure
correct. My problem is when I use the Documents.Add method, the document is
added with the template file, then the NEW command continues to run. There
is no Cancel variable to set which can cancel the command from within the
BeginCommand routine. I also tried redefing CommandName within the routine,
but that didn't work either. How can I cancel the command in progress from
within the reactor routine?

Public WithEvents MyEvents As AcadApplication

Private Sub MyEvents_BeginCommand(ByVal CommandName As String)
' intercepts commands issued from Autocad to do custom functions
MsgBox CommandName
Select Case CommandName
Case "NEW"
Set Doc = Application.Documents.Add("acad.dwt")
CommandName = "help"
End Select
End Sub

Hey, I'm open to easier ways, too!
Thanks,
Keith
0 Likes
282 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Hi Keith,
You have a couple of options:
1) Remove the "new" toolbar button and alter you mns file to eliminate the
"ctrl+n" and the "new" command from the "file" pulldown (pop1 I believe). Then
replace with 2 new toolbar buttons, and a couple of new pulldown options:

Sub NewMetric()
Dim mode As Integer
mode = ThisDrawing.GetVariable("sdi")
If mode = 1 Then
ThisDrawing.New "acadiso.dwt"
Else
ThisDrawing.Application.Documents.Add "acadiso.dwt"
End If
End Sub

Sub NewStandard()
Dim mode As Integer
mode = ThisDrawing.GetVariable("sdi")
If mode = 1 Then
ThisDrawing.New "acad.dwt"
Else
ThisDrawing.Application.Documents.Add "acad.dwt"
End If
End Sub

2) Don't alter the mns file, just undefine the "new" command in you acad2000.lsp
file (this takes care of the the user typing "new" at the command prompt as
well) and replace it with a lisp function that either starts a form giving the
user option or just starts a new file from the acad.dwt template.

-Josh

Keith wrote:

> I added the /t "acad.dwt" parameter to the icon target field, but all the
> NEW drawings do not use the template file. I need to start NEW dwgs with
> the acad.dwt template. If this can be done easily, please let me know.
>
> Otherwise, I'd like to know how to use reactors in VBA which would let me
> open a new drawing with a specific template. I have the BeginCommand event
> set up to display a message if the command is "NEW", so I have the structure
> correct. My problem is when I use the Documents.Add method, the document is
> added with the template file, then the NEW command continues to run. There
> is no Cancel variable to set which can cancel the command from within the
> BeginCommand routine. I also tried redefing CommandName within the routine,
> but that didn't work either. How can I cancel the command in progress from
> within the reactor routine?
>
> Public WithEvents MyEvents As AcadApplication
>
> Private Sub MyEvents_BeginCommand(ByVal CommandName As String)
> ' intercepts commands issued from Autocad to do custom functions
> MsgBox CommandName
> Select Case CommandName
> Case "NEW"
> Set Doc = Application.Documents.Add("acad.dwt")
> CommandName = "help"
> End Select
> End Sub
>
> Hey, I'm open to easier ways, too!
> Thanks,
> Keith
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thanks, Jim. I chose not to change the menus because I want to keep MDT5
menus right out of the box. The acad.lsp I am already customizing, so I
(command "undefine" "new") in the S::Startup function but I can't figure out
how to get (command ".new" "acad.dwt") to work. I keep getting "unknown
command" error on acad.dwt. I know the two choices in the if statement are
identical, but I'll change them after I get the new file loaded. Could this
error be generated because after the new command is issued, a different Lisp
environment is trying to issue the acad.dwt 'command'? That all I can think
of.

Here's my redefined 'new' function:

(defun c:new ()
(if (= (getvar "sdi") 0)
(progn
;; multiple-document interface
(setq fildia (getvar "filedia"))
(setvar "filedia" 0)
(vl-cmdf ".new" "acad.dwt")
(setvar "filedia" fildia)
)
(progn
;; single-document interface
(setq fildia (getvar "filedia"))
(setvar "filedia" 0)
(vl-cmdf ".new" "acad.dwt")
(setvar "filedia" fildia)
)
)
)

Ultimately, I am trying to accomplish two things: load the acad.dwt template
every time a new file is created AND close the Drawing1.dwg window (when in
multiple-document interface mode) when an existing drawing is opened.

I am trying to force the 'closing' of the drawings named "Drawing1.dwg",
"Drawing2.dwg", etc. when new files are created or when an existing file is
opened. On my system, the open command automatically closes the
Drawing1.dwg but on another computer, the Drawing1.dwg remains in the
Documents collection. How can I get this document to close? Could there be
a variable set differently?

One direction I've been working on is this:

I have the following in a standard module. (By naming the sub AcadStartup,
the sub runs automatically when the acadvba.arx is loaded. The arx file is
loaded automatically by having acadvba.arx in the acad.rx file.)

==== Begin standard module ====
Dim ThisSession As New SessionEvents

Sub AcadStartup()
' bind the current application to my class ThisSession
Set ThisSession.MyEvents = thisdrawing.Application
End Sub
==== End standard module ====

I have the following in a Class module named SessionEvents:

==== Begin class module named SessionEvents ====
Public WithEvents MyEvents As AcadApplication

Private Sub MyEvents_BeginOpen(FileName As String)
MsgBox "opening"
End Sub

Private Sub MyEvents_NewDrawing()
Dim MyDoc As AcadDocument
Set MyDoc =
thisdrawing.Application.Documents.item(thisdrawing.GetVariable("dwgname"))
Dim Doc As AcadDocument
On Error GoTo NewDrawing_Error
For Each Doc In Application.Documents
MsgBox Doc.Name
MyEvents.ActiveDocument = Doc.Application.Documents.item(Doc.Name)
MsgBox MyEvents.ActiveDocument.Name
Next

Exit_Here:
Exit Sub

NewDrawing_Error:
MsgBox Err.Description
Resume Exit_Here
End Sub
==== End class module named SessionEvents ====

Minkwitz Design wrote in message
news:3A427661.A9C6BECE@minkwitz-design.com...
> Hi Keith,
> You have a couple of options:
> 1) Remove the "new" toolbar button and alter you mns file to eliminate the
> "ctrl+n" and the "new" command from the "file" pulldown (pop1 I believe).
Then
> replace with 2 new toolbar buttons, and a couple of new pulldown options:
>
> Sub NewMetric()
> Dim mode As Integer
> mode = ThisDrawing.GetVariable("sdi")
> If mode = 1 Then
> ThisDrawing.New "acadiso.dwt"
> Else
> ThisDrawing.Application.Documents.Add "acadiso.dwt"
> End If
> End Sub
>
> Sub NewStandard()
> Dim mode As Integer
> mode = ThisDrawing.GetVariable("sdi")
> If mode = 1 Then
> ThisDrawing.New "acad.dwt"
> Else
> ThisDrawing.Application.Documents.Add "acad.dwt"
> End If
> End Sub
>
> 2) Don't alter the mns file, just undefine the "new" command in you
acad2000.lsp
> file (this takes care of the the user typing "new" at the command prompt
as
> well) and replace it with a lisp function that either starts a form giving
the
> user option or just starts a new file from the acad.dwt template.
>
> -Josh
>
> Keith wrote:
>
> > I added the /t "acad.dwt" parameter to the icon target field, but all
the
> > NEW drawings do not use the template file. I need to start NEW dwgs
with
> > the acad.dwt template. If this can be done easily, please let me know.
> >
> > Otherwise, I'd like to know how to use reactors in VBA which would let
me
> > open a new drawing with a specific template. I have the BeginCommand
event
> > set up to display a message if the command is "NEW", so I have the
structure
> > correct. My problem is when I use the Documents.Add method, the
document is
> > added with the template file, then the NEW command continues to run.
There
> > is no Cancel variable to set which can cancel the command from within
the
> > BeginCommand routine. I also tried redefing CommandName within the
routine,
> > but that didn't work either. How can I cancel the command in progress
from
> > within the reactor routine?
> >
> > Public WithEvents MyEvents As AcadApplication
> >
> > Private Sub MyEvents_BeginCommand(ByVal CommandName As String)
> > ' intercepts commands issued from Autocad to do custom functions
> > MsgBox CommandName
> > Select Case CommandName
> > Case "NEW"
> > Set Doc = Application.Documents.Add("acad.dwt")
> > CommandName = "help"
> > End Select
> > End Sub
> >
> > Hey, I'm open to easier ways, too!
> > Thanks,
> > Keith
>
0 Likes