乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 71|回复: 1

[编程交流] Lisp to open multiple DWG'

[复制链接]

5

主题

7

帖子

2

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-5 17:09:25 | 显示全部楼层 |阅读模式
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?
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 18:23:29 | 显示全部楼层
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.
 
  1. (setq num (getstring)) ; enter your variable; do what ever else open file write the scriptopen dwg1 (setq num "12345") (load "next step") close Yopen dwg2 (setq num "12345") (load "next step") close Yopen dwg3 (setq num "12345") (load "next step") close Y
 

[code]; as you have set num the line will skip so code can be used in non script mode.(if (= num nil)(setq num (getstring t "\nType the numer: "))) ;
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 08:58 , Processed in 0.411329 second(s), 67 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表