明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 6616|回复: 16

3D->2D转三维消隐线框为二维

  [复制链接]
发表于 2010-8-31 21:14:00 | 显示全部楼层 |阅读模式
前阵子一直迷茫,要写个将3D消隐图轮廓线转为2D,后来参阅了国外一篇文章,利用AutoCAD自身命令实现,较为繁琐,将它写出来供大家方便使用。
  1. (defun C:3d2d (/ laylst lay ss)
  2.   (vl-load-com)  
  3.   (vl-catch-all-apply 'vl-cmdf (list "UCS" "N" "V" "" "LAYOUT" "N" "Test" "" ))
  4.   (setvar "CTAB" "Test")
  5.   (setq ss (ssget "x"))
  6.   (vl-catch-all-apply 'vl-cmdf (list "ERASE" ss "" "MVIEW" "F" "" "MSPACE" ""))
  7.   (setq ss (ssget "x"))
  8.   (vl-catch-all-apply 'vl-cmdf (list "SolProf" ss "" "Y" "Y" "Y" ""))
  9.   (setq laylst (xyp-get-tblnext "LAYER"))
  10.   (setq lay (last (vl-remove-if-not
  11.       (function (lambda (x)
  12.     (wcmatch x "PV*")
  13.          )
  14.       )
  15.       laylst
  16.     )
  17.      )
  18.   )
  19.   (setvar "CTAB" "Model")
  20.   (vl-cmdf "UCS" "N" "V" "")
  21.   (setq ss (ssget "x" (list (cons 8 lay))))      
  22.   (vl-file-delete "C:\\TEST.DWG");_路径您可以更改设置,也可以改成发送到剪贴板
  23.   (vl-cmdf "wblock" "c:\\TEST.dwg" "" '(0 0 0) ss "")
  24.   (foreach a laylst
  25.     (if (wcmatch a "P[VH]-*")
  26.       (vl-cmdf "ERASE" (ssget "X" (list (cons 8 a))) "")
  27.       )
  28.     )
  29.   (vl-catch-all-apply 'vl-cmdf (list "layout" "D" "TEST" "" "UCS" "W" ""))
  30.   (vl-Catch-All-Apply
  31.     '(lambda ()
  32.        (vla-Remove
  33.   (vla-GetExtensionDictionary
  34.     (vla-Get-Layers
  35.       (vla-Get-ActiveDocument
  36.         (vlax-Get-Acad-Object)
  37.       )
  38.     )
  39.   )
  40.   "ACAD_LAYERFILTERS"
  41.        )
  42.      )
  43.   );清理图层过滤器  
  44.   (command "_.PURGE" "a" "*" "N");这里您可以选择执行  
  45.   (command "UCS"  "W" "")
  46.   (princ)
  47.   )
  48. (princ "\n3D实体Hidden线框转2D线框程序,命令3D2D, 高山流水 2010.08")



发表于 2010-8-31 21:22:00 | 显示全部楼层
程序在cad2011上测试未通过
 楼主| 发表于 2010-8-31 21:23:00 | 显示全部楼层
<img src="E:\lispbox\gifgifgif\3d2d.gif"/>
发表于 2010-9-1 07:00:00 | 显示全部楼层

错误: no function definition: XYP-GET-TBLNEXT

在2008上通不过

发表于 2010-9-1 12:12:00 | 显示全部楼层

命令: ; 错误: no function definition: XYP-GET-TBLNEXT

06也不行,这是哪里的函数啊

发表于 2010-9-1 18:16:00 | 显示全部楼层

是否要下載通用函數?

 楼主| 发表于 2010-9-1 19:46:00 | 显示全部楼层

xyp-get-tblnext这是个获取图层名称列表的函数,您可以自己写下;也可以到xyp1964.ys168.com下载XYP.lib

2009测试没问题,2006没有测试,应该可以

 

 楼主| 发表于 2010-9-1 19:50:00 | 显示全部楼层
ACAD2011去除图层反应器清理代码应该可以
  1. (defun C:3d2d (/ laylst lay ss)   (vl-load-com)     (vl-catch-all-apply 'vl-cmdf (list "UCS" "N" "V" "" "LAYOUT" "N" "Test" "" ))   (setvar "CTAB" "Test")   (setq ss (ssget "x"))   (vl-catch-all-apply 'vl-cmdf (list "ERASE" ss "" "MVIEW" "F" "" "MSPACE" ""))   (setq ss (ssget "x"))   (vl-catch-all-apply 'vl-cmdf (list "SolProf" ss "" "Y" "Y" "Y" ""))   (setq laylst (xyp-get-tblnext "LAYER"))   (setq lay (last (vl-remove-if-not       (function (lambda (x)     (wcmatch x "PV*")          )       )       laylst     )      )   )   (setvar "CTAB" "Model")   (vl-cmdf "UCS" "N" "V" "")   (setq ss (ssget "x" (list (cons 8 lay))))         (vl-file-delete "C:\\TEST.DWG");_路径您可以更改设置,也可以改成发送到剪贴板   (vl-cmdf "wblock" "c:\\TEST.dwg" "" '(0 0 0) ss "")   (foreach a laylst     (if (wcmatch a "P[VH]-*")       (vl-cmdf "ERASE" (ssget "X" (list (cons 8 a))) "")       )     )   (vl-catch-all-apply 'vl-cmdf (list "layout" "D" "TEST" "" "UCS" "W" ""))     (command "_.PURGE" "a" "*" "N");这里您可以选择执行     (command "UCS"  "W" "")   (princ)   )
发表于 2010-9-2 06:11:00 | 显示全部楼层
希望楼主把xyp-get-tblnext写出来加进去,谢谢!
发表于 2010-9-2 23:25:00 | 显示全部楼层
本帖最后由 作者 于 2010-9-3 23:40:40 编辑

改了一下,能用了,谢谢分享。
  1. (defun c:3d2d(/ laylst lay ss) ;3D转2D,并复制 ;from 高山流水 2010.08
  2. (vl-load-com)
  3. (setvar "cmdecho" 0)
  4. (vl-catch-all-apply 'vl-cmdf (list "UCS" "N" "V" "LAYOUT" "N" "Test"))
  5. (setvar "CTAB" "Test")
  6. (setq ss (ssget "x"))
  7. (vl-catch-all-apply 'vl-cmdf (list "ERASE" ss "" "MVIEW" "F" "MSPACE"))
  8. (setq ss (ssget "x"))
  9. (if (not SolProf_bak)  ;这里改了一下,谢谢龙龙仔版主提醒。
  10.   (progn
  11.     (setq SolProf_bak T)
  12.     (vl-catch-all-apply 'vl-cmdf (list "SolProf" ss "" "Y" "Y" "N"))
  13.   )
  14.   (SolProf ss "" "Y" "Y" "N")
  15. )
  16. (setq laylst (get-layer))
  17. (setq lay (last (vl-remove-if-not (function (lambda (x) (wcmatch x "PV*"))) laylst)))
  18. (setvar "CTAB" "Model")
  19. (vl-cmdf "UCS" "N" "V")
  20. (setq ss (ssget "x" (list (cons 8 lay))))
  21. ;(vl-file-delete "C:\\TEST.DWG") ;可以更改路径,也可以改成发送到剪贴板
  22. ;(vl-cmdf "wblock" "C:\\TEST.dwg" "" '(0 0 0) ss "")
  23. (vl-cmdf "_copyclip" ss "")
  24. (foreach a laylst
  25. (if (wcmatch a "P[VH]-*")
  26. (vl-cmdf "ERASE" (ssget "X" (list (cons 8 a))) "")
  27. )
  28. )
  29. (vl-catch-all-apply 'vl-cmdf (list "layout" "D" "TEST" "UCS" ""))
  30. (command "_.PURGE" "a" "*" "N") ;这里您可以选择执行
  31. (command "UCS" "")
  32. (princ "\n3D转换2D完成,2D线框已复制,粘贴即可。")
  33. (princ)
  34. )
  35. (defun get-layer(/ lay layer layname) ;获得图层列表
  36. (setq layer nil lay (tblnext "LAYER" T))
  37. (while (/= lay nil)
  38. (setq layname (cdr (assoc 2 lay))
  39.         layer (cons layname layer)
  40.          lay (tblnext "LAYER")
  41. )
  42. )
  43. (setq layer (ACAD_Strlsort layer))
  44. )
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-16 16:25 , Processed in 0.191471 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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