找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 713|回复: 5

[他山之石] Shape Explode

[复制链接]

已领礼包: 264个

财富等级: 日进斗金

发表于 2016-12-12 16:59:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×


  1. ;;;   ----------- Shape Explode - Version 1.0 -----------
  2. ;;;   Copyright (C) 2010 by ResourceCAD International
  3. ;;;   Author:   K.E. Blackie
  4. ;;;   
  5. ;;;   
  6. ;;;   RCI PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  7. ;;;   RESOURCECAD INTERNATIONAL SPECIFICALLY DISCLAIMS ANY
  8. ;;;   IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
  9. ;;;   USE.  RESOURCECAD INTERNATIONAL DOES NOT WARRANT THAT THE OPERATION
  10. ;;;   OF THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.
  11. ;;;   
  12. ;;;   
  13. ;;;   ResouceCAD International
  14. ;;;   http://www.resourcecad.com
  15. ;;;   
  16. ;;;   DESCRIPTION
  17. ;;;   Shape Exploder draws a shape as defined in the associated shx shape file
  18. ;;;   This does not currently include some features available in shapes, but
  19. ;;;   does work on simple shapes. It is expected the additional shape features
  20. ;;;   will be added at some point in the future
  21. ;;;   
  22. ;;;   NOTE
  23. ;;;   The included _ReadStream function which is critical to the operation of
  24. ;;;   this program was developed by MP. The original thread where the function
  25. ;;;   was posted at TheSwamp.org can be found here:
  26. ;;;   http://www.theswamp.org/index.php?topic=17465.msg210365#msg210365
  27. ;;;   No coyright is claimed on those portions of code developed by others.
  28. ;;;   
  29. ;;;   USAGE:
  30. ;;;   SHXPlode
  31. ;;;   
  32. ;;;   May 30, 2010
  33. ;;;   
  34. ;;;   ------------------------------------------------------------


  35. ;;; Entrypoint - our function to explode shapes
  36. (defun c:SHXPlode( / data enext insp IsShape name rangl scale shape shapedata sset width )
  37.   (while (/= IsShape t)
  38.     (princ "\nSelect shape to explode: ")
  39.     (setq shape (car (entsel)))
  40.     (if (= (cdr (assoc 0 (entget shape))) "SHAPE")
  41.       (setq IsShape T)
  42.       (princ "\nSelected entity is not a shape: ")
  43.     )
  44.   )
  45.   (setq data (entget shape))
  46.   (setq name (cdr (assoc 2 data))
  47.         scale(cdr (assoc 40 data))
  48.         width(cdr (assoc 41 data))
  49.         rangl(cdr (assoc 50 data))
  50.         insp (cdr (assoc 10 data))
  51.   )
  52.   (setq enext (entlast))
  53.   (setq shapedata (cdr (assoc name (GetMasterDefinitions))))
  54.   (setq osm (getvar "osmode"))
  55.   (DrawVecs (DataString->Points shapedata) insp)
  56.   (setvar "osmode" osm)
  57.   (setq sset (ssadd))
  58.   (while (setq enext (entnext enext))
  59.     (setq sset (ssadd enext sset))
  60.   )
  61.   (vl-cmdf "_rotate" sset "" insp (angtos rangl))
  62.   (vl-cmdf "_scale" sset "" insp scale)
  63.   (entdel shape)
  64.   (princ "\nDone")
  65.   (princ)
  66. )

  67. ;;; Put all shape file definitions into a single searchable data list
  68. (defun GetMasterDefinitions( / n shapefiles)
  69.   (setq shapefiles (GetShapeFiles) MasterDefs nil)
  70.   (foreach n shapefiles
  71.     (setq MasterDefs (append MasterDefs (getShapeDefs n)))
  72.   )
  73.   MasterDefs
  74. )

  75. ;;; get shape file definitions from style table
  76. (defun GetShapeFiles ( / shpfiles test)
  77.   (setq test (tblnext "style" t))
  78.   (while test
  79.     (if (=(cdr (assoc 70 test)) 1)
  80.       (setq shpfiles (append shpfiles (list (cdr (assoc 3 test)))))
  81.     )
  82.     (setq test (tblnext "style"))
  83.   )
  84.   shpfiles
  85. )

  86. ;;; readstream function courtesy of MP
  87. ;;; see post http://www.theswamp.org/index.php?topic=17465.msg210365#msg210365
  88. (defun _ReadStream ( path len / fso file stream result )

  89.     ;;  If the file is successful read the data is returned as
  90.     ;;  a string. Won't be tripped up by nulls, control chars
  91.     ;;  including ctrl z (eof marker). Pretty fast (feel free
  92.     ;;  to bench mark / compare to alternates).
  93.     ;;
  94.     ;;  If the caller wants the result as a list of byte values
  95.     ;;  simply use vl-string->list on the result:
  96.     ;;
  97.     ;;      (setq bytes
  98.     ;;          (if (setq stream (_ReadStream path len))
  99.     ;;              (vl-string->list stream)
  100.     ;;          )
  101.     ;;      )            
  102.     ;;
  103.     ;;  Arguments:
  104.     ;;
  105.     ;;      path  <duh>
  106.     ;;      len   Number of bytes to read. If non numeric, less
  107.     ;;            than 1 or greater than the number of bytes in
  108.     ;;            the file everything is returned.
  109.    
  110.     (vl-catch-all-apply
  111.        '(lambda ( / iomode format size )
  112.             (setq
  113.                 iomode   1 ;; 1 = read, 2 = write, 8 = append
  114.                 format   0 ;; 0 = ascii, -1 = unicode, -2 = system default
  115.                 fso      (vlax-create-object "Scripting.FileSystemObject")
  116.                 file     (vlax-invoke fso 'GetFile path)
  117.                 stream   (vlax-invoke fso 'OpenTextFile path iomode format)
  118.                 size     (vlax-get file 'Size)
  119.                 len      (if (and (numberp len) (< 0 len size)) (fix len) size)
  120.                 result   (vlax-invoke stream 'read len)
  121.             )
  122.             (vlax-invoke stream 'Close)
  123.         )
  124.     )
  125.     (if stream (vlax-release-object stream))
  126.     (if file (vlax-release-object file))
  127.     (if fso (vlax-release-object fso))
  128.     result
  129. )

  130. ;;; Get shapes from file(s)
  131. (defun GetShapeDefs(strPath / fResult intCount n offset ShapeDefs ShapeIndex TOC)
  132.   (setq strPath (findfile strPath))
  133.   (setq fResult (_ReadStream strPath -1))
  134.   (setq intCount (+(ascii (substr fresult 29 1))(*(ascii (substr fresult 30 1))256)))
  135.   (setq TOC (substr fresult 31 (* intCount 4)))
  136.   (setq offset 0)
  137.   (repeat intCount
  138.     (setq ShapeIndex (append ShapeIndex (list (cons (+(ascii (substr TOC (+ offset 1) 1))(*(ascii (substr TOC (+ offset 2) 1))256)) (+(ascii (substr TOC (+ offset 3) 1))(*(ascii (substr TOC (+ offset 4) 1))256))))))
  139.     (setq offset (+ offset 4))
  140.   )
  141.   (setq offset (1+ offset))
  142.   (foreach n ShapeIndex
  143.     (setq ShapeDefs (append ShapeDefs (list (ParseShapeInfo (substr fResult (+ 30 offset) (cdr n))))))
  144.     (setq offset (+ offset (cdr n)))
  145.   )
  146.   ShapeDefs
  147. )

  148. ;;; Parse the shape information string into usable information
  149. ;;; returns ("SHAPENAME" . "DATASTRING")
  150. (defun ParseShapeInfo (ShapeInfo / ndx ShapeName)
  151.   (setq ndx 1
  152.         ShapeName "")
  153.   (while (/= (ascii (substr ShapeInfo ndx 1)) 0)
  154.     (setq ShapeName (strcat ShapeName (substr ShapeInfo ndx 1)))
  155.     (setq ndx (1+ ndx))
  156.   )
  157.   (cons ShapeName (substr ShapeInfo (1+ ndx)(- (strlen ShapeInfo)(strlen ShapeName) 2)))
  158. )

  159. ;;; DataString->Points converts the datastring of the shape into 3dpoints
  160. ;;; for use in drawing the shape
  161. (defun DataString->Points (DataString / mfact penstat plist point testval xOffset yOffset)
  162.   (setq mfact 1.0
  163.         penstat "@")
  164.   (while (>(strlen DataString) 0)
  165.     (setq testVal (ascii (substr DataString 1 1)))
  166.     (cond
  167.       ((= testVal 1)(setq DataString (substr DataString 2) penstat "@")) ;Pen Down
  168.       ((= testVal 2)(setq DataString (substr DataString 2) penstat "")) ;Pen Up
  169.       ((= testVal 3)(setq mfact (/ mfact (ascii (substr DataString 2 1))) DataString (substr DataString 3))) ;Division factor follows
  170.       ((= testVal 4)(setq mfact (* mfact (ascii (substr DataString 2 1))) DataString (substr DataString 3))) ;Multiplication factor follows
  171.       ((= testVal 5)(setq DataString (substr DataString 2))) ;Push current location onto stack **currently ignored
  172.       ((= testVal 6)(setq DataString (substr DataString 2))) ;Pop current location from stack **currently ignored
  173.       ((= testVal 7)(setq DataString (substr DataString 2))) ;Draw subshape number given by next byte **currently ignored
  174.       ((= testVal 8)(setq point (list (* mfact (ascii(substr DataString 2 1)))(* mfact (ascii(substr DataString 3 1)))) DataString (substr DataString 4))) ;x-y displacement from next 2 bytes
  175.       ((= testVal 9)
  176.         (progn
  177.        (while (or (/= 0 (ascii (substr DataString 2 1)))(/= 0 (ascii (substr DataString 3 1))))
  178.          (setq xOffset(ascii(substr DataString 2 1))
  179.                yOffset(ascii(substr DataString 3 1))
  180.          )
  181.          (if (> xOffset 127)
  182.            (setq xOffset (- xOffset 256))
  183.          )
  184.          (if (> yOffset 127)
  185.            (setq yOffset (- yOffset 256))
  186.          )
  187.          (setq point (list (* mfact xOffset)(* mfact yOffset) penstat))
  188.          (setq plist (append plist (list point))
  189.                point nil)
  190.          (setq DataString (substr DataString 3))
  191.        )
  192.        (setq DataString (substr DataString 3))
  193.        )
  194.       )  ;x-y displacement from multiple bytes terminated by double null
  195.       ((= testVal 10)(setq point (ArcVector->ArcPoint (2HexVector (substr DataString 3 1))(ascii (substr DataString 2 1))) DataString (substr DataString 4))) ;Octant arc from next 2 bytes
  196.       ((= testVal 11)(setq DataString (substr DataString 7))) ;Fractional arc from next 5 bytes **currently ignored
  197.       ((= testVal 12)(setq DataString (substr DataString 5))) ;Arc from single x-y displacement and bulge - 3 bytes **currently ignored
  198.       ((= testVal 13)(setq DataString (substr DataString 2))) ;multiple arcs from x-y displacement and bulge data (multiple 3 byte segments terminated by a double null) **currently ignored
  199.       ((= testVal 14)(setq DataString (substr DataString 2))) ;Process next command only if vertical text **Applicable to text only
  200.       ( t (setq point (append (Vector->Point (2HexVector (substr DataString 1 1))) (list PenStat)) DataString (substr DataString 2)))
  201.     )
  202.     (if point
  203.       (setq plist (append plist (list point))
  204.             point nil)
  205.     )
  206.   )
  207.   plist
  208. )

  209. ;;; draw the vectors
  210. ;;; currently only handles lines
  211. ;;; and octant arcs
  212. (defun drawvecs(vecs inspoint / ep n sp prevpoint pt)
  213.   (setq prevpoint inspoint)
  214.   (foreach n vecs
  215.     (cond
  216.       ((= (caddr n) "")(setq prevpoint (NextPoint prevpoint n)))
  217.       ((= (caddr n) "@")
  218.        (progn
  219.         (setq pt (strcat (rtos (car prevpoint) 2 8)","(rtos (cadr prevpoint) 2 8)))
  220.         (vl-cmdf "line" pt (strcat "@"(rtos (car n) 2 8)","(rtos (cadr n) 2 8)) "")
  221.         (setq prevpoint (NextPoint prevpoint n))
  222.        )
  223.       )
  224.       (t (vl-cmdf "arc" prevpoint "c" (strcat "@" (rtos (car n) 2 8)","(rtos (cadr n) 2 8)) "a" (caddr n))
  225.          (setq ep (vlax-get (vlax-ename->vla-object (entlast)) 'Endpoint))
  226.          (setq sp (vlax-get (vlax-ename->vla-object (entlast)) 'Startpoint))
  227.          (if (equal sp (append prevpoint (list 0.0)) 0.0000001)
  228.            (setq prevpoint ep)
  229.            (setq prevpoint sp)
  230.          )  
  231.       )
  232.     )
  233.   )
  234. )

  235. ;;; advance the current point to the next point
  236. ;;; as determined by the offset
  237. (defun NextPoint (startpoint offset / newx newy newpoint)
  238.   (setq newx (+ (car startpoint)(car offset))
  239.         newy (+ (cadr startpoint)(cadr offset))
  240.   )
  241.   (setq newpoint (list newx newy))
  242.   newpoint
  243. )

  244. ;;; convert a char to a hex vector so it can be parsed
  245. ;;; according to the rules defining a shape
  246. (defun 2HexVector (character / ax bx highbit lowbit)
  247.   (setq ascval (ascii character))
  248.   (setq highbit (/ ascval 16))
  249.   (cond
  250.     ((= highbit 0)(setq ax "0"))
  251.     ((= highbit 1)(setq ax "1"))
  252.     ((= highbit 2)(setq ax "2"))
  253.     ((= highbit 3)(setq ax "3"))
  254.     ((= highbit 4)(setq ax "4"))
  255.     ((= highbit 5)(setq ax "5"))
  256.     ((= highbit 6)(setq ax "6"))
  257.     ((= highbit 7)(setq ax "7"))
  258.     ((= highbit 8)(setq ax "8"))
  259.     ((= highbit 9)(setq ax "9"))
  260.     ((= highbit 10)(setq ax "A"))
  261.     ((= highbit 11)(setq ax "B"))
  262.     ((= highbit 12)(setq ax "C"))
  263.     ((= highbit 13)(setq ax "D"))
  264.     ((= highbit 14)(setq ax "E"))
  265.     ((= highbit 15)(setq ax "F"))
  266.   )
  267.   (setq lowbit (- ascval (* highbit 16)))
  268.   (cond
  269.     ((= lowbit 0)(setq bx "0"))
  270.     ((= lowbit 1)(setq bx "1"))
  271.     ((= lowbit 2)(setq bx "2"))
  272.     ((= lowbit 3)(setq bx "3"))
  273.     ((= lowbit 4)(setq bx "4"))
  274.     ((= lowbit 5)(setq bx "5"))
  275.     ((= lowbit 6)(setq bx "6"))
  276.     ((= lowbit 7)(setq bx "7"))
  277.     ((= lowbit 8)(setq bx "8"))
  278.     ((= lowbit 9)(setq bx "9"))
  279.     ((= lowbit 10)(setq bx "A"))
  280.     ((= lowbit 11)(setq bx "B"))
  281.     ((= lowbit 12)(setq bx "C"))
  282.     ((= lowbit 13)(setq bx "D"))
  283.     ((= lowbit 14)(setq bx "E"))
  284.     ((= lowbit 15)(setq bx "F"))
  285.   )
  286.   (strcat "0" ax bx)
  287. )

  288. ;;; convert a vector to a point offset
  289. (defun Vector->Point (vector / ax ay highbit len lowbit)
  290.   (setq highbit (substr vector 2 1)
  291.         lowbit (substr vector 3 1)
  292.   )       
  293.   (cond
  294.     ((= highbit "0")(setq len 0))
  295.     ((= highbit "1")(setq len 1))
  296.     ((= highbit "2")(setq len 2))
  297.     ((= highbit "3")(setq len 3))
  298.     ((= highbit "4")(setq len 4))
  299.     ((= highbit "5")(setq len 5))
  300.     ((= highbit "6")(setq len 6))
  301.     ((= highbit "7")(setq len 7))
  302.     ((= highbit "8")(setq len 8))
  303.     ((= highbit "9")(setq len 9))
  304.     ((= highbit "A")(setq len 10))
  305.     ((= highbit "B")(setq len 11))
  306.     ((= highbit "C")(setq len 12))
  307.     ((= highbit "D")(setq len 13))
  308.     ((= highbit "E")(setq len 14))
  309.     ((= highbit "F")(setq len 15))
  310.   )
  311.   (cond
  312.     ((= lowbit "0")(setq ax len ay 0))
  313.     ((= lowbit "1")(setq ax len ay (* len 0.5)))
  314.     ((= lowbit "2")(setq ax len ay len))
  315.     ((= lowbit "3")(setq ax (* len 0.5) ay len))
  316.     ((= lowbit "4")(setq ax 0 ay len))
  317.     ((= lowbit "5")(setq ax (* len -0.5) ay len))
  318.     ((= lowbit "6")(setq ax (* len -1.0) ay len))
  319.     ((= lowbit "7")(setq ax (* len -1.0) ay (* len 0.5)))
  320.     ((= lowbit "8")(setq ax (* len -1.0) ay 0))
  321.     ((= lowbit "9")(setq ax (* len -1.0) ay (* len -0.5)))
  322.     ((= lowbit "A")(setq ax (* len -1.0) ay (* len -1.0)))
  323.     ((= lowbit "B")(setq ax (* len -0.5) ay (* len -1.0)))
  324.     ((= lowbit "C")(setq ax 0 ay (* len -1.0)))
  325.     ((= lowbit "D")(setq ax (* len 0.5) ay (* len -1.0)))
  326.     ((= lowbit "E")(setq ax len ay (* len -1.0)))
  327.     ((= lowbit "F")(setq ax len ay (* len -0.5)))
  328.   )
  329.   (list ax ay)
  330. )

  331. ;;; convert the arc vector data into a point offset
  332. (defun ArcVector->ArcPoint(vector radius / center dvec range start )
  333.   (setq start (substr vector 2 1))
  334.   (if (numberp (distof start))
  335.     (if (< (distof start) 8)
  336.       (setq dvec 1)
  337.       (setq dvec -1)
  338.     )
  339.     (setq dvec -1)
  340.   )  
  341.   (setq range (* dvec (* (distof (substr vector 3 1))45)))
  342.   (cond
  343.     ((or (= start "0")(= start "8"))(setq center (polar (list 1 1)(angtof "180") radius)))
  344.     ((or (= start "1")(= start "9"))(setq center (polar (list 1 1)(angtof "225") radius)))
  345.     ((or (= start "2")(= start "A"))(setq center (polar (list 1 1)(angtof "270") radius)))
  346.     ((or (= start "3")(= start "B"))(setq center (polar (list 1 1)(angtof "315") radius)))
  347.     ((or (= start "4")(= start "C"))(setq center (polar (list 1 1) 0 radius)))
  348.     ((or (= start "5")(= start "D"))(setq center (polar (list 1 1)(angtof "45") radius)))
  349.     ((or (= start "6")(= start "E"))(setq center (polar (list 1 1)(angtof "90") radius)))
  350.     ((or (= start "7")(= start "F"))(setq center (polar (list 1 1)(angtof "135") radius)))
  351.   )
  352.   (setq center (list (- (car center) 1.0)(- (cadr center) 1.0)))
  353.   (append center (list range))
  354. )
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 3199个

财富等级: 富可敌国

发表于 2016-12-12 17:29:07 | 显示全部楼层
Shape 是个嘛东西? 没有见识过
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 40个

财富等级: 招财进宝

发表于 2016-12-12 17:43:14 | 显示全部楼层

形文件.shx定义的形
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 6881个

财富等级: 富甲天下

发表于 2016-12-12 17:48:30 | 显示全部楼层
都是外文
看不明白啊
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 604个

财富等级: 财运亨通

发表于 2016-12-12 21:25:15 | 显示全部楼层
打开文件碰到shx提示,深恶痛绝,直接按忽略
不知这个能解决不?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 20个

财富等级: 恭喜发财

发表于 2016-12-12 21:56:36 | 显示全部楼层

自己写个程序,把没有定义的SHX替换成有的呗
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2025-9-27 14:18 , Processed in 0.384939 second(s), 38 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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