newer 发表于 2021-1-7 17:51:52

Acad.lsp/acaddoc.lsp fail to load when using command new/open

问题:
Why don't acad.lsp and acaddoc.lsp not load in AutoCAD 2000 when a new document
is started using (command "NEW" ..) and (command "OPEN" ...)?

This is a known problem in AutoCAD 2000 and occurs when these conditions exist:

ACADLSPASDOC is set to 1
LISPINIT is set to 1
SDI is set to 1

To replicate how AutoCAD R14 behaves when SDI is set to 1 (the Single Document
Interface is set to be active) in AutoCAD 2000, the following variables need to
be set as shown:

ACADLSPASDOC is set to 0
DBMOD is set to a value greater than 0

If the present drawing has never been modified (for example, when DBMOD is set
to 0), AutoCAD 2000 will not load and initialize user LSP files. The solution in
this case is to temporarily set LISPINIT to 0. That leaves the current
ACADDOC.LSP and MNL code to load in a New or Opened drawing.

Because ACADLSPASDOC is set to 0, you'll need use only the Acaddoc.lsp for your
autoloaded user files, and not the acad.lsp file, in order to implement this


解答:
The following code shows a combination of the following VBA code (saved into
file "MyNewOpen.dvb"):


Public Sub My_Ac_New()

Dim objacad As AcadApplication
Set objacad = ThisDrawing.Application
Dim theSDIVar As Integer
theSDIVar = objacad.ActiveDocument.GetVariable("SDI")

If theSDIVar = 0 Then
' If SDI = 0
objacad.Documents.Add ("acad")
Else
' If SDI = 1
objacad.ActiveDocument.New ("acad")
End If

End Sub

Public Sub My_Ac_Open()

Dim objacad As AcadApplication
Set objacad = ThisDrawing.Application
Dim theSDIVar As Integer
theSDIVar = objacad.ActiveDocument.GetVariable("SDI")
Dim dwgNameVar As String
dwgNameVar = objacad.ActiveDocument.GetVariable("USERS1")

If theSDIVar = 0 Then
' If SDI = 0
objacad.Documents.Open dwgNameVar, False
Else
' If SDI = 1
objacad.ActiveDocument.Open dwgNameVar
End If

End Sub


and the following lisp code:


(defun RunNewOpen ()
(vl-load-com)
;;; Set LISPINIT OFF when in an Unmodified New drawing and LISPINIT = 1
(if (= (getvar "DBMOD") 0) (setvar "LISPINIT" 0) (setvar "LISPINIT" 1) )
(initget 1 "New Open")
(setq option (getkword "\nStart a New Drawing or Open an Existing one <N/O>: ?
"))
(if (equal option "New")
      (NewOpenWorkarround option)
      (progn
             (setq aDWGfile (getfiled "Open a Drawing File" "" "DWG" 0))
             (if aDWGfile
                  (progn
                        (setvar "USERS1" aDWGfile)
                        (NewOpenWorkarround option)
                  )
             )
      )
)
)

(defun NewOpenWorkarround (tog)
(if (findfile "MyNewOpen.dvb")
      (progn
            (vl-vbaload "MyNewOpen.dvb")
            (if (equal tog "New")
               (vl-vbarun "My_Ac_New")
               (if (equal tog "Open")
                        (vl-vbarun "My_Ac_Open")
                        (princ "\nNeither NEW or OPEN was specified.")
               )
            )
      )
)
(princ)
)


Whenever the function (RunNewOpen) is run from your current document, the user
acaddoc.LSP amd MNL files should either load into the document as it previously
did, or still be available because LISPINT was set temporarily to 0.

For another approach to this problem using script files, see DevNote #45180.

页: [1]
查看完整版本: Acad.lsp/acaddoc.lsp fail to load when using command new/open