Code Red > AutoLISP (Vanilla / Visual)

New drawing without command

(1/2) > >>

T.Willey:
I have a bunch of batch programs, and then seem to crash at the end, and it seems the reason is because of the new command that is issued.  I have tried to use the Method New for the active document, but I can't seem to get it to work.

--- Quote ---Command: (VLAX-INVOKE ACTDOC 'NEW
"C:/ACADSUPP2004/Template/3M-TITLEBLOCK-B.dwt")

***  AAAaaarrrrgghhhh  ***    AutoLISP encountered this error:  AutoCAD:
AutoCAD is unable to service automation request

Command: (VLAX-INVOKE ACTDOC 'NEW
"C:/ACADSUPP2004/Template/3M-TITLEBLOCK-B.dwg")

***  AAAaaarrrrgghhhh  ***    AutoLISP encountered this error:  AutoCAD:
AutoCAD is unable to service automation request

--- End quote ---

Any help is appreciated.  Thanks in advance.

CADmium:
try this

--- Code: ---;;; call     : (DT:DWT-NEW  "C:\\Vorlage.dwt")       
(defun DT:DWT-NEW1 (DWTNAME / DWT)
  (and(=(type DWTNAME) 'STR)
      (not(vl-catch-all-error-p
            (setq DWT(vl-catch-all-apply
                       'vla-add
                       (list
                         (vla-get-documents
                           (vlax-get-acad-object)
                         )
                         DWTNAME
                       )
                     )
           )
         )   
      )
      (not(vl-catch-all-error-p
            (vl-catch-all-apply   
              'vla-activate
              (list DWT)
            )
          )
      )
  )
)
;;; - ------------------------------------------------------------------------------ - ;
;;; call: (DT:DWT-NEW2 "D:\\mdt2004\\einstellungen\\vorlagen\\ke-tka.dwt")             
(defun DT:DWT-NEW2(DWTNAME)
  (and(=(type DWTNAME) 'STR)
      (not(vl-catch-all-error-p
            (vl-catch-all-apply
              'vla-sendcommand
                 (list
                   (vla-get-activedocument
                     (vlax-get-acad-object)
                   )
                   (strcat
                     "vbastmt "   
                     (strcat"AcadApplication.Documents.Add" (chr 34)DWTNAME(chr 34))
                     (chr 13)
                   )
                 ) 
            )
          )
     )     
  )
)

--- End code ---

and for a qnew ..

--- Code: ---(defun DT:DWT-GET-STANDARD ( / NAME)
  (if (and(setq NAME (vl-registry-read
                       (strcat "HKEY_CURRENT_USER\\"
                               (vlax-product-key)
                               "\\PROFILES\\"
                               (vla-get-ActiveProfile
                                 (vla-get-PROFILES
                                   (vla-get-preferences
                                     (vlax-get-acad-object)
                                   )
                                 )
                               )
                               "\\GENERAL"
                       )
                       "QnewTemplate"
                    )
          )
          (setq NAME (findfile NAME))
      )
    NAME   
  ) 
)

(defun c:my-qnew(/ dwtname)
  (if (setq dwtname ( DT:DWT-GET-STANDARD))
    (DT:DWT-NEW2 DWTNAME)
  )
)

--- End code ---

T.Willey:
Thanks.  I had to change it a little as I would need this when I'm in sdi mode.  Here is your code with my slight modification.

--- Code: ---(defun DT:DWT-NEW2(DWTNAME)
  (and(=(type DWTNAME) 'STR)
      (not(vl-catch-all-error-p
            (vl-catch-all-apply
              'vla-sendcommand
                 (list
                   (vla-get-activedocument
                     (vlax-get-acad-object)
                   )
                   (strcat
                     "vbastmt "   
                     (strcat"AcadApplication.ActiveDocument.New" (chr 34)DWTNAME(chr 34)) ; TMW
                     (chr 13)
                   )
                 )
            )
          )
     )     
  )
)

--- End code ---

T.Willey:
This doesn't seem to be working.  It looks like it wants to have that as the last statement in the lisp routine, and I need it to be like the third or fourth from the last.  I will continue to look for a way.

Thanks.

Jeff_M:

--- Quote from: T.Willey on April 21, 2006, 06:33:46 PM ---..... and I need it to be like the third or fourth from the last. 

--- End quote ---
Can you expand on this, Tim? Such as: what else needs to run?

You see, the way I see this working is you open/create a new drawing and as soon as the first one closes or the new one becomes the Active drawing then the lisp will stop executing. Lisp can only operate within the scope of the drawing it was initiated in.

Navigation

[0] Message Index

[#] Next page

Go to full version