乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 39|回复: 19

[编程交流] 自动图案填充

[复制链接]

4

主题

15

帖子

11

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 10:20:35 | 显示全部楼层 |阅读模式
大家好,
 
已经开始使用lisps,可以看到很多可能性。
 
我们执行的一个重复命令是使用剖面线图案ASNI37在风管HA层上填充矩形(或闭合多段线),比例为32,角度为0。
 
这在我们的施工图上表示绝缘管道系统。
 
我想创建一个lisp,我可以简单地键入HH并选择对象,(围绕风管区域绘制)创建图案填充,然后删除对象。
 
我读过几篇关于创建图案填充的帖子,但我的autolisp知识非常基础,我需要一些帮助。
 
谢谢
 
戴夫
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 10:25:17 | 显示全部楼层
 
嗨Dave,
 
我在最近的一个线程上使用了这个程序,并对其进行了修改以满足您的需要。如果还需要修剪,请告诉我。
这段代码有一定的效果。
这是线程的链接。
http://www.cadtutor.net/forum/showthread.php?52876-创建-Ansi-31-Hatch-Linetype
 
以下是您的代码:
红色的默认值可以更改为适合。很抱歉粘贴后的格式很糟糕。
ANSI37.lsp
  1. ;/////////////////////////////////////////////////////////////////////////////////////////
  2. ;
  3. ; Start-Up.
  4. ;
  5. (defun C:ANSI37 (/ CL01 CL02 RAD# DEG# PT01 PT02 PT03 PT04 DLEN E01 CPS SUS HPRP HSCL HWID HANG LNAM LCLR LTYP)
  6. (ANSI37_SUS)
  7. (princ))
  8. (princ "\nANSI37.lsp loaded... Type ANSI37 to start.")
  9. ;
  10. ;/////////////////////////////////////////////////////////////////////////////////////////
  11. ;
  12. ; Save User Settings.
  13. ;
  14. (defun ANSI37_SUS ()
  15. (setq SUS_LST (list "cmdecho" "orthomode" "osmode" "blipmode" "angbase" "angdir" "aunits" "clayer")
  16.        SUS     (mapcar 'getvar SUS_LST)
  17.        TERR *error*
  18.       *error* ANSI37_ET)
  19. (ANSI37_MF)
  20. (princ))
  21. ;
  22. ;/////////////////////////////////////////////////////////////////////////////////////////
  23. ;
  24. ; Main Function.
  25. ;
  26. (defun ANSI37_MF ()
  27. [color=red] (or H:WID (setq H:WID 12))                                                            ;Defualt Hatch Width     = 12[/color]
  28. [color=red] (setq HPRP "ANSI37"                                                                   ;Default Hatch Pattern   = ANSI37[/color]
  29. [color=red]       HSCL 32                                                                         ;Default Hatch Scale     = 32[/color]
  30. [color=red]       HANG 180                                                                        ;Default Hatch Angle     = 0°[/color]
  31. [color=red]       LNAM "DUCT-HA"                                                                  ;Default Layer Name      = DUCT-HA[/color]
  32. [color=red]       LCLR 1                                                                          ;Default Layer Color     = 1 or RED[/color]
  33. [color=red]       LTYP "Continuous")                                                              ;Default Layer Linetype  = Continuous[/color]
  34. (setq H:WID                                                                           ;Set the hatch width
  35.    (cond                                                                               ;Condition
  36.      ((getint (strcat "\nSpecify hatch width. <"(itoa H:WID)">: ")))(T H:WID)))        ;Get the hatch width
  37. (setq HWID H:WID)                                                                     ;Set the Hatch Width
  38. (setvar "osmode" (nth 2 SUS))                                                         ;Turn on Saved User Snaps
  39. (setq CL01 (getpoint "\nSpecify first point along duct: "))                           ;Get the first point
  40. (while                                                                                ;While loop
  41.    (if (/= (setq CL02 (getpoint CL01 "\nSpecify next point along duct: ")) nil)        ;Get the next point, if the next point is nil, Go to the Loop Function
  42.      (progn                                                                            ;Then do the following
  43.        (ANSI37_CPS)                                                                    ;Go to Change Program Settings Function
  44.        (setq RAD# (angle CL01 CL02)                                                    ;Get the angle in radians
  45.              DEG# (ANSI37_RTD RAD#)                                                    ;Convert the radians to degrees
  46.              DLEN (distance CL01 CL02)                                                 ;Get the distance from first point to the next point
  47.              CL01 (trans CL01 1 0)                                                     ;Translate coordinate system
  48.              CL02 (trans CL02 1 0)                                                     ;Translate coordinate system
  49.              PT01 CL01                                                                 ;Calculate Point 01
  50.              PT02 (polar PT01 (ANSI37_DTR (+ DEG#  0))  DLEN)                          ;Calculate Point 02
  51.              PT03 (polar PT01 (ANSI37_DTR (+ DEG# 270)) HWID)                          ;Calculate Point 03
  52.              PT04 (polar PT02 (ANSI37_DTR (+ DEG# 270)) HWID))                         ;Calculate Point 04
  53.        (ANSI37_ML LNAM LCLR LTYP)                                                      ;Set layer name, color, linetype
  54.        (setvar "clayer" LNAM)                                                          ;Set layer current
  55.        (setvar "osmode" 0)                                                             ;Turn off snaps
  56.        (command "._pline" PT01 PT02 PT04 PT03 "C")                                     ;Start Polyline command for hatch perimeter
  57.        (setq E01 (entlast))                                                            ;Set polyline as last entity to E01
  58.        (command "._-bhatch" "_a" "_a" "_y" "" "_p" HPRP HSCL HANG "_s" "_l" "" "")     ;Start Hatch command and fill the polyline
  59.        (command "._erase" E01 "")                                                      ;Erase entity E01 or the polyline perimeter
  60.        (setvar "osmode" (nth 2 SUS))                                                   ;Turn on Saved User Snaps
  61.        (setq CL01 CL02))))                                                             ;Set the next point to the first point
  62. (ANSI37_LF)                                                                           ;Go to the Loop Function
  63. (princ))                                                                              ;Exit quietly
  64. ;
  65. ;/////////////////////////////////////////////////////////////////////////////////////////
  66. ;
  67. ; Loop Function.
  68. ;
  69. (defun ANSI37_LF ()
  70. (setq LOOP "Y")                                                                       ;Default Loop Y or Yes                                                
  71. (initget "Y N")                                                                       ;Set the keywords
  72. (setq LOOP                                                                            ;Set variable LOOP
  73.    (cond                                                                               ;Condition
  74.      ((getkword (strcat "\nContinue? [Y or N] <"LOOP">: ")))(T LOOP)))                 ;Do you wish to continue? Y or N
  75. (cond                                                                                 ;Condition
  76.    ((= LOOP "N")(ANSI37_RUS))                                                            ;If N or No was selected go to ANSI37_RUS, Restore User Settings function
  77.    ((= LOOP "Y")(ANSI37_MF)))                                                            ;If Y or Yes was selected go to HLIN_MF, Main Function
  78. (princ))                                                                              ;Exit quietly
  79. ;
  80. ;/////////////////////////////////////////////////////////////////////////////////////////
  81. ;
  82. ; Degrees To Radians.
  83. ;
  84. (defun ANSI37_DTR (DEG#)(* pi (/ DEG# 180.0)))                                            ;Convert degrees to radians
  85. ;
  86. ;/////////////////////////////////////////////////////////////////////////////////////////
  87. ;
  88. ; Radians To Degrees.
  89. ;
  90. (defun ANSI37_RTD (RAD#)(* 180.0 (/ RAD# pi)))                                            ;Convert radiand to degrees
  91. ;
  92. ;/////////////////////////////////////////////////////////////////////////////////////////
  93. ;
  94. ; Make Layer.
  95. ;
  96. (defun ANSI37_ML (L:NAM L:CLR L:TYP)
  97. (if (null (tblsearch "layer" L:NAM))
  98.    (entmake
  99.      (list
  100.        (cons   0 "LAYER")
  101.        (cons 100 "AcDbSymbolTableRecord")
  102.        (cons 100 "AcDbLayerTableRecord")
  103.        (cons   2  L:NAM)
  104.        (cons  70  0)
  105.        (cons  62  L:CLR)
  106.        (cons   6  L:TYP)
  107.        (cons 290  1))))
  108. (princ))
  109. (princ)
  110. ;
  111. ;/////////////////////////////////////////////////////////////////////////////////////////
  112. ;
  113. ; Change Program Settings.
  114. ;
  115. (defun ANSI37_CPS ()
  116. (setq CPS (list 0 1 0 0 0 0))
  117. (mapcar (function setvar)(list "cmdecho" "orthomode" "blipmode" "angbase" "angdir" "aunits") CPS)
  118. (princ))
  119. (princ)
  120. ;
  121. ;
  122. ;/////////////////////////////////////////////////////////////////////////////////////////
  123. ;
  124. ; Restore User Settings.
  125. ;
  126. (defun ANSI37_RUS ()
  127. (setq *error* TERR)
  128. (if SUS (mapcar 'setvar SUS_LST SUS))
  129. (princ "\nANSI37.lsp has completed successfully and will now restore your settings.")
  130. (princ))
  131. (princ)
  132. ;
  133. ;/////////////////////////////////////////////////////////////////////////////////////////
  134. ;
  135. ; Error Trap.
  136. ;
  137. (defun ANSI37_ET (ERRORMSG)
  138. (command nil nil nil)
  139. (if (not (member ERRORMSG '("console break" "Function cancelled")))
  140.    (princ (strcat "\nError:" ERRORMSG)))
  141. (if SUS (mapcar 'setvar SUS_LST SUS))
  142. (princ "\nANSI37.lsp has encountered a user error!")
  143. (princ "\nProgram will now restore your settings and exit.")
  144. (terpri)
  145. (setq *error* TERR)
  146. (princ))
  147. (princ)
  148. ;
  149. ;/////////////////////////////////////////////////////////////////////////////////////////
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:29:50 | 显示全部楼层
也许是这样?
 
  1. (defun c:HH ( / *error* _StartUndo _EndUndo doc spc ent hobj hl )
  2. (vl-load-com)
  3. ;; © Lee Mac 2010
  4. (setq hl "Duct-HA") ;; Hatch Layer
  5. (defun *error* ( msg )
  6.    (and doc (_EndUndo doc))
  7.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  8.        (princ (strcat "\n** Error: " msg " **")))
  9.    (princ)
  10. )
  11. (defun _StartUndo ( doc ) (_EndUndo doc)
  12.    (vla-StartUndoMark doc)
  13. )
  14. (defun _EndUndo ( doc )
  15.    (if (= 8 (logand 8 (getvar 'UNDOCTL)))
  16.      (vla-EndUndoMark doc)
  17.    )
  18. )
  19. (LM:ActiveSpace 'doc 'spc)
  20. (or (tblsearch "LAYER" hl)
  21.      (vla-add (vla-get-layers doc) hl)
  22. )
  23. (if (setq ent (LM:Selectif (lambda ( x ) (vlax-curve-isClosed x)) entsel "\nSelect Object to Hatch: "))
  24.    (progn
  25.      
  26.      (_StartUndo doc)
  27.      
  28.      (if
  29.        (not
  30.          (vl-catch-all-error-p
  31.            (setq hobj
  32.              (vl-catch-all-apply 'vla-AddHatch
  33.                (list spc acHatchPatternTypePredefined "ANSI37" :vlax-false 0)
  34.              )
  35.            )
  36.          )
  37.        )
  38.        (progn
  39.          (vlax-invoke hobj 'AppendOuterLoop (list (vlax-ename->vla-object ent)))
  40.          (mapcar
  41.            '(lambda ( p v ) (vlax-put-property hobj p v))
  42.            '(Layer AssociativeHatch PatternAngle PatternScale) (list hl :vlax-false 0.0 32.0)
  43.          )
  44.          (vla-Evaluate hobj)
  45.          (entdel ent)
  46.        )
  47.        (princ (strcat "\n** Error: " (vl-catch-all-error-message hobj) " **"))
  48.      )
  49.      (_EndUndo doc)
  50.    )
  51. )
  52. (princ)
  53. )
  54. ;;---------------------=={ Select if }==----------------------;;
  55. ;;                                                            ;;
  56. ;;  Continuous selection prompts until the predicate function ;;
  57. ;;  foo is validated                                          ;;
  58. ;;------------------------------------------------------------;;
  59. ;;  Author: Lee McDonnell, 2010                               ;;
  60. ;;                                                            ;;
  61. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  62. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  63. ;;------------------------------------------------------------;;
  64. ;;  Arguments:                                                ;;
  65. ;;  foo - optional predicate function taking ename argument   ;;
  66. ;;  fun - selection function to invoke                        ;;
  67. ;;  str - prompt string                                       ;;
  68. ;;------------------------------------------------------------;;
  69. ;;  Returns:  selected entity ename if successful, else nil   ;;
  70. ;;------------------------------------------------------------;;
  71. (defun LM:Selectif ( foo fun str / e )
  72. ;; © Lee Mac 2010
  73. (while
  74.    (progn (setq e (car (fun str)))      
  75.      (cond
  76.        ( (eq 'ENAME (type e))
  77.          (if (and foo (not (foo e)))
  78.            (princ "\n** Invalid Object Selected **")
  79.          )
  80.        )
  81.      )
  82.    )
  83. )
  84. e
  85. )
  86. ;;--------------------=={ ActiveSpace }==---------------------;;
  87. ;;                                                            ;;
  88. ;;  Retrieves pointers to the Active Document and Space       ;;
  89. ;;------------------------------------------------------------;;
  90. ;;  Author: Lee McDonnell, 2010                               ;;
  91. ;;                                                            ;;
  92. ;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
  93. ;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
  94. ;;------------------------------------------------------------;;
  95. ;;  Arguments:                                                ;;
  96. ;;  *doc - quoted symbol other than *doc                      ;;
  97. ;;  *spc - quoted symbol other than *spc                      ;;
  98. ;;------------------------------------------------------------;;
  99. (defun LM:ActiveSpace ( *doc *spc )
  100. ;; © Lee Mac 2010
  101. (set *spc
  102.    (if
  103.      (or
  104.        (eq AcModelSpace
  105.          (vla-get-ActiveSpace
  106.            (set *doc
  107.              (vla-get-ActiveDocument
  108.                (vlax-get-acad-object)
  109.              )
  110.            )
  111.          )
  112.        )
  113.        (eq :vlax-true (vla-get-MSpace (eval *doc)))
  114.      )
  115.      (vla-get-ModelSpace (eval *doc))
  116.      (vla-get-PaperSpace (eval *doc))
  117.    )
  118. )
  119. )
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 10:32:43 | 显示全部楼层
这无疑是更好和更简单的使用。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:33:34 | 显示全部楼层
 
感谢Buzzard,这是我第一次使用VL创建图案填充,在这样做时需要注意一些事情(详细信息见VLIDE帮助文件),所以我想试试。
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 10:37:20 | 显示全部楼层
我几乎可以发誓你已经做了类似的事情。我就是记不起那根线了。无论如何,它仍然需要一个层函数,但我想我们不能放弃存储。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:40:51 | 显示全部楼层
 
哦,是的-忘了图层。。。
回复

使用道具 举报

4

主题

15

帖子

11

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 10:44:13 | 显示全部楼层
谢谢大家的反馈。将公布最终结果。
 
戴夫
回复

使用道具 举报

4

主题

15

帖子

11

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 10:48:16 | 显示全部楼层
 
谢谢Buzzard。
 
这个lisp可以实现我想要的,除了我希望它完全填充矩形,而不是在其周围放一条边。
 
基本上,启动命令,选择现有的矩形或闭合多段线(一些风管是weired形状)并用图案填充。
 
戴夫
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 10:49:42 | 显示全部楼层
 
我的编辑速度有点快,所以我希望有一些怪癖。我建议你试试李的节目。我相信他把你想要的东西都放进去了。顺便说一句,我的程序正在请求风管宽度,以将图案填充设置为,并且不留下矩形。所以我不确定你到底是什么意思,但李的节目是你最好的选择。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-6 21:18 , Processed in 1.597261 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表