TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: T.Willey on April 20, 2006, 01:50:53 PM

Title: New drawing without command
Post by: T.Willey on April 20, 2006, 01:50:53 PM
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

Any help is appreciated.  Thanks in advance.
Title: Re: New drawing without command
Post by: CADmium on April 20, 2006, 02:28:41 PM
try this
Code: [Select]
;;; 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)
                   )
                 ) 
            )
          )
     )     
  )
)

and for a qnew ..
Code: [Select]
(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)
  )
)

Title: Re: New drawing without command
Post by: T.Willey on April 20, 2006, 02:45:58 PM
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: [Select]
(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)
                   )
                 )
            )
          )
     )     
  )
)
Title: Re: New drawing without command
Post by: T.Willey on April 21, 2006, 06:33:46 PM
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.
Title: Re: New drawing without command
Post by: Jeff_M on April 21, 2006, 06:58:31 PM
..... and I need it to be like the third or fourth from the last. 
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.
Title: Re: New drawing without command
Post by: T.Willey on April 21, 2006, 07:05:43 PM
..... and I need it to be like the third or fourth from the last. 
Can you expand on this, Tim? Such as: what else needs to run?
Sure.

This is my batch plot routine.  I change it to SDI mode so that I can run a lisp to plot instead of a script or a VBA program.  It will plot and all, but when it was trying to execute the new command after it finishes plotting all the drawings, it would crash it.  So I tried to code a way to open a new drawing, but that doesn't seem to something that the ActiveX controls support for lisp.  The vbastmt waits until the end of the routine finishes, and then runs the statement, which causes an error because now it's in MDI mode.

Psuedo code:
Change to SDI mode
Select the drawings, and plot options
Plot them all
Open a new drawing
Change all variables back, mainly back to MDI mode if Acad was in it before the plot routine.

I hope that is clear.