明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2764|回复: 4

等待你优化:复杂线型打散炸开(源码)

[复制链接]
发表于 2012-12-23 21:44 | 显示全部楼层 |阅读模式
本帖最后由 NetBee 于 2012-12-23 22:03 编辑

由于有时需要复制图形给打印店,又担心没有线型文件,会变样。
所以急需将线型打散,所以根据et工具的文字打散改了几行代码,能打散了,但必须在ET工具下运行。
由于没有时间继续了。

哪位搞个脱ET版?
  1. (defun NBTF_VXVariant->Lst2 (v)
  2.    (cond
  3.      ((= (type v) 'variant)
  4.        (NBTF_VXVariant->Lst (variant-value v)))
  5.      ((= (type v) 'safearray)
  6.        (mapcar 'NBTF_VXVariant->Lst2 (safearray-value v)))
  7.      (T v)
  8.    )
  9. )

  10. (defun NBTF_VXEntBox (ent / obj maxpt minpt)
  11.   (setq obj (vlax-ename->vla-object ent))
  12.   (vla-GetBoundingBox obj 'minpt 'maxpt)
  13.   (list (NBTF_VXVariant->Lst2 minpt)(NBTF_VXVariant->Lst2 maxpt))
  14. )


  15. (defun c:NBTC_PLexp (/ fun_setini fun_setclose grplst getgname blknm FLTR GLST GDICT SS VIEW UPLFT TMPFIL TBX
  16.                    TMPFIL CNT PT1 PT2 ENT TXT TXTYP PTLST ZM LOCKED GNAM vpna vplocked)

  17. ; --------------------- GROUP LIST FUNCTION ----------------------
  18. ;   This function will return a list of all the group names in the
  19. ;   drawing and their entity names in the form:
  20. ;   ((<ename1> . <name1>) ... (<enamex> . <namex>))
  21. ; ----------------------------------------------------------------

  22.   (defun nbtf-txtexp-grplst (/ GRP ITM NAM ENT GLST)

  23.     (setq GRP  (dictsearch (namedobjdict) "ACAD_GROUP"))
  24.     (while (setq ITM (car GRP))       ; While edata item is available
  25.       (if (= (car ITM) 3)             ; if the item is a group name
  26.         (setq NAM (cdr ITM)           ; get the name
  27.               GRP (cdr GRP)           ; shorten the edata
  28.               ITM (car GRP)           ; get the next item
  29.               ENT (cdr ITM)           ; which is the ename
  30.               GRP (cdr GRP)           ; shorten the edata
  31.               GLST                    ; store the ename and name
  32.                   (if GLST
  33.                     (append GLST (list (cons ENT NAM)))
  34.                     (list (cons ENT NAM))
  35.                   )
  36.         )
  37.         (setq GRP (cdr GRP))          ; else shorten the edata
  38.       )
  39.     )
  40.     GLST                              ; return the list
  41.   )

  42. ; ------------------- GET GROUP NAME FUNCTION --------------------
  43. ;   This function returns a list of all the group names in GLST
  44. ;   where ENT is a member. The list has the same form as GLST
  45. ; ----------------------------------------------------------------

  46.   (defun nbtf-txtexp-getgname (ENT GLST / GRP GDATA NAM NLST)
  47.     (if (and GLST (listp GLST))
  48.       (progn
  49.         (foreach GRP GLST
  50.           (setq GDATA (entget (car GRP)))
  51.           (foreach ITM GDATA                   ; step through the edata
  52.             (if (and
  53.                   (= (car ITM) 340)            ; if the item is a entity name
  54.                   (eq (setq NAM (cdr ITM)) ENT) ; and the ename being looked for
  55.                 )
  56.               (setq NLST                       ; store the ename and name
  57.                       (if NLST
  58.                         (append NLST (list (cons (car GRP) (cdr GRP))))
  59.                         (list (cons (car GRP) (cdr GRP)))
  60.                       )
  61.               )
  62.             )
  63.           )
  64.         )
  65.       )
  66.     )
  67.     NLST
  68.   )
  69. ( fun_setini)
  70. ; ----------------------------------------------------------------
  71. ;                          主程序
  72. ; ----------------------------------------------------------------

  73.   (if (and                                                ; Are we in plan view?
  74.         (equal (car (getvar "viewdir")) 0 0.00001)
  75.         (equal (cadr (getvar "viewdir")) 0 0.00001)
  76.         (> (caddr (getvar "viewdir")) 0)
  77.       )

  78.     (progn

  79.       (prompt "\n选择要分解的复杂线型: ")

  80.       (Setq FLTR    '((-4 . "<AND")
  81.                         (-4 . "<OR")                      ; filter for 复合线
  82.                           (0 . "*POLYLINE")
  83.                         (-4 . "OR>")
  84.                         (-4 . "<NOT")
  85.                           (102 . "{ACAD_REACTORS")        ; and not leader text
  86.                         (-4 . "NOT>")
  87.                       (-4 . "AND>")
  88.                      )
  89.             GLST     (nbtf-txtexp-grplst)                             ; Get all the groups in drawing
  90.             GDICT    (if GLST
  91.                        (dictsearch (namedobjdict) "ACAD_GROUP")
  92.                      )
  93.             SS       (ssget  FLTR)
  94.             CNT      0
  95.       )
  96.       ;; filter out the locked layers
  97.       (if SS
  98.         (setq SS (car (bns_ss_mod SS 1 T)))
  99.       ) ;if

  100.       ;; if we have anything left
  101.       (if SS
  102.         (progn
  103.           (setq CNT 0)                                 ; Reset counter
  104.           (while (setq ENT (ssname SS CNT))            ; step through each object in set

  105.             (and
  106.               GLST                                     ; if groups are present in the drawing
  107.               (setq GNAM (nbtf-txtexp-getgname ENT GLST))          ; and the text item is in one or more
  108.               (foreach GRP GNAM                        ; step through those groups
  109.                 (command "_.-group" "_r"               ; and remove the text item
  110.                   (cdr GRP) ENT ""
  111.                 )
  112.               )
  113.             )

  114.             (setq TBX (NBTF_VXEntBox ENT))   ; get textbox points

  115.             (setq TBX (mapcar '(lambda (x)
  116.                                  (trans x 1 0)         ; convert the points to WCS
  117.                                )
  118.                         TBX
  119.                       )
  120.             )

  121.             (setq PTLST (append PTLST TBX))            ; Build list of bounding box
  122.                                                        ; points for text items selected

  123.             (setq CNT (1+ CNT))                        ; get the next text item
  124.           ); while

  125.           (setq PTLST (mapcar '(lambda (x)
  126.                                  (trans x 0 1)         ; convert all the points
  127.                                )                       ; to the current ucs
  128.                       PTLST
  129.                     )
  130.           )

  131.           (if (setq ZM (acet-geom-zoom-for-select PTLST))          ; If current view does not contain
  132.             (progn                                     ; all bounding box points
  133.               (setq ZM
  134.                 (list
  135.                   (list (- (caar ZM) (acet-geom-pixel-unit))     ; increase zoom area by
  136.                         (- (cadar ZM) (acet-geom-pixel-unit))    ; one pixel width to
  137.                         (caddar ZM)                    ; sure nothing will be lost
  138.                   )
  139.                   (list (+ (caadr ZM) (acet-geom-pixel-unit))
  140.                         (+ (cadadr ZM) (acet-geom-pixel-unit))
  141.                         (caddr (cadr zm))
  142.                   )
  143.                 )
  144.               )
  145.               (if (setq vpna (acet-currentviewport-ename))
  146.                   (setq vplocked (acet-viewport-lock-set vpna nil))
  147.               );if
  148.               (command "_.zoom" "_w" (car ZM) (cadr ZM))  ; zoom to include text objects
  149.             )
  150.           )

  151.           (setq VIEW     (acet-geom-view-points)
  152.                 TMPFIL   (strcat (getvar "tempprefix") "PLexp.wmf")
  153.                 PT1      (acet-geom-midpoint (car view) (cadr view))
  154.                 PT2      (list (car PT1) (cadadr VIEW))
  155.           )

  156.           (if (acet-layer-locked (getvar "clayer"))       ; if current layer is locked
  157.             (progn
  158.               (command "_.layer" "_unl" (getvar "clayer") "")  ; unlock it
  159.               (setq LOCKED T)
  160.             )
  161.           )

  162.           (command ;;"_.mirror" SS "" PT1 PT2 "_y"
  163.                    "_.WMFOUT" TMPFIL SS "")

  164.           (if (findfile tmpfil)                           ; Does WMF file exist?
  165.             (progn
  166.               (command "_.ERASE" SS "")                   ; erase the orignal text
  167.               (setq ss (acet-wmfin TMPFIL))               ; insert the WMF file
  168.               ;;(command "_.mirror" ss "" PT1 PT2 "_y")
  169.             ) ;progn
  170.           ) ;if


  171.           (if LOCKED
  172.             (command "_.layer" "_lock" (getvar "clayer") "") ; relock if needed
  173.           ) ;if

  174.           (if ZM (command "_.zoom" "_p"))              ; Restore original view if needed
  175.           (if vplocked
  176.               (acet-viewport-lock-set vpna T) ;re-lock the viewport if needed.
  177.           );if
  178.           (prompt (acet-str-format "\n%1 个复杂线型对象已经被分解为直线。"  CNT))
  179.           (prompt "\n该直线对象已经被放在图层 0。")
  180.         )
  181.       )
  182.     )
  183.     (prompt "\n视图需在平面 (0 0 1)。")
  184.   );if equal
  185.   ;;(acet-error-restore)                                  ; Retsore values
  186.   (princ)
  187. )


  188. (princ)
"觉得好,就打赏"
还没有人打赏,支持一下
 楼主| 发表于 2012-12-23 21:50 | 显示全部楼层
由于只是针对打印,所有不需要太碎,我记得可以打散为复合线,而不是很多的小线段的。
发表于 2012-12-24 10:02 | 显示全部楼层
你干嘛不转成PDF的?
 楼主| 发表于 2012-12-28 08:57 | 显示全部楼层
转换为pdf的话,分辨率有问题。
过高文件太大
过小打印出来看不清。
发表于 2019-10-9 01:33 | 显示全部楼层
本帖最后由 caoyin 于 2019-10-9 01:37 编辑

1.线型是随DWG文件保存的,无需.lin支持文件。(包含形或字体的复杂线型需要.shx支持)
2.线型打散无需导出wmf,dxf组码已经包含详细的定义信息,直接读取组码即可用直线(复杂线型包括形或字体)模拟出来

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

本版积分规则

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

GMT+8, 2024-4-28 13:14 , Processed in 0.447282 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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