乐筑天下

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

[编程交流] 帮助使用简单的Autolisp pr

[复制链接]

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 07:42:55 | 显示全部楼层
别再发照片了你让我的头更疼了
 
我认为我不理解的部分是如何将三维点转换为二维点。。。。。
我能想到的唯一一件事是,当一个三维点被转换成一维的二维对象时,需要的是你们想要表达的东西。你可以画一条从(xy)到(xz)的线。假设你有一个点在(3.00 2.00 2.00)和一个图,其中正Y=Z,负Y=Y
 
  1. Z
  2. |
  3. |
  4. |      P1 (3.00 2.00)
  5. |
  6. ---------------X
  7. |
  8. |      P2 (3.00 2.00)
  9. |
  10. |
  11. Y

 
绘制一条线P1>P2,从2个点(0D)创建一条线(1D)。
 
但现在的问题是,如何在图上的两个给定点之间画一条线?然后我们将进入下一维度更高的0D(点)1D(线)2D(闭合形状)?
 
对于下一个示例,假设我们在(3.00 2.00 2.00)和(5.00 4.00 3.00)处有一个点。它会像下面这样吗?
 
  1. Z
  2. |              P2
  3. |
  4. |      P1
  5. |
  6. ---------------X
  7. |
  8. |      P4
  9. |              P3
  10. |
  11. Y  

 
绘制线P1>P2>P3>P4>P1,创建闭合形状。
 
如果这是您想要使用的:
 
  1. (defun c:ADefXYZ (/ pointA pointB Ax Ay Az Bx By Bz)
  2. (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
  3. (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
  4. (setq Startpoint (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
  5. (setq Xoff (nth 0 Startpoint));;selects the 1st variable in the list
  6. (setq Yoff (nth 1 Startpoint));;selects the 2nd variable in the list
  7. (setq Zoff (nth 2 Startpoint));;selects the 3rd variable in the list
  8. (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
  9. (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
  10. (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
  11. (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
  12. (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
  13. (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
  14. (setq p1 (list (+ Ax Xoff) (+ (* -1 Ay) Yoff)));; finds coords based on startpoint offset
  15. (setq p2 (list (+ Ax Xoff) (+ Az Yoff)));; finds coords based on startpoint offset
  16. (setq p3 (list (+ Bx Xoff) (+ Bz Yoff)));; finds coords based on startpoint offset
  17. (setq p4 (list (+ Bx Xoff) (+ (* -1 By) Yoff)));; finds coords based on startpoint offset
  18. (entmake (list (cons 0 "LINE") ;; Creates a Line
  19.          (cons 10 P1)
  20.          (cons 11 P2)
  21.          ))
  22. (entmake (list (cons 0 "LINE") ;; Creates a Line
  23.          (cons 10 P2)
  24.          (cons 11 P3)
  25.          ))
  26. (entmake (list (cons 0 "LINE") ;; Creates a Line
  27.          (cons 10 P3)
  28.          (cons 11 P4)
  29.          ))
  30. (entmake (list (cons 0 "LINE") ;; Creates a Line
  31.          (cons 10 P4)
  32.          (cons 11 P1)
  33.          ))
  34. )

 
 
***注意,这是基于当前UCS坐标的,如果UCS距离当前点10k单位,则x、y和z将偏离图表
 
这张图片是它将做什么的示例(不添加引线)
 

                               
登录/注册后可看大图
回复

使用道具 举报

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 07:43:14 | 显示全部楼层
 
我从不喜欢回忆
cadr caddr等我只使用N
(汽车xyz)=(第n个0 xyz)
(cadr xyz)=(第n个1 xyz)
(caddr xyz)=(第n个2 xyz)
 
我不记得是否有一个命令来做一个数字的倒数,但我只使用(*-1(nth2xyz)),基本上是-1*Z
回复

使用道具 举报

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 07:48:28 | 显示全部楼层
我知道这让人困惑,但这是程序应该做的:
 
点P和T投影到两个平面上,因此它成为4个点。我们从来没有真正绘制三维空间,只是在坐标系中。
 
点P(x,y,z)分解为2个点,坐标为:
P1(x,y,0)
P2(x,-z,0)
 
另一点T(x1,y1,z1)也
T1(x1,y1,0)
T2(x1,-z1,0)
 
然后我可以画两行:
L1(P1,T1)
L2(P2,T2)
回复

使用道具 举报

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 07:52:27 | 显示全部楼层
不确定Z是向上还是向下,所以只需删除一个你不想要的部分。
 
  1. (defun c:ADefXYZ (/ pointA pointB Ax Ay Az Bx By Bz)
  2. (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
  3. (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
  4. (setq Startpoint (getpoint "\nSelect Point to start flaten: "));;Asks user to specify point where 3D points are converted to 2D
  5. (setq Xoff (nth 0 Startpoint));;selects the 1st variable in the list
  6. (setq Yoff (nth 1 Startpoint));;selects the 2nd variable in the list
  7. (setq Zoff (nth 2 Startpoint));;selects the 3rd variable in the list
  8. (setq Ax (nth 0 PointA)) ;;selects the 1st variable in the list pointA
  9. (setq Ay (nth 1 PointA)) ;;selects the 2nd variable in the list pointA
  10. (setq Az (nth 2 PointA)) ;;selects the 3rd variable in the list pointA
  11. (setq Bx (nth 0 PointB)) ;;selects the 1st variable in the list pointB
  12. (setq By (nth 1 PointB)) ;;selects the 2nd variable in the list pointB
  13. (setq Bz (nth 2 PointB)) ;;selects the 3rd variable in the list pointB
  14. ;;if Z is down keep here
  15. (setq p1 (list (+ Ax Xoff) (+ Ay Yoff)));; finds coords based on startpoint offset
  16. (setq p2 (list (+ Ax Xoff) (+ (* -1 Az) Yoff)));; finds coords based on startpoint offset
  17. (setq T1 (list (+ Bx Xoff) (+ By Yoff)));; finds coords based on startpoint offset
  18. (setq T2 (list (+ Bx Xoff) (+ (* -1 Bz) Yoff)));; finds coords based on startpoint offset
  19. ;;if Z is down to here
  20. ;;if Z is up keep here
  21. (setq p1 (list (+ Ax Xoff) (+ (* -1 Ay) Yoff)));; finds coords based on startpoint offset
  22. (setq p2 (list (+ Ax Xoff) (+ Az Yoff)));; finds coords based on startpoint offset
  23. (setq T1 (list (+ Bx Xoff) (+ (* -1 By) Yoff)));; finds coords based on startpoint offset
  24. (setq T2 (list (+ Bx Xoff) (+ Bz Yoff)));; finds coords based on startpoint offset
  25. ;;if Z is up to here
  26. (entmake (list (cons 0 "LINE") ;; Creates a Line
  27.          (cons 10 P1)
  28.          (cons 11 T1)
  29.          ))
  30. (entmake (list (cons 0 "LINE") ;; Creates a Line
  31.          (cons 10 P2)
  32.          (cons 11 T2)
  33.          ))
  34. )

 
为什么你第一次就不能这么说呢
 
这段代码的结果看起来与上面相同,只是没有连接坐标之间的垂直线
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:53:15 | 显示全部楼层
仅供参考:要对值求反:
 
  1. _$ (setq x 10)
  2. 10
  3. _$ (- x)
  4. -10
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 07:58:20 | 显示全部楼层
真奇怪,不是吗<如果只向减号函数发送一个参数,则第一个参数有一个隐含的0。
 
至于如何更改列表中的项目,通常不会在lisp中进行更改。您只需要重新创建列表。在某些情况下,如关联列表(如DXF代码。数据对),您可以将subst与assoc一起使用。但使用subst基本上可以用一个项目替换整个列表中的新项目-例如。
  1. (subst 2 1 '(1 2 3 1 2 3 1 2 3)) ;Returns (2 2 3 2 2 3 2 2 3)

 
您可能想看看ReplaceNth函数:http://www.theswamp.org/index.php?topic=41680.0
 
虽然对于这些要点列表,我不想麻烦。简单地做这样的事情并不太难:
  1. ;; Say originalPoint = (X Y Z)
  2. (setq newPoint1 (list (car originalPoint) (cadr originalPoint) 0.0)) ; (X Y 0)
  3. (setq newPoint2 (list (car originalPoint) (- (caddr originalPoint)) 0.0)) ; (X -Z 0)
回复

使用道具 举报

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 08:01:32 | 显示全部楼层
谢谢大家的帮助!我根据帖子写下了我想要的东西。现在看起来是这样的:
 
  1. (defun c:DrawAB ( / pointA pointB Axx Ayy Azz Byy Bzz)
  2. (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
  3. (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
  4. (setq Axx (nth 0 PointA))                         ;;selects the 1st variable in the list pointA
  5. (setq Ayy (nth 1 PointA))                         ;;selects the 2nd variable in the list pointA
  6. (setq Azz (nth 2 PointA))                         ;;selects the 3rd variable in the list pointA
  7. (setq Bxx (nth 0 PointB))                         ;;selects the 1st variable in the list pointB
  8. (setq Byy (nth 1 PointB))                         ;;selects the 2nd variable in the list pointB
  9. (setq Bzz (nth 2 PointB))                        ;;selects the 3rd variable in the list pointB
  10. (setq P1 (list (* Axx -1) (* -1 Ayy)))        ;;sets coords for p on plane (x-y)
  11. (setq P2 (list (* Axx -1) Azz))                ;;sets coords for p on plane (x-z)
  12. (setq T1 (list (* Bxx -1) (* -1 Byy)))        ;;sets coords for T on plane (x-y)
  13. (setq T2 (list (* Bxx -1) Bzz))                ;;sets coords for T on plane (x-z)
  14. (command "line" P1 T1 "")                        ;;draws the line on plane (x-y)
  15. (command "line" P2 T2 "")                        ;;draws the line on plane (x-z)
  16. (command "insert" "tA1" P1 1 1 0)                ;;inserts the mark for P on plane (x-y)
  17. (command "insert" "tA2" P2 1 1 0)                ;;inserts the mark for P on plane (x-z)
  18. (command "insert" "tb1" T1 1 1 0)                ;;inserts the mark for T on plane (x-y)
  19. (command "insert" "tb2" T2 1 1 0)                ;;inserts the mark for T on plane (x-z)
  20. (princ)
  21. )

 
我现在去掉了“从原点的偏移”部分,因为我正在尽可能地保持基本,现在将保持原始世界UCS上的所有内容,包括轴方向(否定值的原因)。一旦绘图变得更高级,我将进一步研究它,因此仍然感谢未来的提醒。
 
我想用“xline”替换“line”,但每次都会出错(块没有插入到正确的位置,线不会引用2个点,而只是一个坐标)。关于扭曲值的xline命令,有什么我应该知道的吗?
 
干杯
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 08:04:08 | 显示全部楼层
任何时候,只要使用(命令)调用并仅提供x和y值,就有可能出现不稳定的结果。它应该默认为当前sysvar“ELEVATION”值。但是,根据捕捉设置、ucs值等,没有真正好的方法可以预测准确的结果。您可以在点输入中添加“_non”,但这不是gaurntee-David
回复

使用道具 举报

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 08:06:13 | 显示全部楼层
好的,我已经试着把Z输入为0.0,但是xline仍然给我schizo结果,而基线每次都能可靠地工作。因此,我决定将生成的行扩展到预定义的矩形边缘,而不是用作打印边距。到目前为止,我认为我已经将直线和矩形重命名为VLA对象,但现在有一个全新的VLA命令谱需要理解:P
 
有人能给我演示一下如何延长VLA线的模型吗?
此外,是否有方法输入X坐标并接收具有该坐标的线上的点?
 
现在我的代码是这样的:
  1. (vl-load-com)
  2. ;;********************************************************************************************
  3. (defun c:frame ( / )                                ;;Draw the frame for the entire drawing
  4. (setq corner1 (list -15.5 15 0))
  5. (setq corner3 (list 5.5 -14 0))
  6. (command "rectangle" corner1 corner3)
  7. (setq F1 (entlast))
  8. (setq FrameO(vlax-ename->vla-object F1))
  9. )
  10. ;;********************************************************************************************
  11. ;;Define the coordinates of point A
  12. (defun c:defA ( / )                               
  13. (setq pointA (getpoint "\nSpecify Point A: "));;Asks user to specify point
  14. (setq Axx (nth 0 PointA))                         ;;selects the 1st variable in the list pointA
  15. (setq Ayy (nth 1 PointA))                         ;;selects the 2nd variable in the list pointA
  16. (setq Azz (nth 2 PointA))                         ;;selects the 3rd variable in the list pointA
  17. (setq A1 (list (* Axx -1) (* -1 Ayy) 0.0))        ;;sets coords for p on plane (x-y)
  18. (setq A2 (list (* Axx -1) Azz 0.0))                ;;sets coords for p on plane (x-z)
  19. )
  20. ;;********************************************************************************************
  21. ;;Define the coordinates of point B
  22. (defun c:defB ( / )                               
  23. (setq pointB (getpoint "\nSpecify Point B: "));;Asks user to specify point
  24. (setq Bxx (nth 0 PointB))                         ;;selects the 1st variable in the list pointB
  25. (setq Byy (nth 1 PointB))                         ;;selects the 2nd variable in the list pointB
  26. (setq Bzz (nth 2 PointB))                        ;;selects the 3rd variable in the list pointB
  27. (setq B1 (list (* Bxx -1) (* -1 Byy) 0.0))        ;;sets coords for T on plane (x-y)
  28. (setq B2 (list (* Bxx -1) Bzz 0.0))                ;;sets coords for T on plane (x-z)
  29. )
  30. ;;********************************************************************************************
  31. ;;Draw line with (X,Y) coordinates
  32. (defun c:DrawP1 ( / pointA pointB Axx Ayy Azz Bxx Byy Bzz p1)
  33. (entmake (list (cons 0 "LINE")(cons 10 A1)(cons 11 B1)))
  34. (setq p1 (entlast))
  35. (setq p1i(vlax-ename->vla-object p1))
  36. )
  37. ;;********************************************************************************************
  38. ;;Draw line with (X,Z) coordinates
  39. (defun c:DrawP2 ( / pointA pointB Axx Ayy Azz Bxx Byy Bzz p2)
  40.                                         ;;
  41. (entmake (list (cons 0 "LINE")(cons 10 A2)(cons 11 B2)))
  42. (setq p2 (entlast))
  43. (setq p2i(vlax-ename->vla-object p2))
  44. (vla-lengthen p2 "dy" 5)
  45. (vla-lengthen p2 "dy" -5)
  46. )
  47. ;;********************************************************************************************
  48. (defun c:insA ( / )
  49. (command "insert" "tA1" A1 1 1 0)                ;;inserts the mark for P on plane (x-y)
  50. (command "insert" "tA2" A2 1 1 0)                ;;inserts the mark for P on plane (x-z)
  51. )
  52. ;;********************************************************************************************
  53. (defun c:insB ( / )
  54. (command "insert" "tb1" B1 1 1 0)                ;;inserts the mark for T on plane (x-y)
  55. (command "insert" "tb2" B2 1 1 0)                ;;inserts the mark for T on plane (x-z)
  56. )
  57. ;;********************************************************************************************
  58. (princ)
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 08:08:36 | 显示全部楼层
 
您需要计算线的新起点和终点的坐标,然后更改VLA线对象的起点和终点属性。然而,这是不必要的,因为您可以首先创建一条长度和位置正确的线。
 
 
对于三维中的任意直线,可以计算直线向量(使用直线的起点和终点),然后使用直线方程计算具有给定X坐标(如果存在)的点的坐标;或者,可以计算线向量和Y-Z平面之间的交点,以及给定X坐标处的原点(或“高程”)。
e、 g.从这里使用我的线平面相交函数:
 
  1. [color=GREEN];; Line-Plane Intersection  -  Lee Mac[/color]
  2. [color=GREEN];; Returns the point of intersection of a line defined by[/color]
  3. [color=GREEN];; points p1,p2 and a plane defined by its origin and normal[/color]
  4. ([color=BLUE]defun[/color] LM:IntersLinePlane ( p1 p2 org nm )
  5.    ([color=BLUE]setq[/color] org ([color=BLUE]trans[/color] org 0 nm)
  6.          p1  ([color=BLUE]trans[/color] p1  0 nm)
  7.          p2  ([color=BLUE]trans[/color] p2  0 nm)
  8.    )
  9.    ([color=BLUE]trans[/color]
  10.        ([color=BLUE]inters[/color] p1 p2
  11.            ([color=BLUE]list[/color] ([color=BLUE]car[/color] p1) ([color=BLUE]cadr[/color] p1) ([color=BLUE]caddr[/color] org))
  12.            ([color=BLUE]list[/color] ([color=BLUE]car[/color] p2) ([color=BLUE]cadr[/color] p2) ([color=BLUE]caddr[/color] org))
  13.            [color=BLUE]nil[/color]
  14.        )
  15.        nm 0
  16.    )
  17. )

或者,对于平面中的二维线,可以使用inters函数(onseg参数设置为nil)来查找线向量和从平面中具有给定X坐标的点延伸的向量之间的交点,例如,对于X-Y平面中的线:
 
  1. 18
或甚至有点三角:
 
关于它的价值,以下是我对基于您上一段代码的程序的看法:
 
不过,我还没有完整阅读这篇文章,所以很可能有更好的方法来实现您希望获得的结果。
 
请注意,上述内容不考虑UCS变化。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-13 21:08 , Processed in 0.357155 second(s), 70 queries .

© 2020-2025 乐筑天下

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