Add if statement to give me a choice of which data file to set

Add if statement to give me a choice of which data file to set

johnw
Collaborator Collaborator
560 Views
9 Replies
Message 1 of 10

Add if statement to give me a choice of which data file to set

johnw
Collaborator
Collaborator

In the code below I don't know where I should insert an IF statement that when I execute this command it will prompt me "Is this set of layers for std or custom:". If std, which would be the default, it would follow the layerset.dat coding that is already listed. If Custom, type "C" for custom and then it would load, read, a file called layerset1.dat instead. Nothing else would need to change. Thanks for any assistance. 

 

(defun C:LAYERSET ()
    (command "redraw")
    (SETVAR "REGENMODE" 0)
    (COMMAND-S "LAYER""SET""0""")
    (COMMAND-S "LAYER""FREEZE""*""")
    (prompt "Installing new layers:  ")
    (terpri)
    (prompt "          please wait....")
    (SAVEMODE
        (quote
            ("CMDECHO" "MENUECHO" "EXPERT")
        )
    )
    (setvar "EXPERT" 0)
    (setvar "CMDECHO" 0)
    (setvar "MENUECHO" 3)
    (setq RFILE (OPEN (strcat lisp "layerset.dat") "r")) ;Opens layerset.dat for read
    (setq LAYER (read-line RFILE))
    (setq LINETYPE (read-line RFILE))
    (setq COLOR (read-line RFILE))
        (while (/= LAYER nil)
            (command "LAYER" "m" LAYER "lt" LINETYPE LAYER "c" COLOR LAYER "");if linetype does not exist, then, this will be interrupted in the middle
    (command ^C^C)
            (setq LAYER (read-line RFILE))
            (setq LINETYPE (read-line RFILE))
            (setq COLOR (read-line RFILE))
        )                                              ;end while
    (close RFILE)
    (terpri)
   (SETVAR "REGENMODE" 1)
   (COMMAND "LAYER""THAW""*""")
   (RESTMODE)
    (prompt "\nAll the Layers, Colors, and Linetypes are installed or have been reinstalled....")
    (prin1)
)
0 Likes
Accepted solutions (2)
561 Views
9 Replies
Replies (9)
Message 2 of 10

john.uhden
Mentor
Mentor

Hello, @johnw , I am JohnU.

 

First, I'm gonna guess that your .DAT file contains multiple layers and properties.  So you may want to structure your program something like this:

 (setq RFILE (OPEN (strcat lisp "layerset.dat") "r")) ;Opens layerset.dat for read
 (while (setq line (read-line RFILE))
   (setq LAYER (read-line RFILE))
   (setq LINETYPE (read-line RFILE))
   (setq COLOR (read-line RFILE))
   (if (not (tblsearch "ltype" linetype))
     (setq linetype "Continuous") ;if linetype does not exist
   )
   (command "LAYER" "m" LAYER "lt" LINETYPE LAYER "c" COLOR LAYER "")
 )

Of course I would prefer to include the layer, linetype. and color as one line in the file, each property delimited.  by a tab.  Otherwise, if you miss a line or add an extra one, then your sequence will be lobotomized.  If you're interested in that method then I (or dozens of others) will provide you a function to do that.

Always remember to close the file. 

John F. Uhden

0 Likes
Message 3 of 10

paullimapa
Mentor
Mentor

I would change the code at this point:

(setq RFILE (OPEN (strcat lisp "layerset.dat") "r")) ;Opens layerset.dat for read

to this:

; dynmode needs to be 1 or 3 to display cursor popup
(if(<= (rem (getvar"dynmode") 2) 0) ; if even # chks negative value as well
  (progn
   (setq dynmode (getvar"dynmode")) ; save current setting
   (setvar "dynmode" 1) ; enable dynmode
  )
) ; if
(or **lyropt** (setq **lyropt** "Standard")) ; setup default
(initget (setq lyropt "Standard Custom"))
(setq **lyropt** (cond ((getkword (strcat "\nIs this set of layers for [" (vl-string-translate " " "/" lyropt) "] <" **lyropt** ">: ")))(**lyropt**)))
(if dynmode (setvar "dynmode" dynmode)) ; restore original dynmode setting
(if (eq **lyropt** "Standard")
 (setq lyrfile "layerset.dat")
 (setq lyrfile "layerset1.dat")
)
(setq RFILE (OPEN (strcat lisp lyrfile) "r")) ;Opens layer file to read

paullimapa_0-1686628688517.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 10

komondormrex
Mentor
Mentor
Accepted solution

acet used.

(defun C:LAYERSET ()
    (command "redraw")
    (SETVAR "REGENMODE" 0)
    (COMMAND-S "LAYER""SET""0""")
    (COMMAND-S "LAYER""FREEZE""*""")
    (prompt "Installing new layers:  ")
    (terpri)
    (prompt "          please wait....")
    (SAVEMODE
        (quote
            ("CMDECHO" "MENUECHO" "EXPERT")
        )
    )
    (setvar "EXPERT" 0)
    (setvar "CMDECHO" 0)
    (setvar "MENUECHO" 3)

	;********************************************************************************************
	(if (= 6 (acet-ui-message "Are you going to process STD Layer set?" "Attention" 4))
			(setq RFILE (OPEN (strcat lisp "layerset.dat") "r")) ;Opens layerset.dat for read
			(setq RFILE (OPEN (strcat lisp "layerset1.dat") "r")) ;Opens layerset1.dat for read
	)
	;********************************************************************************************

    (setq LAYER (read-line RFILE))
    (setq LINETYPE (read-line RFILE))
    (setq COLOR (read-line RFILE))
        (while (/= LAYER nil)
            (command "LAYER" "m" LAYER "lt" LINETYPE LAYER "c" COLOR LAYER "");if linetype does not exist, then, this will be interrupted in the middle
    (command ^C^C)
            (setq LAYER (read-line RFILE))
            (setq LINETYPE (read-line RFILE))
            (setq COLOR (read-line RFILE))
        )                                              ;end while
    (close RFILE)
    (terpri)
   (SETVAR "REGENMODE" 1)
   (COMMAND "LAYER""THAW""*""")
   (RESTMODE)
    (prompt "\nAll the Layers, Colors, and Linetypes are installed or have been reinstalled....")
    (prin1)
)
Message 5 of 10

johnw
Collaborator
Collaborator

Thanks for your help on this! I really appreciate it! 

0 Likes
Message 6 of 10

WeTanks
Mentor
Mentor

please teach me

Why is it an error?

 

WeTanks_0-1686786651491.png

 

(defun C:LAYERSET ()
    (command "redraw")
	;********************************************************************************************
	(if (= 6 (acet-ui-message "Are you going to process STD Layer set?" "Attention" 4))
			(setq RFILE (OPEN (strcat "D:\\OneDrive\\11_LISP_FORUM\\layerset.dat") "r")) ;Opens layerset.dat for read
			(setq RFILE (OPEN (strcat "D:\\OneDrive\\11_LISP_FORUM\\layerset1.dat") "r")) ;Opens layerset1.dat for read
	)
	;********************************************************************************************



 

 ==================================================
English is my second language.
Please don't worry if I make any English mistakes.
英語は母国語ではない
英語のミスをしても気にしないでください。

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 7 of 10

john.uhden
Mentor
Mentor

@WeTanks ,

You appear to be using strcat with only one string.

John F. Uhden

0 Likes
Message 8 of 10

WeTanks
Mentor
Mentor

This is my all LISP. I just modified that part of dat.

(defun C:LAYERSET ()
    (command "redraw")
    (SETVAR "REGENMODE" 0)
    (COMMAND-S "LAYER""SET""0""")
    (COMMAND-S "LAYER""FREEZE""*""")
    (prompt "Installing new layers:  ")
    (terpri)
    (prompt "          please wait....")
    (SAVEMODE
        (quote
            ("CMDECHO" "MENUECHO" "EXPERT")
        )
    )
    (setvar "EXPERT" 0)
    (setvar "CMDECHO" 0)
    (setvar "MENUECHO" 3)

	;********************************************************************************************
	(if (= 6 (acet-ui-message "Are you going to process STD Layer set?" "Attention" 4))
			(setq RFILE (OPEN (strcat "D:\\OneDrive\\11_LISP_FORUM\\layerset.dat") "r")) ;Opens layerset.dat for read
			(setq RFILE (OPEN (strcat "D:\\OneDrive\\11_LISP_FORUM\\layerset1.dat") "r")) ;Opens layerset1.dat for read
	)
	;********************************************************************************************

    (setq LAYER (read-line RFILE))
    (setq LINETYPE (read-line RFILE))
    (setq COLOR (read-line RFILE))
        (while (/= LAYER nil)
            (command "LAYER" "m" LAYER "lt" LINETYPE LAYER "c" COLOR LAYER "");if linetype does not exist, then, this will be interrupted in the middle
    (command ^C^C)
            (setq LAYER (read-line RFILE))
            (setq LINETYPE (read-line RFILE))
            (setq COLOR (read-line RFILE))
        )                                              ;end while
    (close RFILE)
    (terpri)
   (SETVAR "REGENMODE" 1)
   (COMMAND "LAYER""THAW""*""")
   (RESTMODE)
    (prompt "\nAll the Layers, Colors, and Linetypes are installed or have been reinstalled....")
    (prin1)
)

 

 

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes
Message 9 of 10

komondormrex
Mentor
Mentor
Accepted solution

it is undeclared 'savemode' function which your code tries to execute in line 9. you need to load it before running your code.

and as @john.uhden  wrote it is better to remove 'strcat' function for concatenating the only string. however the code will still be running with it.

 

or you can add these functions to your code or load them independently.

(defun savemode (var_list)
	(setq savemode_remembered (mapcar 'cons var_list (mapcar 'getvar var_list)))
	(princ)
)

(defun restmode nil
	(mapcar '(lambda (var_data) (setvar (car var_data) (cdr var_data))) savemode_remembered)
	(princ)
)
Message 10 of 10

WeTanks
Mentor
Mentor

どうもありがとうございました。

We.Tanks

EESignature

A couple of Fusion improvement ideas that could your vote/support:
図面一括印刷

0 Likes