Hi,
I asked this question also on the Autocadforum but I feel this is a better place for it.
I've got a Lisp-problem.
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 (NL/FR) pops up. So far so good.
After I click a language (I just programmed 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:
Code:
------------------------------------------------------
;;;; 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 cET_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
-------------------------------------------------
;;;;EFINE 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:
Code:
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;}
}
}