LISP: Autocad crashes on lisp

LISP: Autocad crashes on lisp

Anonymous
Not applicable
1,162 Views
3 Replies
Message 1 of 4

LISP: Autocad crashes on lisp

Anonymous
Not applicable

Hi,

 

I want to freeze a layer (language layer) for a complete folder of DWG's.
I've found a working LISP to do what i want so no problems there.
NOW:

I've come up with the idea to let the user choose in which language they want to work by asking this through a Dialog box.
When I start the command "Set_language" the box with the language selection pops up. So far so good.
After I click a language (just NL for now), I get the folder selection window which is also very good.
But when I select the folder with the DWG's en press OK, autocad hangs itself followed by a fatal error.
I don't seem to find the problem in this but i think it has something to do with the fact that the Language selection window stays open.

Also, I can't seem to put my "DONE" signal  (prompt or alert i haven't decided yet) at the end of the routine.It pops up right before the routine starts with processing the dwg's in the chosen folder.

 

Does anyone know how i can fix this? I tried a few things but my knowledge of lisp is very limited and i'm out of ideas.

Thanks in Advance,

LISP code below:

------------------------------------------------------
;;;; ROUTINE TO CHOOSE WORKFOLDER
-------------------------------------------------------
(defun BrowseForFolder ( Message / sh folder parentfolder folderobject result)
 (vl-load-com)
  (setq sh
   (vla-getInterfaceObject
     (vlax-get-acad-object)
       "Shell.Application"
     )
   )


   (setq folder
      (vlax-invoke-method
          sh
          'BrowseForFolder
          0
          Message
          0
       )
   )
   (vlax-release-object sh)


    (if folder
      (progn
         (setq parentfolder
           (vlax-get-property folder 'ParentFolder)
         )
        (setq FolderObject
           (vlax-invoke-method
              ParentFolder
               'ParseName
              (vlax-get-property Folder 'Title)
           )
        )
       (setq result
          (vlax-get-property FolderObject 'Path)
       )
       (mapcar 'vlax-release-object
         (list folder parentfolder folderobject)
       )
     (if (/= (substr result (strlen result)) "\\")
       (setq result (strcat result "\\"))
       result
     )
   )
 )
); defun


--------------------------------------------------
;;;; DEFINE FUNCTION AND CALL DIALOGBOX;;;;;;;;;;
-------------------------------------------------
(defun c:SET_LANGUAGE (/ dcl_id)   ;define the function
 
  (setq dcl_id (load_dialog "DB01.dcl"))  ;load the DCL file
 
  (if (not (new_dialog "DB01" dcl_id))   ;load the dialogue box
    (exit)      ;if not loaded exit
 
  )
 
  (action_tile "cancel" "(done_dialog)")
        ;if Cancel button selected, close
              ;the dialogue.
 
  (action_tile "NL" "(done_dialog) (set_NL)")
       ;if NL button is selected
  (action_tile "FR" "(done_dialog)")            ;if FR button is selected
 
  (start_dialog)    ;start the dialogue
 
  (unload_dialog dcl_id)   ;unload the dialogue
 
  (princ)
 
)      ;defun
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
(princ)      ;load clean
-------------------------------------------------
;;;;:DEFINE ACTIONS;;;;;;;;;;;;;;;;;;;;
------------------------------------------------

(defun set_NL ()          ; FUNCTION SET LAYER TO NL
           (if (setq DirPath (BrowseForFolder "Select folder of drawings to process: "))  ; ASK WHICH FOLDER
       (progn
    (setq DwgList (vl-directory-files DirPath "*.dwg" 1))    ;LOOK FOR DWG'S
      (setq f (vl-directory-files DirPath "*.dwg" 1))
     (length f)
      (setq ScrFile (vl-filename-mktemp "Batch_Dwg.scr"))    ; CREATE TEMPORARY SCRIPT
      (setq Ofil (open ScrFile "W"))
      (write-line "SDI 0" Ofil)       ; Force Multi-Document mode
      (write-line (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 0)") Ofil)  ;DISABLE USERWINDOWS
       (foreach Dwg DwgList       
         (setq FullPath (strcat DirPath Dwg))
         (write-line (strcat "_.open " (chr 34) FullPath (chr 34)) Ofil)        ;OPEN DWG
         (write-line (strcat "(command "(chr 34)"_layer"(chr 34)(chr 34)"S"(chr 34)(chr 34)"DRAW"(chr 34)(chr 34)(chr 34)")") Ofil) ;SET LAYER TO DRAW
         (write-line (strcat "(command "(chr 34)"_layer"(chr 34)(chr 34)"F"(chr 34)(chr 34)"INFO_FR"(chr 34)(chr 34)(chr 34)")") Ofil) ; HIDE LAYER "INFO_FR"
         (write-line (strcat "(command "(chr 34)"_layer"(chr 34)(chr 34)"T"(chr 34)(chr 34)"INFO_NL"(chr 34)(chr 34)(chr 34)")") Ofil) ; SHOW LAYER "INFO_NL"
         (write-line ".qsave" Ofil)             ; SAVE
         (write-line "_.close" Ofil)             ; CLOSE
      ); foreach
      ); progn
          (prompt "Done Processing Schemes!")     ;PROMPT WHEN DONE
   ); if
    )

 

 

 

DCL FILE:

DB01 : dialog {
 
 key = "main";
 
 : column {
 
 : text {
 key = "Choose Your Language";
        }
 }
    : row {
 
 : spacer { width = 1; }
 
 : button {
 label = "NL";
 key = "NL";
 width = 12;
 fixed_width = true;
 mnemonic = "Y";
 is_default = true;
 }
 
 : button {
 label = "FR";
 key = "FR";
 width = 12;
 fixed_width = true;
 mnemonic = "N";
   }
 
 : button {
 label = "Cancel";
 key = "cancel";
 width = 12;
 fixed_width = true;
 mnemonic = "C";
 is_cancel = true;
   }
 
 : spacer { width = 1;}
 
 }
 
     }

0 Likes
1,163 Views
3 Replies
Replies (3)
Message 2 of 4

wispoxy
Advisor
Advisor

Is the file you're working with created with AutoCAD? The Error shows an unknown file being in the wrong place.

 

It's kinda weird, so let me give you a link with a guide all about it down to the very code that created it.

 

AutoLisp_Developers_Guide.pdf

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

Here is a great AutoCAD extension that you can use to accomplish this.

 

https://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3Abatch-in-...

0 Likes
Message 4 of 4

Anonymous
Not applicable

I've found a sluiten for my problem. Thanks for thema developpers Guide and the batch tool. I"ll take a look at it! 

0 Likes