模具论坛

 找回密码
 注册

扫一扫,微信登录

QQ登录

只需一步,快速开始

搜索
热搜: 冲压 注塑 求助
    回车查看更多
    论坛可能已存在您要发布的主题帖 关闭
      查看: 1765|回复: 5

      [求助] 怎么用LSP命令打开或关闭图块?

      [复制链接]
      发表于 2010-5-26 22:50:00 | 显示全部楼层 |阅读模式
      求助各位大侠,能不能开发LSP命令来控制图块,打开或者关闭,我的标准件是做的图块,都放在0层,在总图中不容易看清楚,想用命令显示或关闭,求高手解答一下,谢谢了!
      发表于 2010-5-27 20:53:57 | 显示全部楼层
      我也在关注中,希望有解
      发表于 2010-5-27 22:55:23 | 显示全部楼层
      图块都要在0层做的。

      把图块放到不同的层,直接关层就成了。
       楼主| 发表于 2010-5-28 00:45:10 | 显示全部楼层
      我们是把0层也就是标准件层和模板层一起拆,如果把图块放到不同的层,拆图的时候就麻烦了
      发表于 2010-5-28 01:05:25 | 显示全部楼层
      工作习惯的问题,阿拉的 0层 通常是空白的。
      拆图是按图层来,一零件一图层。


      这个程序可以选择图块或其他
      command: ssx


      (defun ssx_fe (/ x data fltr ent)
        (setq ent (car (entsel "\nSelect object/<None>: ")))
        (if ent
          (progn
            (setq data (entget ent))
            (foreach x '(0 2 6 7 8 39 62 66 210)   ; does not include 38
              (if (assoc x data)
                (setq fltr
                  (cons (assoc x data) fltr)
                )
              )
            )   
            (reverse fltr)
          )
        )
      )
      ;;;
      ;;; Remove "element" from "alist".
      ;;;
      ;;; ssx_re == SSX_Remove_Element
      ;;;
      (defun ssx_re (element alist)
        (append
          (reverse (cdr (member element (reverse alist))))
          (cdr (member element alist))   
        )
      )
      ;;;
      ;;; INTERNAL ERROR HANDLER
      ;;;
      (defun ssx_er (s)                     ; If an error (such as CTRL-C) occurs
                                            ; while this command is active...
        (if (/= s "Function cancelled")
          (princ (strcat "\nError: " s))
        )
        (if olderr (setq *error* olderr))   ; Restore old *error* handler
        (princ)
      )
      ;;;   
      ;;; Get the filtered sel-set.
      ;;;
      ;;;
      (defun ssx (/ olderr)
        (gc)                                        ; close any sel-sets            
        (setq olderr *error*
              *error* ssx_er
        )
        (setq fltr (ssx_fe))
        (ssx_gf fltr)
      )
      ;;;
      ;;; Build the filter list up by picking, selecting an item to add,
      ;;; or remove an item from the list by selecting it and pressing RETURN.
      ;;;
      ;;; ssx_gf == SSX_Get_Filters
      ;;;
      (defun ssx_gf (f1 / t1 t2 t3 f1 f2)
        (while
          (progn
            (cond (f1 (prompt "\nFilter: ") (prin1 f1)))
            (initget
              "Block Color Entity Flag LAyer LType Pick Style Thickness Vector")
            (setq t1 (getkword (strcat
              "\n>>Block name/Color/Entity/Flag/"
              "LAyer/LType/Pick/Style/TEext/Thickness/Vector: ")))
          )
          (setq t2
            (cond
              ((eq t1 "Block")      2)   ((eq t1 "Color")     62)
              ((eq t1 "Entity")     0)   ((eq t1 "LAyer")      8)
              ((eq t1 "LType")      6)   ((eq t1 "Style")      7)
              ((eq t1 "Thickness") 39)   ((eq t1 "Flag" )     66)
              ((eq t1 "Vector")   210)   ((eq t1 "TExt" )      1)
              (T t1)
            )
          )
          (setq t3
            (cond
              ((= t2  2)  (getstring "\n>>Block name to add/<RETURN to remove>: "))
              ((= t2 62)  (initget 4 "?")
                (cond
                  ((or (eq (setq t3 (getint
                    "\n>>Color number to add/?/<RETURN to remove>: ")) "?")
                    (> t3 256))
                    (ssx_pc)                        ; Print color values.
                    nil
                  )
                  (T
                    t3                              ; Return t3.
                  )
                )
              )
              ((= t2  0) (getstring "\n>>Entity type to add/<RETURN to remove>: "))
              ((= t2  8) (getstring "\n>>Layer name to add/<RETURN to remove>: "))
              ((= t2  6) (getstring "\n>>Linetype name to add/<RETURN to remove>: "))
              ((= t2  1) (getstring "\n>>TExt to add/<RETURN to remove>: "))
              ((= t2  7)
                (getstring "\n>>Text style name to add/<RETURN to remove>: ")
              )
              ((= t2 39)  (getreal   "\n>>Thickness to add/<RETURN to remove>: "))
              ((= t2 66)  (if (assoc 66 f1) nil 1))
              ((= t2 210)
                (getpoint  "\n>>Extrusion Vector to add/<RETURN to remove>: ")
              )
              (T          nil)
            )
          )
          (cond
            ((= t2 "Pick") (setq f1 (ssx_fe) t2 nil)) ; get entity
            ((and f1 (assoc t2 f1))                 ; already in the list
              (if (and t3 (/= t3 ""))
                ;; Replace with a new value...            
                (setq f1 (subst (cons t2 t3) (assoc t2 f1) f1))
                ;; Remove it from filter list...
                (setq f1 (ssx_re (assoc t2 f1) f1))
              )  
            )
            ((and t3 (/= t3 ""))
              (setq f1 (cons (cons t2 t3) f1))
            )
            (T nil)
          )
        )
        (if f1 (setq f2 (ssget "x" f1)))
        (setq *error* olderr)
        (if (and f1 f2)
          (progn
            (princ (strcat "\n" (itoa (sslength f2)) " found. "))
            f2
          )
          (progn (princ "\n0 found.") (prin1))
        )
      )
      ;;;
      ;;; Print the standard color assignments.
      ;;;
      ;;;
      (defun ssx_pc ()
        (if textpage (textpage) (textscr))
        (princ "\n                                                     ")
        (princ "\n                 Color number   |   Standard meaning ")
        (princ "\n                ________________|____________________")
        (princ "\n                                |                    ")
        (princ "\n                       0        |      <BYBLOCK>     ")
        (princ "\n                       1        |      Red           ")
        (princ "\n                       2        |      Yellow        ")
        (princ "\n                       3        |      Green         ")
        (princ "\n                       4        |      Cyan          ")
        (princ "\n                       5        |      Blue          ")
        (princ "\n                       6        |      Magenta       ")
        (princ "\n                       7        |      White         ")
        (princ "\n                    8...255     |      -Varies-      ")
        (princ "\n                      256       |      <BYLAYER>     ")
        (princ "\n                                               \n\n\n")
      )
      ;;;
      ;;; C: function definition.
      ;;;
      (defun c:ssx () (ssx)(princ))
      (princ "\n\tType \"ssx\" at a Command: prompt or ")
      (princ "\n\t(ssx) at any object selection prompt. ")
      (princ)

      [ 本帖最后由 FANZAI 于 2010-5-28 01:14 编辑 ]
       楼主| 发表于 2010-5-28 21:19:05 | 显示全部楼层
      谢谢你的程序,下来研究下。我们标准件是做好的块,放在0层,拆模板的时候模板和0层一起拆,自动生成标准件,孔位置不会错位。
      您需要登录后才可以回帖 登录 | 注册

      本版积分规则

      关闭

      招聘信息 上一条 /5 下一条

      关闭

      求职信息 上一条 /5 下一条

      关闭

      技术求助 上一条 /5 下一条

      QQ|小黑屋|手机版|模具论坛 ( 浙ICP备15037217号 )

      GMT+8, 2025-7-30 04:53

      Powered by Discuz! X3.4

      © 2001-2013 Comsenz Inc.

      快速回复
      返回顶部
      返回列表
       
      客服电话:0577-61318188
      模具论坛交流群:
      模具论坛交流群
      工作时间:
      08:30-17:30