明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 853|回复: 1

【求助】下面网址中的程序有问题,可否帮忙修改一下

[复制链接]
发表于 2021-8-20 21:25:23 | 显示全部楼层 |阅读模式
2明经币
 楼主| 发表于 2021-8-20 21:27:04 | 显示全部楼层
  1. ;;;************************ centerPline.LSP ***********************;;;
  2. ;;; ;;;
  3. ;;; Centerline between two polyline ;;;
  4. ;;; ;;;
  5. ;;; author: Gian Paolo Cattaneo ;;;
  6. ;;; ;;;
  7. ;;; version: 1.0 - 21.12.2013 ;;;
  8. ;;; ;;;
  9. ;;;****************************************************************;;;

  10. (defun c:CPL ( / *error* Loft_n Loft_p Loft_u Loft_v :e1 :e2
  11. e1 e2 p1 p2 D_off EL e1o e2o L1 L2 EL1 E_new
  12. *pl* E_join pa pb e_del results rip)

  13. (defun *error* ( msg )
  14. (command "_.undo" "_end")
  15. (if Loft_n (setvar 'loftnormals Loft_n))
  16. (if Loft_p (setvar 'loftparam Loft_p))
  17. (if Loft_u (setvar 'surfu Loft_u))
  18. (if Loft_v (setvar 'surfv Loft_v))
  19. (if pl_type (setvar 'plinetype pl_type))
  20. (setvar 'cmdecho cmd)

  21. (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  22. (princ (strcat "\nError: " msg))
  23. )
  24. (princ)
  25. )

  26. (setq cmd (getvar 'cmdecho))
  27. (setvar 'cmdecho 0)
  28. (command "_.undo" "_begin")

  29. (if (null ETmsg) (check_ET))
  30. (check_ucs)
  31. (check_view)
  32. (check_ver)

  33. (setq Loft_n (getvar 'loftnormals))
  34. (setq Loft_p (getvar 'loftparam))
  35. (setq Loft_u (getvar 'surfu))
  36. (setq Loft_v (getvar 'surfv))
  37. (setq pl_type (getvar 'plinetype))

  38. (setvar 'loftnormals 0)
  39. (setvar 'loftparam 7)
  40. (setvar 'surfu 0)
  41. (setvar 'surfv 0)
  42. (if (= 0 (getvar 'plinetype)) (setvar 'plinetype 1))

  43. (if (and
  44. (setq :e1 ( "\nSelect First Polyline"))
  45. (setq p1 (cadr :e1))
  46. (setq :e1 (car :e1))
  47. (not (redraw :e1 3))
  48. (setq :e2 ( "\nSelect Second Polyline"))
  49. (setq p2 (cadr :e2))
  50. (setq :e2 (car :e2))
  51. )
  52. (progn
  53. (redraw :e1 4)
  54. (check_elev)
  55. (check_normal)
  56. (setq e1 (entmakex (cdr (entget :e1))))
  57. (setq e2 (entmakex (cdr (entget :e2))))
  58. (setq D_off (* (Max (MaxDist e1 e2) (MaxDist e2 e1)) 0.53))

  59. (setq EL (entlast))
  60. (command "_offset" D_off e1 "_non" p2 "")
  61. (setq e1o (entlast))
  62. (check_offset)

  63. (setq EL (entlast))
  64. (command "_offset" D_off e2 "_non" p1 "")
  65. (setq e2o (entlast))
  66. (check_offset)

  67. (command "_move" e1o e2o "" "_non" "0,0,0" "_non" (list 0.0 0.0 (* D_off 0.5)))

  68. (command "_loft" e1 e1o "" "")
  69. (setq L1 (entlast))
  70. (command "_loft" e2 e2o "" "")
  71. (setq L2 (entlast))

  72. (setq EL (entlast) EL1 EL)

  73. (command "_intersect" L1 L2 "")

  74. (mapcar
  75. '(lambda (x)
  76. (if (not (vlax-erased-p x)) (entdel x))
  77. )
  78. (list e1o e2o e1 e2 L1 L2)
  79. )

  80. (if (> (sslength (setq E_new (e_next EL "SS"))) 0)
  81. (progn
  82. (if :ET:
  83. (acet-flatn E_new nil)
  84. (progn
  85. (command "_move" E_new "" "_non" "0,0,0" "_non" "0,0,1e99")
  86. (command "_move" E_new "" "_non" "0,0,0" "_non" "0,0,-1e99")
  87. )
  88. )
  89. (setq E_join (e_next EL1 "LS"))

  90. (if (= "LINE" (cdr (assoc 0 (entget (car E_join)))))
  91. (progn
  92. (setq pa (trans (cdr (assoc 10 (entget (car E_join)))) 0 1))
  93. (setq pb (trans (cdr (assoc 11 (entget (car E_join)))) 0 1))
  94. (command "_pline" "_non" pa "_non" pb "")
  95. (setq E_join (subst (entlast) (setq e_del (car E_join)) E_join))
  96. (entdel e_del)
  97. )
  98. )
  99. (command "_.join")
  100. (apply 'command E_join)
  101. (command "")
  102. (setq results t)
  103. )
  104. )
  105. )
  106. )
  107. (setvar 'loftnormals Loft_n)
  108. (setvar 'loftparam Loft_p)
  109. (setvar 'surfu Loft_u)
  110. (setvar 'surfv Loft_v)
  111. (setvar 'plinetype pl_type)
  112. (command "_.undo" "_end")
  113. (setvar 'cmdecho cmd)
  114. (prompt "\n ") (prompt "\n ")(prompt "\n ")
  115. (if results (prompt (strcat "\nCenterline created " (if :ET: "(Polyline)." "(Spline)."))))
  116. (princ)
  117. )

  118. ;****************************************************************************

  119. (defun check_ET ()
  120. (if (member "acetutil.arx" (arx))
  121. (progn
  122. (or acet-flatn (load "FLATTENSUP.LSP"))
  123. (setq :ET: t)
  124. )
  125. (progn
  126. (setq :ET: nil)
  127. (alert
  128. (strcat
  129. "Express Tools are not installed."
  130. "\nIf there are curves the centerline is drawn with a spline."
  131. )
  132. )
  133. (setq ETmsg t)
  134. )
  135. )
  136. )

  137. ;****************************************************************************

  138. (defun check_ucs ()
  139. (or
  140. (and
  141. (zerop (caddr (getvar 'ucsxdir)))
  142. (zerop (caddr (getvar 'ucsydir)))
  143. )
  144. (progn
  145. (alert "UCS not normal to the WCS")
  146. (exit)
  147. )
  148. )
  149. )

  150. ;****************************************************************************

  151. (defun check_view ()
  152. (or
  153. (and
  154. (zerop (car (getvar 'viewdir)))
  155. (zerop (cadr (getvar 'viewdir)))
  156. (> (caddr (getvar 'viewdir)) 0)
  157. )
  158. (progn
  159. (alert "View needs to be in plan (0 0 1)")
  160. (exit)
  161. )
  162. )
  163. )

  164. ;****************************************************************************

  165. (defun check_ver ()
  166. (if (< (atoi (substr (ver) 13)) 2011)
  167. (progn
  168. (alert "This routine require AutoCAD 2011 or higher.")
  169. (exit)
  170. )
  171. )
  172. )

  173. ;****************************************************************************

  174. (defun ( / *poly* *esel* *p*)
  175. (while (not *poly*)
  176. (setvar "errno" 0)
  177. (setq *esel* (entsel ))
  178. (setq *poly* (car *esel*))
  179. (setq *p* (cadr *esel*))
  180. (if (= 7 (getvar 'errno))
  181. (alert "No objects selected")
  182. )
  183. (if (= 'ename (type *poly*))
  184. (cond
  185. ( (null (wcmatch (cdr (assoc 0 (entget *poly*))) "LWPOLYLINE"))
  186. (alert "Invalid selection, the object is not a LWPOLYLINE.")
  187. (setq *poly* nil)
  188. )
  189. ( (= 1 (logand 1 (cdr (assoc 70 (entget *poly*)))))
  190. (alert "Invalid selection, the polyline is not open.")
  191. (setq *poly* nil)
  192. )
  193. )
  194. )
  195. )
  196. (list *poly* *p*)
  197. )

  198. ;****************************************************************************

  199. (defun check_elev ()
  200. (if
  201. (not
  202. (equal
  203. (cdr (assoc 38 (entget :e1)))
  204. (cdr (assoc 38 (entget :e2)))
  205. 1e-6
  206. )
  207. )
  208. (progn
  209. (alert "Polylines have different elevation.")
  210. (exit)
  211. )
  212. )
  213. )

  214. ;****************************************************************************

  215. (defun check_normal ()
  216. (if
  217. (or
  218. (not (equal (cdr (assoc 210 (entget :e1))) '(0.0 0.0 1.0) ))
  219. (not (equal (cdr (assoc 210 (entget :e2))) '(0.0 0.0 1.0) ))
  220. )
  221. (progn
  222. (alert "Polyline is not normal to the WCS.")
  223. (exit)
  224. )
  225. )
  226. )

  227. ;****************************************************************************

  228. (defun e_next (entL mode / next)
  229. (if (= mode "SS") (setq next (ssadd)))
  230. (if (/= entL (entlast))
  231. (while (setq entL (entnext entL))
  232. (if (entget entL)
  233. (cond
  234. ( (= mode "LS") (setq next (cons entL next)) )
  235. ( (= mode "SS") (setq next (ssadd entL next)) )
  236. )
  237. )
  238. )
  239. )
  240. next
  241. )

  242. ;****************************************************************************

  243. (defun check_offset ( / o_del)
  244. (if rip (setq rip (1+ rip)) (setq rip 1))
  245. (if (> (length (setq o_del (e_next EL "LS"))) 1)
  246. (progn
  247. (entdel e1)
  248. (entdel e2)
  249. (if (= rip 2) (entdel e1o))
  250. (mapcar
  251. '(lambda (x)
  252. (if (not (vlax-erased-p x)) (entdel x))
  253. )
  254. o_del
  255. )
  256. (alert
  257. (strcat
  258. "Modeling failed."
  259. "\nTry to split the polylines into more portions."
  260. )
  261. )
  262. (exit)
  263. )
  264. )
  265. )

  266. ;****************************************************************************

  267. (defun MaxDist (ent1 ent2 / :step De1 :div p_step :D Dmax)
  268. (setq :step (/ (setq De1 (vlax-curve-getDistAtParam ent1 (vlax-curve-getEndParam ent1))) 500))
  269. (setq :div :step)
  270. (setq Dmax 0.00)
  271. (while ( :D Dmax) (setq Dmax :D))
  272. (setq :div (+ :div :step))
  273. )
  274. Dmax
  275. )

  276. ;****************************************************************************

  277. (vl-load-com)

  278. (prompt "\n ") (prompt "\n ")
  279. (princ "\nCenterline between two polyline - by Gian Paolo Cattaneo")
  280. (princ "\ncenterPline.LSP loaded ............... Type "CPL" to run ")
  281. (princ)
  282. (c:cpl)
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-17 00:37 , Processed in 0.153666 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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