明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1711|回复: 0

[源码] 分享一个画剖面线的代码

[复制链接]
发表于 2014-3-4 21:50 | 显示全部楼层 |阅读模式
  1. ;;;CADALYST 03/06  Tip2096: sectionline.lsp  Section Line (c) Wm. J. Townsend

  2. ;;;  SECTIONLINE.LSP - January ?006 - Wm.J.Townsend
  3. ;;;
  4. ;;;  Three styles of section lines each with optional annotation or
  5. ;;;  section/grid/page markers. Optional "SECTION X-X" tag too.
  6. ;;;
  7. ;;;  Makes a new SectionLine layer and is based on your DIMSCALE setting.
  8. ;;;
  9. ;;;  SE1 is the old standard dashed lines and arrowheads.
  10. ;;;
  11. ;;;  SE2 is a modified ISO style. Pick two points to control the
  12. ;;;  direction of the view.
  13. ;;;
  14. ;;;  SE3 is a free form ziggity-zaggity section line. Pick a bunch
  15. ;;;  of points to form the cut, and then select the viewing angle.

  16. ;;; Common file settings

  17. (defun *pmd_err* (msg)
  18.   (if (or (/= msg "\nFunction canceled. ")(= msg "\nQuit / Exit Abort. "))(princ)
  19. (princ (strcat "\nError: " msg)))(setq *error* *err_old* *err_old* nil)(layerback)
  20. (princ))

  21. ;;;

  22. (defun dtr (a) (* pi (/ a 180.0)))

  23. ;;;

  24. (defun selayer ()
  25.   (setvar "cmdecho" 0)
  26.   (setq *err_old* *error* *error* *pmd_err*)
  27.     (command "undo" "mark")
  28.       (if (= 0 (getvar "measurement"))(setq dist 0.25))
  29.       (if (= 1 (getvar "measurement"))(setq dist 6.0))
  30.   (setq tt1 nil)
  31.   (setq tm1 nil)
  32.   (setq tm2 nil)
  33.   (setq tm3 nil)
  34.   (setq msg5 nil)
  35.   (setq osm (getvar "osmode")
  36.         otm (getvar "orthomode")
  37.         olm (getvar "clayer")
  38.         dsc (getvar "dimtxt")
  39.         dsz (getvar "dimscale")
  40.         tsz (getvar "textsize")
  41.         tsm (tblsearch "layer" "SectionLine"))
  42.   (if (null tsm)
  43.     (progn
  44.       (prompt "\nCreating SectionLine Layer...\n")
  45.         (command "-layer" "m" "SectionLine" "lt" "dashed" "SectionLine" "c" "230" "SectionLine" "")))
  46.       (command "-layer" "s" "SectionLine" "")
  47.   (setvar "osmode" 0)
  48.   (setvar "orthomode" 0)
  49. (princ))

  50. ;;;

  51. (defun layerback ()
  52.   (setq *error* *err_old* *err_old* nil)
  53.     (command)(command)
  54.   (setvar "osmode" osm)
  55.   (setvar "orthomode" otm)
  56.   (setvar "dimscale" dsz)
  57.     (command "-layer" "s" olm "")
  58. (princ))

  59. ;;;

  60. (defun c:dfix ()
  61. (layerback)
  62. (princ))

  63. ;;;  Draws the directional leaders and places the view labels.

  64. (defun pointers ()
  65.   (setvar "dimscale" 2.0)
  66.   (command "leader" pt1 pt6 "" "" "n")(command "change" "l" "" "p" "lt" "continuous" "")
  67.   (command "leader" pt2 pt7 "" "" "n")(command "change" "l" "" "p" "lt" "continuous" "")
  68.   (command "text" "mc" pt8 (* dsc 1.5) 0 tt1)
  69.   (command "text" "mc" pt9 (* dsc 1.5) 0 tt1)
  70.   (setvar "dimscale" dsz))

  71. ;;;  Adds optional annotation, or SECTION (GRID/PAGE) identification
  72. ;;;  next to the cut line.

  73. (defun section_grid_page ()
  74.   (setq tm1 (getstring T "\nEnter SectionLine Identification, or Annotation <none>: ")
  75.         tm2 (getstring "\nEnter Page Number <none>: ")
  76.         tm3 (getstring "\nEnter Grid Coordinate <none>: ")
  77.        msg1 (strcase tm1)
  78.        msg2 (strcase (strcat tm1 " (" tm2 ")"))
  79.        msg3 (strcase (strcat tm1 " (" tm3 "/" tm2 ")")))
  80.   (setq msg5 msg3)
  81.   (progn
  82.     (cond
  83.       ((/= tm3 "")(setq msg5 msg3))
  84.       ((/= tm2 "")(setq msg5 msg2))
  85.       ((= tm2 "")(setq msg5 msg1)))
  86.     (command "text" "ml" pt10 dsc 0 msg5)))

  87. ;;; Draws the optional "SECTION  X - X" tag.

  88. (defun view_label ()
  89.   (setq choice (getstring "\nDo you wish to add a SectionLine View label? Yes/<No>: "))
  90.   (setq msg4 (strcase (strcat "%%uSECTION  "tt1" - "tt1"%%u")))
  91.     (if (or (= 89 (ascii choice))(= 121 (ascii choice)))
  92.       (progn
  93.         (setq pt12 (getpoint "\nPick a point for the SectionLine Reference label: "))
  94.         (command "text" "mc" pt12 dsc 0 msg4))
  95.       (princ)))

  96. ;;;  4 Point basic section line.

  97. (defun c:se1 ()
  98. (selayer)
  99.   (setq tt1 (strcase (getstring "\nEnter SectionLine Identifier: "))
  100.         pt1 (getpoint "\nPick SectionLine start point: ")
  101.         pt2 (getpoint pt1 "\nPick next corner: ")
  102.         pt3 (getpoint pt2 "\nPick next corner: ")
  103.         pt4 (getpoint pt3 "\nPick SectionLine end point:")
  104.        rang (angle pt2 pt1)
  105.        eang (angle pt3 pt4)
  106.         pt5 (polar pt1 rang (* dsc 1.25))
  107.         pt6 (polar pt4 eang (* dsc 1.25)))
  108.   (progn
  109.     (setvar "dimscale" 2.0)
  110.     (command "dim1" "leader" pt1 pt2 ^c ^c)
  111.     (command "erase" "l" "")
  112.     (command "dim1" "leader" pt4 pt3 ^c ^c)
  113.     (command "erase" "l" "")
  114.     (command "pline" pt1 pt2 pt3 pt4 "")
  115.     (command "text" "m" pt5 (* dsc 1.5) "0" tt1)
  116.     (command "text" "m" pt6 (* dsc 1.5) "0" tt1)
  117.     (setvar "dimscale" dsz))
  118.   (setq choice (getstring "\nDo you wish to add a SectionLine Reference label? Yes/<No>: "))
  119.     (if (or (= 89 (ascii choice))(= 121 (ascii choice)))
  120.       (progn
  121.         (setvar "osmode" 39)
  122.         (setq pt15 (getpoint "\nPick a point for the SectionLine reference label: ")
  123.                pt5 (polar pt15 0 (* dsc 1.5))
  124.               pt10 (polar pt5 0 (* dsc 0.5)))
  125.       (section_grid_page)
  126.         (command "line" pt5 pt15 ""))
  127.         (princ))
  128. (view_label)
  129. (layerback)
  130. (princ))

  131. ;;;  2 Point directional section line.

  132. (defun c:se2 ()
  133. (selayer)
  134.   (setq tt1 (strcase (getstring "\nEnter SectionLine Identifier: "))
  135.         pt1 (getpoint "\nPick SectionLine start point: ")
  136.         pt2 (getpoint pt1 "\nPick SectionLine end point: ")
  137.         ang (angle pt1 pt2)
  138.        aang (angle pt2 pt1)
  139.        bang (dtr 90)
  140.        cang (+ aang bang)
  141.         pt3 (polar pt1 aang dist)
  142.         pt4 (polar pt2 ang dist)
  143.         pt6 (polar pt1 cang (* dsc 4.0))
  144.         pt7 (polar pt2 cang (* dsc 4.0))
  145.        dang (angle pt1 pt6)
  146.         pt8 (polar pt6 dang (* dsc 1.25))
  147.         pt9 (polar pt7 dang (* dsc 1.25)))
  148.   (if (or (> (dtr 90) ang)(< (dtr 270) ang))
  149.     (setq pt5 (polar pt4 0 (* dsc 1.5)))
  150.     (setq pt5 (polar pt3 0 (* dsc 1.5))))
  151.   (setq pt10 (polar pt5 0 (* dsc 0.5)))
  152.   (setq choice (getstring "\nDo you wish to add a SectionLine Reference label? Yes/<No>: "))
  153.     (if (or (= 89 (ascii choice))(= 121 (ascii choice)))
  154.       (progn
  155.         (command "pline" pt3 pt4 "")(command "change" "l" "" "p" "c" "1" "")
  156.           (if (or (> (dtr 90) ang)(< (dtr 270) ang))
  157.             (command "pline" pt4 pt5 "")
  158.             (command "pline" pt3 pt5 ""))
  159.           (pointers)
  160.           (section_grid_page))
  161.       (progn
  162.        (command "pline" pt3 pt4 "")(command "change" "l" "" "p" "c" "1" "")
  163.        (pointers)))
  164. (view_label)
  165. (layerback)
  166. (princ))

  167. ;;;  Multi-point freeform section line. Too many variables (for me) to
  168. ;;;  automate the label position, so you get to select your own.

  169. (defun c:se3 ()
  170. (selayer)
  171.   (setq tt1 (strcase (getstring "\nEnter SectionLine Identifier: ")))
  172.   (setq pt1 (getpoint"\nPick SectionLine start point: "))
  173.   (setq pt2 (getpoint pt1 "\nPick next point: "))
  174.   (command "pline" pt1 pt2 "")
  175.     (while
  176.       (setq pt3 (getpoint pt2"\nPick next point: "))
  177.       (command "pline" "" pt3 "")
  178.       (command "pedit" pt1 "j" pt2 pt3 "" "")
  179.       (setq pt2 pt3))
  180.   (command "change" pt1 "" "p" "c" "1" "")
  181.     (progn
  182.       (command "circle" pt1 dist)
  183.       (command "extend" "l" "" pt1 "")
  184.       (command "erase" "l" ""))
  185.     (progn
  186.       (command "circle" pt2 dist)
  187.       (command "extend" "l" "" pt2 "")
  188.       (command "erase" "l" ""))
  189.   (setq pt5 (getpoint pt1 "\nPick a point to select SectionLine view angle: "))
  190.   (setq ang (angle pt1 pt5)
  191.        aang (angle pt5 pt1)
  192.        bang (dtr 90)
  193.        cang (+ aang bang)
  194.         pt6 (polar pt1 ang (* dsc 4.0))
  195.         pt7 (polar pt2 ang (* dsc 4.0))
  196.        dang (angle pt1 pt6)
  197.         pt8 (polar pt6 dang (* dsc 1.25))
  198.         pt9 (polar pt7 dang (* dsc 1.25)))
  199.         (pointers)
  200.   (setq choice (getstring "\nDo you wish to add a SectionLine Reference label? Yes/<No>: "))
  201.     (if (or (= 89 (ascii choice))(= 121 (ascii choice)))
  202.       (progn
  203.         (setvar "osmode" 39)
  204.         (setq pt15 (getpoint "\nPick a point for the SectionLine reference label: "))
  205.         (setq pt5 (polar pt15 0 (* dsc 1.5)))
  206.         (setq pt10 (polar pt5 0 (* dsc 0.5)))
  207.         (section_grid_page)
  208.         (command "line" pt5 pt15 ""))
  209.         (princ))
  210. (view_label)
  211. (layerback)
  212. (princ))

  213. ;;;

  214. (princ "\nC:SE1~SE3, SectionLine utilities loaded.")
  215. (princ)

评分

参与人数 2明经币 +2 收起 理由
zctao1966 + 1 赞一个!
flyfox1047 + 1 赞一个!

查看全部评分

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

本版积分规则

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

GMT+8, 2024-5-2 11:16 , Processed in 5.655382 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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