Results 1 to 6 of 6

Thread: Lisp: Autocad crashes ( on dialogbox?)

  1. #1
    Member
    Join Date
    2015-05
    Posts
    14
    Login to Give a bone
    0

    Question Lisp: Autocad crashes ( on dialogbox?)

    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;}
     
     }
     
         }
    Last edited by BlackBox; 2015-05-29 at 03:55 PM. Reason: Please use [CODE] Tags

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Lisp: Autocad crashes ( on dialogbox?)

    This code worked for me.

    I would suggest running the function then getting the result before proceeding with the rest of your code.

    P=

    ChooseYourLanguage.jpg

    Code:
    DB01 : dialog {
      label         = "Choose Your Language";
      : spacer {
        height = 1;
      }
      : row {
        : button {
          allow_accept = true;
          is_tab_stop  = true;
          key          = "nl";             
          label        = "&NL";
          mnemonic     = "N";
          width        = 15;
        }
        : button {
          allow_accept = true;
          is_tab_stop  = true;
          key          = "fr";             
          label        = "&FR ";
          mnemonic     = "F";
          width        = 15;
        }
        : button {
          allow_accept = true;
          is_default   = true;
          is_tab_stop  = true;
          key          = "cancel";             
          label        = "&Cancel ";
          mnemonic     = "C";
          width        = 15;
        }
      }
    }
    Code:
    (defun C:DB01 (/  id intStart)
     (if (findfile "DB01.dcl")
      (progn
       (setq id (load_dialog "DB01.dcl"))
       (new_dialog "DB01" id)
       (action_tile "nl"     "(done_dialog 0)")
       (action_tile "fr"     "(done_dialog 1)")
       (action_tile "cancel" "(done_dialog 2)")
       (set_tile "cancel" "1")
       (if (setq intStart (start_dialog))
        (progn
         (unload_dialog id)
         (nth intStart (list "NL" "FR" nil))
        )
       )
      )
      (princ "\nDialog Control Language DB01.dcl not found: ")
     )
    )
    Attached Images Attached Images
    Attached Files Attached Files
    AutomateCAD

  3. #3
    Member
    Join Date
    2015-05
    Posts
    14
    Login to Give a bone
    0

    Default Re: Lisp: Autocad crashes ( on dialogbox?)

    Thanks for your reply Peter.
    I'll try this first thing tomorrow.

  4. #4
    Member
    Join Date
    2015-05
    Posts
    14
    Login to Give a bone
    0

    Default Re: Lisp: Autocad crashes ( on dialogbox?)

    So, it's been a while since I worked on the script.
    But now, back on track.
    And again (due to lack of LISP knowledge) problems.
    2 questions:

    1)
    I've had the idea to automatically fill in some attributes of a certain block.
    When the users starts the routine, they will be given a dialog box with 3 fields:
    Drawn By, Verrified By and Approved By.
    Also the date is filled in automatically.

    I've managed to fill in the Date in the specific attribute so that's OK.
    But for some reason, the value of the fields won't get placed in the assigned attributesfield.
    The code I used was this:

    For the dialog box:
    (set_tile "drawn" "Name")
    (mode_tile "drawn" 2)
    (action_tile "drawn" "(setq DELV $value)")

    For the function:
    (ChangeBlock "CATREVBELA0" "DRAWN0" DELV nil)

    2)
    I've searched for a way to check if the fields are filled.
    This check needs to be done, before the routine goes to the next step (choosing folder).
    When you press one of the language buttons (NL only for testing) and there is something missing in the fields, an alert shows in the box.
    BUT:
    I've got the same problem as in the beginning with the 2 dialogboxes. How can I close the first dialogbox BEFORE the second one opens?
    It seems I don't understand the (done_dialog) function completly, especially when the action of the buttons need to check some things first, before the actual routine can start running.

    Can someone help me with this?
    Thanks in Advance
    Attached Files Attached Files

  5. #5
    Member
    Join Date
    2015-05
    Posts
    14
    Login to Give a bone
    0

    Default Re: Lisp: Autocad crashes ( on dialogbox?)

    After a few tries, I've decided to change the way I get my information from the dialogbox.
    Instead of making 2 buttons I made a selection list.
    Now there are two buttons, OK & Cancel.

    I can do the check for the fields.
    I now I can read the Language selection (tested this bu prompting the result)
    So everything works except:
    I still have the same problem as in my first post.
    The first dialogbox needs to be closed first before the "select folder box" pops up.
    What's the best way to do this?

    Thanks in advance,

    Code:
    DCL coding:
    DB02 : dialog {
      label         = "FILL IN NAMES AND CHOOSE YOUR LANGUAGE";
      : spacer {
        height = 1;
      }
      :boxed_row {
      label = "&Names";
            : edit_box
    	{
    	label = "DRAWN BY:";
    	mnemonic = "N";
    	key = "drawn";
    	alignment = centered;
    	edit_limit = 6;
    	edit_width = 6;
            value = "";
    	}
     
    	: edit_box
    	{
    	label = "VERRIFIED BY:";
    	mnemonic = "A";
    	key = "verified";
    	alignment = centered;
    	edit_limit = 6;
    	edit_width = 6;
    	value = "";
    	}
    
            : edit_box
    	{
    	label = "APROVED BY:";
    	mnemonic = "A";
    	key = "aproved";
    	alignment = centered;
    	edit_limit = 6;
    	edit_width = 6;
    	value = "";
    	}
    	}
     : boxed_column {				//define boxed column
            label = "&Language";			//give it a label
     
         	: popup_list {				
            key = "selections";			//give it a name
            value = "1" ;				//initial value
            }					
     
           }					
    
    :row{
     : errtile
    	{
    	width = 30;
    	}
    
      }
    
           ok_cancel ;
    
    
    
    : row {					 	//define row
     
    
         : paragraph {				//define paragraph
     
         : text_part {				//define text
         label = "Created";	                	//give it some text
         }						//end text
     
         : text_part {				//define more text
         label = "by";	//some more text
         }						//end text
     
         }						//end paragraph
     
         }						//end row
    					
         }						//end dialog
    
    
    LISP coding:
    ------------------------------------------------------
    ;;;; 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:INIT (/ id intStart DELV VERIF APPR)
    
      (setq selected_language "NL")		;preset hole size
    
      (setq	TALEN '("NL" "FR")		;define list
      )					;setq
    
    
      (setq dcl_id (load_dialog "DB02.dcl")) ;load dialog
    
      (if (not (new_dialog "DB02" dcl_id)	;test for dialog
    
          )					;not
        (progn
          (exit)				;exit if no dialog
          (princ "\ Dialog not found")
        )					;endprogn
      )					;endif
    
      (mode_tile "drawn" 2)			; field drawn can be overwritten by user
      (action_tile "drawn" "(setq DELV $value)")
    					;moves value from field "drawn" to variable DELV
      (set_tile "drawn" "Name")		;fills in "NAME" by default
      (mode_tile "verified" 2)
      (action_tile "verified" "(setq VERIF $value)")
      (set_tile "verified" "Name")
      (mode_tile "aproved" 2)
      (action_tile "aproved" "(setq APPRO $value)")
      (set_tile "aproved" "Name")
    
      (start_list "selections")		;start the list box
      (mapcar 'add_list TALEN)		;fill the list box
      (end_list)				;end list
    
      (action_tile
        "cancel"				;if cancel button pressed
        "(done_dialog) (setq userclick nil)" ;close dialog, set flag
      )					;action_tile
    
      (action_tile
        "accept"				;if O.K. pressed
        (strcat				;string 'em together
          "(progn 
           (setq selected_language (atof (get_tile \"selections\")))"
    					;get list selection
          " (val1)(setq userclick T))"	;close dialog, set flag
        )					;strcat
    
    
      )					;action tile
    
    
    
      (start_dialog)			;start dialog
      (unload_dialog dcl_id)		;unload
    
      (princ)				;load clean
    
    )					;DEFUN
    
    
    
    -------------------------------------------------
    ;; CHECK IF NAMES ARE WRITTEN IN THE FIELDS
    -------------------------------------------------
    (defun val1 ()
    
      (if userclick				;check O.K. was selected
        (progn
    
          (setq selected_language (fix selected_language))
    					;convert to integer
          (setq selected_language (nth selected_language TALEN))
    					;get the size
        )					;progn
    
      )					;if userclick
      (if (= (get_tile "drawn") "Name")	;default value of field is "name"
        (progn
          (set_tile "error" "You must enter a name in 'Drawn By' !")
    					;give alert when user didn't change field
          (mode_tile "drawn" 2)		;allows the field to be overwritten
        )					;progn
        (val2)
      )					;if
    
    )					;defun
    
    -------------------
    					;same functons as val1 but different field
    
    (defun val2 ()
      (if (= (get_tile "verified") "Name")
        (progn
          (set_tile	"error"
    		"You must enter a name in 'Verified By' !"
          )
          (mode_tile "verified" 2)
        )					;progn
        (val3)
    
      )					;if
    )					;defun
    -------------------
    					;same functons as val1 but different field
    (defun val3 ()
      (if (= (get_tile "aproved") "Name")
        (progn
          (set_tile	"error"
    		"You must enter a name in 'Approved By' !"
          )
          (mode_tile "aproved" 2)
        )					;progn
        (progn
          (done_dialog)
          (check_language)
        )					;progn
      )					;if
    )					;defun
    --------------------------------------
    					;Function to check which language is selected
    
    (defun check_language()
      (if
        (eq selected_language "NL")		;if NL is selected
         (set_NL)				;Start set_NL
         (set_FR)				;ELSE start set_FR
      )					;endif
    )					;defun
    
    ------------------------------------------------
    ;;;;:DEFINE ACTIONS;;;;;;;;;;;;;;;;;;;;
    ------------------------------------------------
    ;;;; ROUTINE SET NL
    
    (defun set_NL ()			; FUNCTION SET LAYER TO NL
      (if
        (setq DirPath
    	   (BrowseForFolder "Select folder of drawings to process: ")
        )
    
         (progn
           (setq DwgList (vl-directory-files DirPath "*.dwg" 1))
           (setq ScrFile (strcat DirPath "Batch_Dwg.scr"))
           (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
           )
           (foreach	Dwg DwgList
    	 (setq FullPath (strcat DirPath Dwg))
    	 (write-line
    	   (strcat "_.open " (chr 34) FullPath (chr 34))
    	   Ofil
    	 )
    	 (write-line
    	   (strcat "(command "
    		   (chr 34)
    		   "_layer"
    		   (chr 34)
    		   (chr 34)
    		   "S"
    		   (chr 34)
    		   (chr 34)
    		   "DRAW"
    		   (chr 34)
    		   (chr 34)
    		   (chr 34)
    		   ")"
    	   )
    	   Ofil
    	 )
    	 (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
    	 )
    	 (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
    	 )
    	 (write-line
    	   (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)")
    	   Ofil
    	 )
    	 (write-line ".qsave" Ofil)
    	 (write-line "_.close" Ofil)
           )				; foreach
           (write-line "\(alert \"Done!!\"\)" Ofil)
           (close Ofil)
           (command "_.script" ScrFile)
         )
      )
      (princ)
    )					; function
    
    ---------------------------------------------------------------------
    ;;;; ROUTINE SET FR
    
    (defun set_FR ()			; FUNCTION SET LAYER TO FR
      (if (setq DirPath
    	     (BrowseForFolder "Select folder of drawings to process: ")
          )
        (progn
          (setq DwgList (vl-directory-files DirPath "*.dwg" 1))
          (setq ScrFile (strcat DirPath "Batch_Dwg.scr"))
          (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
          )
          (foreach Dwg DwgList
    	(setq FullPath (strcat DirPath Dwg))
    	(write-line
    	  (strcat "_.open " (chr 34) FullPath (chr 34))
    	  Ofil
    	)
    	(write-line
    	  (strcat "(command "
    		  (chr 34)
    		  "_layer"
    		  (chr 34)
    		  (chr 34)
    		  "S"
    		  (chr 34)
    		  (chr 34)
    		  "DRAW"
    		  (chr 34)
    		  (chr 34)
    		  (chr 34)
    		  ")"
    	  )
    	  Ofil
    	)
    	(write-line
    	  (strcat "(command "
    		  (chr 34)
    		  "_layer"
    		  (chr 34)
    		  (chr 34)
    		  "F"
    		  (chr 34)
    		  (chr 34)
    		  "INFO_NL"
    		  (chr 34)
    		  (chr 34)
    		  (chr 34)
    		  ")"
    	  )
    	  Ofil
    	)
    	(write-line
    	  (strcat "(command "
    		  (chr 34)
    		  "_layer"
    		  (chr 34)
    		  (chr 34)
    		  "T"
    		  (chr 34)
    		  (chr 34)
    		  "INFO_FR"
    		  (chr 34)
    		  (chr 34)
    		  (chr 34)
    		  ")"
    	  )
    	  Ofil
    	)
    	(write-line
    	  (strcat "(setvar " (chr 34) "FILEDIA" (chr 34) " 1)")
    	  Ofil
    	)
    	(write-line ".qsave" Ofil)
    	(write-line "_.close" Ofil)
          )					; foreach
          (write-line "\(alert \"Done!!\"\)" Ofil)
          (close Ofil)
          (command "_.script" ScrFile)
        )					; progn
      )					; if
      (princ)
    )					; function
    ---------------------------------------------------------------------
    Last edited by Ed Jobe; 2015-07-29 at 03:07 PM. Reason: Added Code Tags

  6. #6
    Member
    Join Date
    2015-05
    Posts
    14
    Login to Give a bone
    0

    Default Re: Lisp: Autocad crashes ( on dialogbox?)

    Solved the crashing problem. (and now I'm finally beginning to understand the dialog_done function.

    for cancel-button: (action_tile "cancel" "(done_dialog 0)")
    for the OK-buttonaction_tile "accept" (strcat"(progn (setq selected_language (atof (get_tile \"selections\")))" " (val1)")

    val1 to val3 i'm checking if my 3 edit-fields are used. At the end of the 3rd "sub"function I've placed (done_dialog 2)

    added this piece of code (instead of just (start_dialog) (Unload_dialog)
    if the flag is set to 2 (is being set after the check of the edit-boxes), i go to my routine that checks which language is selected and so on.

    (setq main_flag (start_dialog))
    (if (= main_flag 2)
    (check_language));if
    (unload_dialog dcl_id)

Similar Threads

  1. Replies: 7
    Last Post: 2015-08-07, 06:28 AM
  2. 2013: Opening Worksets Dialogbox
    By mvalencia25 in forum Revit - Worksharing/Worksets/Revit Server
    Replies: 3
    Last Post: 2015-05-07, 03:47 PM
  3. 2012: Lost a dialogbox & need help to get it back
    By cdmdwgpe.67574 in forum ACA General
    Replies: 2
    Last Post: 2012-01-19, 09:54 PM
  4. Replies: 0
    Last Post: 2010-04-01, 03:21 PM
  5. Dialogbox Tastaturkürzel abschalten
    By mauricio2 in forum Inventor - General
    Replies: 2
    Last Post: 2007-07-30, 01:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •