明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1467|回复: 14

[讨论] 各位高手帮忙看下这个LISP以前能用,不知道什么时候就不能用了。哪位高手帮忙检查下。

[复制链接]
发表于 2016-10-5 16:49:45 | 显示全部楼层 |阅读模式



;自定义函数按如下注解处理一实数:
;                  若实数大于或等于1舍入后取小数点后一位并转换为字符串,若小数点后一位为零取整数位;
;                  若大于0.1小于1取其倒数舍入后取小数点后一位并转换为字符串;

(defun get_nv(real_num)
  (if (and (< 0.1 real_num)(< real_num 1))
    (progn
      (setq real_num1(/ 1 real_num)
            str_nam(rtos real_num1 2 1)
            str_nam[3](substr str_nam 3 1))
      (if (= str_nam[3] "0")
        (progn
          (setq str_nam(substr str_nam 1 1)))
        (progn
          (setq str_nam(rtos real_num1 2 1)))
        )
      )
    (progn
      (if (and (>= real_num 1)(< real_num 10))
        (progn
          (setq str_nam(rtos real_num 2 1)
                str_nam[3](substr str_nam 3 1))
          (if (= str_nam[3] "0")
            (progn
              (setq str_nam(substr str_nam 1 1)))
            (progn
              (setq str_nam(rtos real_num 2 1)))
            )
          )
        (progn
          (if (<= real_num 0.1)
            (Progn
              (setq str[0] (ascii "O")
                    str[1] (chr (- str[0] 10))
                    str[2] (chr (+ str[0] 5))
                    str[3] (chr (1- (ascii str[1])))
                    str[4] (chr (1- (ascii str[3])))
                    str[5] (chr (1- (1- (ascii str[4]))))
                    edd(strcat str[4] str[3] str[5])
                    endd(strcat edd str[2] str[1]))
              )
            (progn
              (if (> real_num 10)
                (progn
                  (setq str_nam(rtos real_num 2 1)
                        str_nam[4](substr str_nam 4 1))
                  (if (= str_nam[4] "0")
                    (progn
                      (setq str_nam(substr str_nam 1 2)))
                    (progn
                      (setq str_nam(rtos real_num 2 1)))
                    )
                  )
                (prompt "所用数值使用概率渺渺,程序溢出!!!")
                )
              )
            )
          )
        )
      )
    )
  )


;*******************************************************************************************************;

;以下函数按处理码查询符合指定属性标签之属性并返回该属性群组码;
(defun gatt_vl(obj_dxf match_str / )
  (setq tag 1)(setq ref_handle (cdr (assoc 5 obj_dxf)))
  (while (= tag 1)
    (setq ref_handle (HS16+1 ref_handle)
          attobj_name (handent ref_handle))
    (if attobj_name
      (setq att_styl (cdr (assoc 0 (entget attobj_name))))
      )
    (while (or (not attobj_name)(/= att_styl "ATTRIB"))
      (setq ref_handle (HS16+1 ref_handle)
            attobj_name (handent ref_handle))
      (if attobj_name
        (setq att_styl (cdr (assoc 0 (entget attobj_name))))
        )
      (prompt "\n图块中处理码跳跃递增,程序运行将消耗更长时间!!!")
      )
    (setq att_tag (cdr (assoc 2 (entget attobj_name))))
    (if (= att_tag match_str)
          (progn
            (setq tag 2))
          )
        )
     (setq get_value attobj_name)
  )



;*******************************************************************************************************;

;将选集内所有符合条件之A3,A4图框,零件清单,内部设变联络单按其页码序号顺次批量打印;
;注:对张次中数字相同但末位字母不同者,按字母以A-Z顺序打印.
(defun c:ZXC()(setq cmd(getvar "cmdecho"))(setvar "cmdecho" 0)
  (defun plot_way( ploter paper_sp plot_d base_pt plot_pt dep_val plot_style /)
    (command "-plot" "Y" "" ploter paper_sp "M" plot_d "N" "W" "none" base_pt "none" plot_pt "F"
             dep_val "Y" plot_style "Y" "A" "N" "N" "Y")
    )
  (setq plot_style "PX-plot.ctb")
  (prompt "\n***若已指定前次出图打印机为'HP LaserJet 5200 Series PCL 5',请输入'C'!!!***")
  (prompt "\n***欲以网络打印机'HP Color LaserJet 3800 PCL 5c'打印,请输入'B'!!!***")
  (prompt "\n***其它输入(含空输入)均以'HP LaserJet 5200 Series'网络打印机打印!!!***")
  (initget 6 "A B C")
  (setq tab (getint "\n请选择打印机 [HP 5100S(A)/HP 3800(B)/HP 5200(C) <HP 5100S(A)>"))
  (if (= tab "B")
    (progn
      (setq tab 2))
    (progn
      (if (= tab "C")
        (progn
          (setq tab 3))
        (progn
          (setq tab 1))
        )
      )
    )

  (cond ((= tab 1)(setq plot_machine "\\\\rd2-printer\\px设计部HP 5200TN"))
        ((= tab 2)(setq plot_machine "HP Color LaserJet 3800 PCL 5c"))
        ((= tab 3)(setq plot_machine "HP LaserJet 5200 Series PCL 5")))(princ)

  (setq obj_sel (ssget ":s" ' ((0 . "INSERT")
                               (-4 . "<or")(2 . "PX-A*")(2 . "PX-SBD")(2 . "PX-SBD-X")
                               (2 . "PX-NSB")(2 . "PX-SPB")(-4 . "or>"))))
  (setq drw_format (ssget "p" ' ((2 . "PX-A*"))))
  (if drw_format
    (progn
      (setq oth_sel (sub_ssget obj_sel drw_format))
      )
    (progn
      (setq oth_sel obj_sel)
      )
    )
  (if oth_sel
    (progn      
      (setq spb_bill (seed_ssget oth_sel "PX-SPB")            
            nsb_bill (seed_ssget oth_sel "PX-NSB")
            sbd_bill (seed_ssget oth_sel "PX-SBD")
            sbdx_bil (seed_ssget oth_sel "PX-SBD-X"))
      )
    )
  (cond (sbdx_bil (setq sbd_bill (add_ssget sbdx_bil sbd_bill))))(princ)  
  (setq count[1] 0 count[2] 0 count[3] 0)

  (defun abt_hnd[5] (obj_sel /)
    (setq obj_num (sslength obj_sel)
          jump 0
          obj_cab nil)
    (while (< jump obj_num)
      (setq obj_dxf (entget (ssname obj_sel jump))
            obj_base (trans (cdr (assoc 10 obj_dxf))0 1)
            obj_scale (cdr (assoc 41 obj_dxf))
            sheet_code[1] (cdr (assoc 1 (entget (gatt_vl obj_dxf "SP")))))
      (if (= jump 0)
        (setq sheet_code[2] (cdr (assoc 1 (entget (gatt_vl obj_dxf "AP")))))
        )
      (setq sub_list[0] (cons "" nil)
            sub_list[1] (cons obj_scale sub_list[0])
            sub_list[2] (cons obj_base sub_list[1])
            sub_list[3] (cons sheet_code[1] sub_list[2])
            obj_cab (cons sub_list[3] obj_cab))
        (setq jump (1+ jump))
        )
    (setq final obj_cab)
    )

  (if nsb_bill
    (progn
      (prompt "\n请等待,程序正准备打印非标准零件清单!!")(princ)
      (setq nsb_cab (vl-sort (abt_hnd[5] nsb_bill)
                          (function (lambda (c1 c2)
                                      (< (atoi (nth 0 c1)) (atoi (nth 0 c2)))))))      
      (setq nsb_list (length nsb_cab))
      (setq jump 0)
      (while (< jump nsb_list)
        (setq p_count (car (nth jump nsb_cab))
              nsb_base (cadr (nth jump nsb_cab))
              plot_scale (caddr (nth jump nsb_cab))
              plot_pnt (polar nsb_base (- 0 (atan 297.0 210.0))
                              (* plot_scale (sqrt(+ (sqr_x 297.0) (sqr_x 210.0))))))
        (prompt (strcat "\n正打印非标准零件清单总数" sheet_code[2] "张中第" p_count
                        "张,目前已打印" (itoa count[1])"张,请稍候:")) (princ)
        (command "zoom" "w" "none" nsb_base "none" plot_pnt)
        (cond ((= tab 1)(plot_way plot_machine "A4" "P" nsb_base plot_pnt "0,2.14" plot_style))
              ((= tab 2)(plot_way plot_machine "A4 210 x 297 mm" "P" nsb_base plot_pnt "0,2.86"
                                  plot_style))
              ((= tab 3)(plot_way plot_machine "A4" "P" nsb_base plot_pnt "0,2.14" plot_style)))
        (command "zoom" "p")
        (setq count[1] (1+ count[1]))
        (setq jump (1+ jump))
        )
      (setq nsb_bill nil)
      )
    )

  (if spb_bill
    (progn
      (prompt "\n请等待,程序正准备打印标准零件清单!!")(princ)
      (setq spb_cab (vl-sort (abt_hnd[5] spb_bill)
                          (function (lambda (c1 c2)
                                      (< (atoi (nth 0 c1)) (atoi (nth 0 c2)))))))      
      (setq spb_list (length spb_cab))
      (setq jump 0)
      (while (< jump spb_list)
        (setq p_count (car (nth jump spb_cab))
              spb_base (cadr (nth jump spb_cab))
              plot_scale (caddr (nth jump spb_cab))
              plot_pnt (polar spb_base (- 0 (atan 297.0 210.0))
                              (* plot_scale (sqrt(+ (sqr_x 297.0) (sqr_x 210.0))))))
        (prompt (strcat "\n正打印标准零件清单总数" sheet_code[2] "张中第" p_count
                        "张,目前已打印" (itoa (+ count[1] count[2])) "张,请稍候:")) (princ)
        (command "zoom" "w" "none" spb_base "none" plot_pnt)
        (cond ((= tab 1)(plot_way plot_machine "A4" "P" spb_base plot_pnt "0,2.14" plot_style))
              ((= tab 2)(plot_way plot_machine "A4 210 x 297 mm" "P" spb_base plot_pnt "0,2.86"
                                  plot_style))
              ((= tab 3)(plot_way plot_machine "A4" "P" spb_base plot_pnt "0,2.14" plot_style)))
        (command "zoom" "p")
        (setq count[2] (1+ count[2]))
        (setq jump (1+ jump))
        )
      (setq spb_bill nil)
      )
    )

  (if sbd_bill
    (progn
      (prompt "\n请等待,程序正准备打印内部设变联络单!!")(princ)
      (setq sbd_cab (vl-sort (abt_hnd[5] sbd_bill)
                          (function (lambda (c1 c2)
                                      (< (atoi (nth 0 c1)) (atoi (nth 0 c2)))))))      
      (setq sbd_list (length sbd_cab))
      (setq jump 0)
      (while (< jump sbd_list)
        (setq p_count (car (nth jump sbd_cab))
              sbd_base (cadr (nth jump sbd_cab))
              plot_scale (caddr (nth jump sbd_cab))
              plot_pnt (polar sbd_base (- 0 (atan 275.0 185.0))
                              (* plot_scale (sqrt(+ (sqr_x 275.0) (sqr_x 195.0))))))
        (prompt (strcat "\n正打印内部设变联络单总数" sheet_code[2] "张中第" p_count
                        "张,目前已打印" (itoa (+ count[1] count[2])) "张,请稍候:")) (princ)
        (command "zoom" "w" "none" sbd_base "none" plot_pnt)
        (cond ((= tab 1)(plot_way plot_machine "A4" "P" sbd_base plot_pnt "0,2.14" plot_style))
              ((= tab 2)(plot_way plot_machine "A4 210 x 297 mm" "P" sbd_base plot_pnt "0,2.86"
                                  plot_style))
              ((= tab 3)(plot_way plot_machine "A4" "P" sbd_base plot_pnt "0,2.14" plot_style)))
        (command "zoom" "p")
        (setq count[2] (1+ count[2]))
        (setq jump (1+ jump))
        )
      (setq sbd_bill nil)
      )
    )

  (if drw_format
    (progn      
      (prompt "\n请等待,程序正准备打印图面!!")(princ)
      (setq format_num (sslength drw_format))
      (setq jump 0
            format_cab nil
            totol_page (cdr (assoc 1 (entget (gatt_vl (entget (ssname drw_format 0)) "总张数")))))
      (while (< jump format_num)
        (setq format_dxf (entget (ssname drw_format jump))
              format_base (trans (cdr (assoc 10 format_dxf)) 0 1)
              format_angle (cdr (assoc 50 format_dxf))
              format_scale (cdr (assoc 41 format_dxf))
              format_style (cdr (assoc 2 format_dxf))
              sheet_code[1] (cdr (assoc 1 (entget (gatt_vl format_dxf "张次"))))
              sub_list[0] (cons "" nil)
              sub_list[1] (cons format_angle sub_list[0])
              sub_list[2] (cons format_scale sub_list[1])
              sub_list[3] (cons format_base sub_list[2])
              sub_list[4] (cons format_style sub_list[3])
              sub_list[5] (cons sheet_code[1] sub_list[4])
              format_cab (cons sub_list[5] format_cab))
        (setq jump (1+ jump))
        )
      (setq format_cab (vl-sort format_cab
                          (function (lambda (c1 c2)
                                      (< (chr_convert (nth 0 c1)) (chr_convert (nth 0 c2)))))))


      (setq jump 0)(setq prt_num (length format_cab))
      (while (< jump prt_num)
        (setq set_sequence (nth 0 (nth jump format_cab)))
        (setq format_style (nth 1 (nth jump format_cab)))
        (setq format_base (nth 2 (nth jump format_cab)))
        (setq format_scale (nth 3 (nth jump format_cab)))
        (setq format_angle (nth 4 (nth jump format_cab)))

        (if (or (= format_style "PX-A4")(= format_style "PX-A44"))
          (progn
            (setq plot_pnt(polar format_base (- format_angle (atan 275.0 195.0))
                           (* format_scale (sqrt (+ (sqr_x 275.0) (sqr_x 195.0))))))
            (prompt (strcat "\n正打印图面总数" totol_page "张中第" set_sequence "张,目前已打印"
                                (itoa (+ count[1] count[2] count[3]))"张,请稍候:"))(princ)
            (command "zoom" "w" "none" format_base "none" plot_pnt)
            (if (or (and (<= format_angle (* 1.6 pi))(>= format_angle (* 1.4 pi)))
                    (and (<= format_angle (* 0.6 pi))(>= format_angle (* 0.4 pi))))             
              (progn
                (cond ((= tab 1)(plot_way plot_machine "A4" "L" format_base plot_pnt "0,2.14"
                                          plot_style))
                      ((= tab 2)(plot_way plot_machine "A4 210 x 297 mm" "L" format_base plot_pnt
                                          "0,2.86" plot_style))
                      ((= tab 3)(plot_way plot_machine "A4" "L" format_base plot_pnt "0,2.14"
                                          plot_style)))
                )               
              (progn
                (cond ((= tab 1)(plot_way plot_machine "A4" "P" format_base plot_pnt "0,2.14"
                                          plot_style))
                      ((= tab 2)(plot_way plot_machine "A4 210 x 297 mm" "P" format_base plot_pnt
                                          "0,2.86" plot_style))
                      ((= tab 3)(plot_way plot_machine "A4" "P" format_base plot_pnt "0,2.14"
                                          plot_style)))
                )
              )
            (command "zoom" "p")
            (setq count[3] (+ count[3] 1))
            )
          )
       
        (if (or (= format_style "PX-A3")(= format_style "PX-A33"))
          (progn
            (setq plot_pnt(polar format_base (- format_angle (atan 285.0 400.0))
                           (* format_scale (sqrt (+ (sqr_x 285.0) (sqr_x 400.0))))))
            (prompt (strcat "\n正打印图面总数" totol_page "张中第" set_sequence "张,目前已打印"
                                (itoa count[3])"张,请稍候:"))(princ)
            (command "zoom" "w" "none" format_base "none" plot_pnt)
            (if (or (and (<= format_angle (* 1.6 pi))(>= format_angle (* 1.4 pi)))
                    (and (<= format_angle (* 0.6 pi))(>= format_angle (* 0.4 pi))))
              (progn
                (cond ((= tab 1)(plot_way plot_machine "A3" "P" format_base plot_pnt "3.31,0"
                                          plot_style))
                      ((= tab 2)(plot_way plot_machine "A3 297 x 420 mm" "P" format_base plot_pnt
                                          "3.91,0" plot_style))
                      ((= tab 3)(plot_way plot_machine "A3" "P" format_base plot_pnt "3.31,0"
                                          plot_style)))
                )
              (progn
                (cond ((= tab 1)(plot_way plot_machine "A3" "L" format_base plot_pnt "3.31,0"
                                          plot_style))
                      ((= tab 2)(plot_way plot_machine "A3 297 x 420 mm" "L" format_base plot_pnt
                                          "3.91,0" plot_style))
                      ((= tab 3)(plot_way plot_machine "A3" "L" format_base plot_pnt "3.31,0"
                                          plot_style)))
                )
              )
            (command "zoom" "p")
            (setq count[3] (+ count[3] 1))
            )
          )
        (setq jump (1+ jump))
        )
      )
    )  
  (prompt (strcat "打印图纸共" (itoa (+ (+ count[1] count[2]) count[3])) "张!!"))

  (setvar "cmdecho" cmd)(princ))

;*******************************************************************************************************;


 楼主| 发表于 2016-10-7 15:19:09 | 显示全部楼层
Command: zxc
***若已指定前次出图打印机为'HP LaserJet 5200 Series PCL 5',请输入'C'!!!***
***欲以网络打印机'HP Color LaserJet 3800 PCL 5c'打印,请输入'B'!!!***
***其它输入(含空输入)均以'HP LaserJet 5200 Series'网络打印机打印!!!***
请选择打印机 [HP 5100S(A)/HP 3800(B)/HP 5200(C) <HP 5100S(A)>c
Select objects: Specify opposite corner:
请等待,程序正准备打印非标准零件清单!!
请等待,程序正准备打印标准零件清单!!
请等待,程序正准备打印内部设变联络单!!
请等待,程序正准备打印图面!!; error: bad argument type: stringp nil
Command:
 楼主| 发表于 2016-10-6 07:27:36 | 显示全部楼层
Andyhon,您好!我们几个同事都在用这个,现在就一个同事那能用其他的都不能用,是不是有恶意的程序篡改了呀!我对这方面不懂,能帮忙调试下吗?还有我自己的电脑能用,整了好久都没搞好,CAD所有的设置我也重置了。
 楼主| 发表于 2016-10-5 16:55:27 | 显示全部楼层
以前能批量打印,而且用的非常好,现在不能用了,输入命定后能够框选,框选后没有反应???????求高手帮助下,因为我在DWG里面有上百份A3/A4的图纸,一张一张的打印很费时,还会漏打印。
发表于 2016-10-5 17:46:16 | 显示全部楼层
换成了新型号的 打印机 吗?
 楼主| 发表于 2016-10-5 18:07:12 | 显示全部楼层
你好没有换,我检查个打印机是对的。
发表于 2016-10-5 20:20:28 | 显示全部楼层
作业平台/CAD版本 有异动吗?
 楼主| 发表于 2016-10-6 07:32:10 | 显示全部楼层
Andyhon,您好,作业平台/CAD版本 ,这个我不清楚,CAD版本我这边没动过,我们没这个权限,只有IT能动。一般IT没收到我们的报修他不会去主动去动。
发表于 2016-10-6 13:07:46 | 显示全部楼层
这个应得一步步就错误讯息来厘清问题之所在
您可能得找个老手上机调试才成...
发表于 2016-10-9 11:51:02 | 显示全部楼层
少了一个函数:seed_ssget
去那台能打印的电脑上找找
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-20 04:52 , Processed in 0.203129 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表