andr3flaviano Posted October 5, 2016 Posted October 5, 2016 Hello, guys! I'm creating a lisp to open multiple DWG's in a directory and alterate a number at a especific position. I have a function (called txt) to write the number at a position and I have another function (called change_all) to open every DWG in the directory and execute the function "txt". I want that the "Change_all" asks me the number and then execute the "txt" to write that number in all DWG's. The functions are already working, but i couldn't call the "txt" with the parameter number previously defined Here are the code: (defun c:txt (tval) ; (setq num0 (ssget "_C" '(347.06 18.12) '(350.90 18.12))) ; (command ".erase" num0 "" ); (setq pt1 '(346.5 15.84)) ; (if (not (tblsearch "Layer" "TEXT")) (command "-layer" "m" "TEXT" "") ) ;_ end if (entmake (list '(0 . "TEXT") '(8 . "TEXT5") (cons 10 pt1) (cons 40 4.5) (cons 1 tval) '(50 . 0.0) '(7 . "ROMANS") '(71 . 0) '(62 . 4) '(72 . 0) '(73 . 0) ) ;_ end list ) ;_ end entmake (*error* "") (princ) ) ;_ end defun (defun c: change_all (/ dwglist dwgname dwgpre file openfile uhoh len) (vl-load-com) (if (and (setq dwgpre (getvar 'dwgprefix)) (setq dwglist (vl-sort (vl-remove (strcat dwgpre (getvar 'dwgname)) (mapcar '(lambda (dwgname) (strcat dwgpre dwgname)) (vl-directory-files dwgpre "*.dwg") ) ) ' ) ) (setq uhoh "Readonly drawings will not be processed!" ) (setq len (strlen uhoh)) ) (progn (setq openfile (open (setq file (strcat dwgpre "myscript.scr")) "w")) (setq num (getstring t "\nType the numer: ")) ; (progn (foreach f dwglist (if (and (not (Is_ReadOnly f)) (/= (checkAttFile f) 1) ) (progn (write-line (strcat "_.open \"" f "\"") openfile) (write-line "(C: (txt num))" openfile) ; (write-line "_.qsave _.close" openfile) ) (setq uhoh (strcat uhoh "\n" f)) ) ) (close openfile) (command "_.script" file) (if (= (strlen uhoh) len) (princ "All drawings successfully processed...") (alert uhoh) ) ) ) ) (princ) ) ; End Defun Could someone help me, please? Quote
BIGAL Posted October 6, 2016 Posted October 6, 2016 The 1st step calls for the enter variable, you can write to file the answer or you can write to the registery or write the script file which includes as part of each dwg open the variable value. (setq num (getstring)) ; enter your variable ; do what ever else open file write the script open dwg1 (setq num "12345") (load "next step") close Y open dwg2 (setq num "12345") (load "next step") close Y open dwg3 (setq num "12345") (load "next step") close Y ; as you have set num the line will skip so code can be used in non script mode. [color=#ff0000](if (= num nil)(setq num (getstring t "\nType the numer: "))) ; <-- Asks the value to be written [/color] [color=#ff0000] [/color] Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.