乐筑天下

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

[编程交流] 任何绘制线条的函数

[复制链接]

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 10:57:56 | 显示全部楼层 |阅读模式
你好
是否有任何函数或方法可以让您有机会连续绘制双线和多线。
 
或者像entmake之类的东西。。。。。如果可能,请致电
 
非常感谢
塔瓦特
回复

使用道具 举报

15

主题

209

帖子

121

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-6 11:02:44 | 显示全部楼层
我想这就是你要找的。
 
  1. (defun DB_LINE (WallWidth / Point1 Point2 StartPt Start1 Start2 Line1 Line2 Line3 Line4 Int2 WallLayer WallLine)
  2. ;; Set the correct layer
  3. (setq WallLayer "0")
  4. (setq WallLine "BYLAYER")
  5. ;; Get first point
  6. (setq Point1 (getpoint "\n Define first point: "))
  7. ;; Define first point as startpoint
  8. (setq        StartPt Point1)
  9. ;; Get next point
  10. (setq        Point2 (getpoint Point1 "\n Define next point: "))
  11. ;; start to create the wall
  12. (setq        Line1 (vlax-ename->vla-object (STDLIB_CREATE_LINE Point1 Point2 WallLayer WallLine 256)))
  13. ;; Defin the first line as the strting line
  14. (setq        Start1 Line1)
  15. ;; Create second line
  16. (setq        Line2 (car (vlax-invoke Line1 'offset WallWidth)))
  17. ;; Define the second line as the second start line
  18. (setq        Start2 Line2)
  19. ;; Reset the first point to the second point
  20. (setq        Point1 Point2)
  21. ;; While we are creating lines
  22. (while
  23.         ;; Meet these criteria
  24.         (progn
  25.                 ;; Watch to close
  26.                 (initget "Close")
  27.                 ;; get next point
  28.                 (setq Point2 (getpoint Point1 "\n Define next point: "))
  29.                 ;; Check to see if it is a point list
  30.                 (= (type Point2) 'LIST)
  31.         )
  32.         ;; Create next section of wall
  33.         (setq Line3 (vlax-ename->vla-object (STDLIB_CREATE_LINE Point1 Point2 WallLayer WallLine 256)))
  34.         (setq Line4 (car (vlax-invoke Line3 'offset WallWidth)))
  35.         ;; Get the intersection of the first section and the second section
  36.         (setq Int2 (vlax-invoke Line2 'intersectwith Line4 acExtendBoth))
  37.         ;; Chang the end points to meet
  38.         (vlax-put Line2 'endpoint Int2)
  39.         (vlax-put Line4 'startpoint Int2)
  40.         ;; Reset the lines
  41.         (setq Line1 Line3)
  42.         (setq Line2 Line4)
  43.         ;; Reset the point
  44.         (setq Point1 Point2)
  45. )
  46. ;; If the user want to close the line
  47. (if (= Point2 "Close")
  48.         (progn
  49.                 ;; Create last section of wall
  50.                 (setq Line3 (vlax-ename->vla-object (STDLIB_CREATE_LINE Point1 StartPt WallLayer WallLine 256)))
  51.                 (setq Line4 (car (vlax-invoke Line3 'offset WallWidth)))
  52.                 ;; Get the intersection of the first section and the second section
  53.                 (setq Int2 (vlax-invoke Line2 'intersectwith Line4 acExtendBoth))
  54.                 ;; Reset the lines
  55.                 (vlax-put Line2 'endpoint Int2)
  56.                 (vlax-put Line4 'startpoint Int2)                       
  57.                 ;; Now close it ....
  58.                 ;; Get the intersection of the last section and the first section
  59.                 (setq Int2 (vlax-invoke Start2 'intersectwith Line4 acExtendBoth))
  60.                 ;; Chang the end points to meet
  61.                 (vlax-put Line4 'endpoint Int2)
  62.                 (vlax-put Start2 'startpoint Int2)
  63.         )
  64. )
  65. )
  66. ;;; ------------------------------------------------------------------------
  67. ;;;    STDLIB_CREATE_LINE.LSP
  68. ;;;
  69. ;;;    Copyright © December, 2008
  70. ;;;    Timothy G. Spangler
  71. ;;;
  72. ;;;    Permission to use, copy, modify, and distribute this software
  73. ;;;    for any purpose and without fee is hereby granted, provided
  74. ;;;    that the above copyright notice appears in all copies and
  75. ;;;    that both that copyright notice and the limited warranty and
  76. ;;;    restricted rights notice below appear in all supporting
  77. ;;;    documentation.
  78. ;;;
  79. ;;;    STDLIB_CREATE_LINE
  80. ;;;
  81. ;;;                 Description:
  82. ;;;                        Called from a menu pulldown or rightclick menu
  83. ;;;                * (STDLIB_CREATE_LINE <STARTPOINT> <ENDPOINT> <LAYER> <LINETYPE> <COLOR> )
  84. ;;;                <STARTPOINT>        =        LIST                =        List of 2D / 3D points
  85. ;;;                <ENDPOINT>                =        LIST                =        List of 2D / 3D points
  86. ;;;                <LAYER>                                =        STRING        =        Valid layer name
  87. ;;;                <LINETYPE>                =        STRING        =        Valid linetype (loaded)
  88. ;;;                <COLOR>                                = REAL                = Valid color number
  89. ;;;
  90. ;;;                        Returns:
  91. ;;;                                Ename of created line
  92. ;;;
  93. ;;; ------------------------------------------------------------------------
  94. ;;; MAIN FUNCTION ;;;;;;;;;;;;;;;;;;;;;;;;;
  95. (defun STDLIB_CREATE_LINE (StartPoint EndPoint Layer Linetype Color / LineList)
  96. (setq LineList
  97.         (list
  98.                 (cons 0 "LINE")
  99.                 (cons 100 "AcDbEntity")
  100.                 (cons 100 "AcDbLine")
  101.                 (cons 6 Linetype)
  102.                 (cons 8 Layer)
  103.                 (cons 10 StartPoint)
  104.                 (cons 11 EndPoint)
  105.                 (cons 39 0.0)
  106.                 (cons 62 Color)
  107.                 (cons 210 (list 0.0 0.0 1.0))
  108.         )
  109. )
  110. (entmakex LineList)
  111. )
  112. (princ)
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 11:05:29 | 显示全部楼层
太好了,蒂姆先生
 
我希望我能处理这些函数,我认为处理entmake对我来说有点困难。
 
您是否有任何Lisp实现您在中提供的entmake作为示例。
 
非常感谢你。
塔瓦特
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 11:09:44 | 显示全部楼层
这是Tims代码,添加了一个测试函数。
加载并键入DB以启动。
 
  1. (defun C:DB ()
  2. (or WW (setq WW 4.0))
  3. (setq WW$ (rtos WW 2 1))
  4. (setq WW (cond ((getreaL (strcat "\nSpecify wall width: <"WW$">: ")))(T WW)))
  5. (DB_LINE WW)
  6. (princ))
  7. (defun DB_LINE (WallWidth / Point1 Point2 StartPt Start1 Start2 Line1 Line2 Line3 Line4 Int2 WallLayer WallLine)
  8. ;; Set the correct layer
  9. (setq WallLayer "0")
  10. (setq WallLine "BYLAYER")
  11. ;; Get first point
  12. (setq Point1 (getpoint "\n Define first point: "))
  13. ;; Define first point as startpoint
  14. (setq        StartPt Point1)
  15. ;; Get next point
  16. (setq        Point2 (getpoint Point1 "\n Define next point: "))
  17. ;; start to create the wall
  18. (setq        Line1 (vlax-ename->vla-object (STDLIB_CREATE_LINE Point1 Point2 WallLayer WallLine 256)))
  19. ;; Defin the first line as the strting line
  20. (setq        Start1 Line1)
  21. ;; Create second line
  22. (setq        Line2 (car (vlax-invoke Line1 'offset WallWidth)))
  23. ;; Define the second line as the second start line
  24. (setq        Start2 Line2)
  25. ;; Reset the first point to the second point
  26. (setq        Point1 Point2)
  27. ;; While we are creating lines
  28. (while
  29.         ;; Meet these criteria
  30.         (progn
  31.                 ;; Watch to close
  32.                 (initget "Close")
  33.                 ;; get next point
  34.                 (setq Point2 (getpoint Point1 "\n Define next point: "))
  35.                 ;; Check to see if it is a point list
  36.                 (= (type Point2) 'LIST)
  37.         )
  38.         ;; Create next section of wall
  39.         (setq Line3 (vlax-ename->vla-object (STDLIB_CREATE_LINE Point1 Point2 WallLayer WallLine 256)))
  40.         (setq Line4 (car (vlax-invoke Line3 'offset WallWidth)))
  41.         ;; Get the intersection of the first section and the second section
  42.         (setq Int2 (vlax-invoke Line2 'intersectwith Line4 acExtendBoth))
  43.         ;; Chang the end points to meet
  44.         (vlax-put Line2 'endpoint Int2)
  45.         (vlax-put Line4 'startpoint Int2)
  46.         ;; Reset the lines
  47.         (setq Line1 Line3)
  48.         (setq Line2 Line4)
  49.         ;; Reset the point
  50.         (setq Point1 Point2)
  51. )
  52. ;; If the user want to close the line
  53. (if (= Point2 "Close")
  54.         (progn
  55.                 ;; Create last section of wall
  56.                 (setq Line3 (vlax-ename->vla-object (STDLIB_CREATE_LINE Point1 StartPt WallLayer WallLine 256)))
  57.                 (setq Line4 (car (vlax-invoke Line3 'offset WallWidth)))
  58.                 ;; Get the intersection of the first section and the second section
  59.                 (setq Int2 (vlax-invoke Line2 'intersectwith Line4 acExtendBoth))
  60.                 ;; Reset the lines
  61.                 (vlax-put Line2 'endpoint Int2)
  62.                 (vlax-put Line4 'startpoint Int2)                       
  63.                 ;; Now close it ....
  64.                 ;; Get the intersection of the last section and the first section
  65.                 (setq Int2 (vlax-invoke Start2 'intersectwith Line4 acExtendBoth))
  66.                 ;; Chang the end points to meet
  67.                 (vlax-put Line4 'endpoint Int2)
  68.                 (vlax-put Start2 'startpoint Int2)
  69.         )
  70. )
  71. )
  72. ;;; ------------------------------------------------------------------------
  73. ;;;    STDLIB_CREATE_LINE.LSP
  74. ;;;
  75. ;;;    Copyright © December, 2008
  76. ;;;    Timothy G. Spangler
  77. ;;;
  78. ;;;    Permission to use, copy, modify, and distribute this software
  79. ;;;    for any purpose and without fee is hereby granted, provided
  80. ;;;    that the above copyright notice appears in all copies and
  81. ;;;    that both that copyright notice and the limited warranty and
  82. ;;;    restricted rights notice below appear in all supporting
  83. ;;;    documentation.
  84. ;;;
  85. ;;;    STDLIB_CREATE_LINE
  86. ;;;
  87. ;;;                 Description:
  88. ;;;                        Called from a menu pulldown or rightclick menu
  89. ;;;                * (STDLIB_CREATE_LINE <STARTPOINT> <ENDPOINT> <LAYER> <LINETYPE> <COLOR> )
  90. ;;;                <STARTPOINT>        =        LIST                =        List of 2D / 3D points
  91. ;;;                <ENDPOINT>                =        LIST                =        List of 2D / 3D points
  92. ;;;                <LAYER>                                =        STRING        =        Valid layer name
  93. ;;;                <LINETYPE>                =        STRING        =        Valid linetype (loaded)
  94. ;;;                <COLOR>                                = REAL                = Valid color number
  95. ;;;
  96. ;;;                        Returns:
  97. ;;;                                Ename of created line
  98. ;;;
  99. ;;; ------------------------------------------------------------------------
  100. ;;; MAIN FUNCTION ;;;;;;;;;;;;;;;;;;;;;;;;;
  101. (defun STDLIB_CREATE_LINE (StartPoint EndPoint Layer Linetype Color / LineList)
  102. (setq LineList
  103.         (list
  104.                 (cons 0 "LINE")
  105.                 (cons 100 "AcDbEntity")
  106.                 (cons 100 "AcDbLine")
  107.                 (cons 6 Linetype)
  108.                 (cons 8 Layer)
  109.                 (cons 10 StartPoint)
  110.                 (cons 11 EndPoint)
  111.                 (cons 39 0.0)
  112.                 (cons 62 Color)
  113.                 (cons 210 (list 0.0 0.0 1.0))
  114.         )
  115. )
  116. (entmakex LineList)
  117. )
  118. (princ)
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 11:12:21 | 显示全部楼层
谢谢你,巴扎德先生。
 
我很高兴再次收到你的来信,这非常有帮助。
 
我的野兽问候,
 
塔瓦特
回复

使用道具 举报

15

主题

209

帖子

121

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-6 11:15:56 | 显示全部楼层
 
下面是代码中调用STDLIB\u CREATE\u行的行
 
  1. (STDLIB_CREATE_LINE Point1 Point2 WallLayer WallLine 256)
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 11:17:33 | 显示全部楼层
 
只需注意,参数WallWidth需要提供一个值,在本例中为WW。
 
 
  1. (defun C:DB ()
  2. (or WW (setq WW 4.0))
  3. (setq WW$ (rtos WW 2 1))
  4. (setq WW (cond ((getreaL (strcat "\nSpecify wall width: <"WW$">: ")))(T WW)))
  5. (DB_LINE [color="Red"]WW[/color])
  6. (princ))
  7. (defun DB_LINE ([color="red"]WallWidth[/color] / Point1 Point2 StartPt Start1 Start2 Line1 Line2 Line3 Line4 Int2 WallLayer WallLine)

 
此行调用局部函数DB\u line,提供的参数为WW。
 
  1. (DB_LINE WW)

 
如果没有提供的值,则会出现参数太少的错误。
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 11:20:12 | 显示全部楼层
 
好极了
我一直在尝试,但这让我失望;
  1. (defun C:Dline ()
  2.   (setq pl (getpoint"\nSpecify first point:"))
  3. (DB_LINE)
  4. (princ))

 
你很好地说明了问题的核心。
热烈问候,
塔瓦特
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-6 11:23:27 | 显示全部楼层
Tim先生
 
非常感谢你的帮助。
 
由于您的简短提示,我无法很好地理解您的观点,此外,我的Autolisp中级水平。
 
再次感谢。。。。。。。。
塔瓦特
回复

使用道具 举报

15

主题

209

帖子

121

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-6 11:29:04 | 显示全部楼层
 
希望这对你有帮助。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-4 22:17 , Processed in 0.610415 second(s), 72 queries .

© 2020-2025 乐筑天下

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