乐筑天下

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

[编程交流] LISP-自动标注ac

[复制链接]

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 16:41:32 | 显示全部楼层 |阅读模式
大家好,
 
我在一家玻璃公司工作,正在尝试编写一个AutoLISP命令,通过按供应商喜欢的格式标注带有孔和切口的玻璃面板尺寸,将我们的大部分工作自动化。
 
我会在这里附上一张照片,展示我到目前为止所做的事情。
174132kpzzw258284w61r6.jpg
 
左边的矩形显示了我想要的尺寸。
右边的矩形显示了我的LISP例程当前的功能。
我在编写逻辑以按我想要的方式对其进行尺寸标注时遇到了问题。
 
它应该遵循的规则是:
1) 尺寸字符串应制作到离孔最近的角落
2) 如果两个孔对齐,尺寸应穿过较近的孔
3) 如果两个维度到达同一个角,它们应以3”的间隔堆叠(通常为DIMBASELINE设置偏移)
4) 尺寸字符串应始终在其上方较大尺寸的后面3英寸(参见左上角的5英寸测量值)
 
然而,这些规则仅适用于“矩形”形状选项。在例程的最终版本中,我希望有一个易于扩展的规则列表,我可以修改和调整每个形状。
 
我在下面附上了一个测试图和LISP例程的当前版本。矩形尺寸标注规则的代码见第436-494行。
 
如果您能帮我解决这个问题,我们将不胜感激。
 
非常感谢。
 
图形文件:autodimtest。图纸
当前LISP:autoDim。lsp
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:05:56 | 显示全部楼层
这是一大堆代码,不用花几个小时去想。我会在两个不同的层上进行两次尺寸标注,在构建形状时可能会更多。对于非常简单的形状矩形等,代码大小似乎过大,可能我看错了。
 
Ps喜欢形状块。
回复

使用道具 举报

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 17:15:09 | 显示全部楼层
谢谢你的回复,比格尔。
 
你能详细说明你在两个不同的层面上标注尺寸的意思吗?
您是指图层特性管理器中定义的图层吗?
 
我对编程基本上是新手,所以我相信可以做很多简化。
 
目前,该程序的工作原理如下:
•分析多段线,必要时对其进行改造,以确保起点位于最左下角,并从那里顺时针走
•将每个顶点的坐标保存到变量A到H(在定义的所有形状中最多只有8个点)
•保存包围多段线最外顶点的边界框。这用于定义标注位置。我可以将其偏移3”,然后放置第一个dim,然后再次放置下一个dim,以允许dim堆叠
•将所有孔的坐标保存到列表中((x1 y1)(x2 y2).)然后可以按minX、minY等对列表进行排序。
•然后才开始根据此信息放置尺寸。大多数形状的基本尺寸规则已经包含在自定义函数drawDim中,遵循我制作的形状块中列出的规则。
 
我对孔的问题是,当尺寸标注到同一侧的不同角落时,堆叠必须重置。我认为我需要程序识别它之前的DIM和它之后的DIM,以便它可以动态地决定放置维度的堆叠级别,而不是在每次操作中严格地增加边界框大小。你可以在我的第一篇文章中看到,右边的矩形就是这样。
 
代码如此庞大有几个原因:
我选择为每个形状单独定义尺寸标注规则,其中有67个不同的形状,因为这将有助于我在未来对其进行扩展。
它如此长的另一个原因是,该命令还用作双重检查,以确保正确绘制形状。60%的代码是错误消息,检查某些角是否为正方形,边是否等长等。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:30:24 | 显示全部楼层
之后的最终输出是您已经生成的内容的变体,因此,堆叠的dim 12 15 20位于层DIM1上,尽管您在对象顶部执行dim 12,但位于层Dim2上。是的,它意味着一直翻转层(setvar“clayer”“dim2”)。这只是我,但写一些已经完成了根据规则,然后再次尝试重做它是非常困难的,这将意味着检查规则22,如果真的做规则22A。同样,您可能需要第三层DIM3,其dims始终可见。使用2个布局应该能够通过关闭视口中的正确图层来查看结果是否正确。
回复

使用道具 举报

2

主题

5

帖子

3

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 17:51:43 | 显示全部楼层
谢谢你的想法。
 
我想在不向绘图中添加任何附加层的情况下完成它。经过一些思考,我想出了一个只适用于我的代码解决方案。我会把它贴在这里给任何好奇或想看它的人。
 
我添加的代码:
  1. (if (setq holes        (orgCoords holes "BL"))
  2. (progn
  3.         (foreach j holes
  4.                 (cond
  5.                         ( (= (nearCoor j glassBorderPts) a)
  6.                                 (if (or  (isInline j holes "y" "top")
  7.                                         (not (isInline j holes "y" nil)))
  8.                                         (setq orderedHoles (addHole j orderedHoles "bottom" a)))
  9.                                 (if (or  (isInline j holes "x" "right")
  10.                                         (not (isInline j holes "x" nil)))
  11.                                         (setq orderedHoles (addHole j orderedHoles "left" a)))
  12.                         )
  13.                         ( (= (nearCoor j glassBorderPts) b)
  14.                                 (cond
  15.                                         ( (isInline j holes "y" "top") (setq orderedHoles (addHole j orderedHoles "bottom" a)) )
  16.                                         ( (not (isInline j holes "y" nil)) (setq orderedHoles (addHole j orderedHoles "top" b)) )
  17.                                 );cond
  18.                                 (if (or  (isInline j holes "x" "right")
  19.                                         (not (isInline j holes "x" nil)))
  20.                                         (setq orderedHoles (addHole j orderedHoles "left" b)))
  21.                         )
  22.                         ( (= (nearCoor j glassBorderPts) c)
  23.                                 (cond
  24.                                         ( (isInline j holes "y" "top") (setq orderedHoles (addHole j orderedHoles "bottom" d)) )
  25.                                         ( (not (isInline j holes "y" nil)) (setq orderedHoles (addHole j orderedHoles "top" c)) )
  26.                                 );cond
  27.                                 (cond
  28.                                         ( (isInline j holes "x" "right") (setq orderedHoles (addHole j orderedHoles "left" b)) )
  29.                                         ( (not (isInline j holes "x" nil)) (setq orderedHoles (addHole j orderedHoles "right" c)) )
  30.                                 );cond
  31.                         )
  32.                         ( (= (nearCoor j glassBorderPts) d)
  33.                                 (if (or  (isInline j holes "y" "top")
  34.                                         (not (isInline j holes "y" nil)))
  35.                                         (setq orderedHoles (addHole j orderedHoles "bottom" d)))
  36.                                 (cond
  37.                                         ( (isInline j holes "x" "right") (setq orderedHoles (addHole j orderedHoles "left" a)) )
  38.                                         ( (not (isInline j holes "x" nil)) (setq orderedHoles (addHole j orderedHoles "right" d)) )
  39.                                 );cond
  40.                         )
  41.                 );cond
  42.         );foreach
  43.         (setq orderedHoles (orgCoords orderedHoles (list "bottom" a "LB")))
  44.         (setq orderedHoles (orgCoords orderedHoles (list "bottom" d "RB")))
  45.         (setq orderedHoles (orgCoords orderedHoles (list "left" a "BL")))
  46.         (setq orderedHoles (orgCoords orderedHoles (list "left" b "TL")))
  47.         (setq orderedHoles (orgCoords orderedHoles (list "top" b "LT")))
  48.         (setq orderedHoles (orgCoords orderedHoles (list "top" c "RT")))
  49.         (setq orderedHoles (orgCoords orderedHoles (list "right" c "TR")))
  50.         (setq orderedHoles (orgCoords orderedHoles (list "right" d "BR")))
  51.         (setq bounding (drawHoleDims orderedHoles bounding))
  52. );progn
  53. );if

 
isInline函数:
  1. (defun isInline (pt pts axis dir / j ans flag)
  2. ;Checks if a point is inline with any point in a list of points,
  3. ;and if it is the furthest point inline point in a given direction
  4. ;pt                :        List - Coordinate pair (x y) for point to check
  5. ;pts                :        List - List of coordinate pairs for points to check against
  6. ;axis                :        String - Which axis to check for other points ("x" or "y")
  7. ;dir                :        String - Direction to check if point is the furthest ("left", "bottom", etc) pass nil to check for inline only
  8. ;Returns        :        T if holes are inline AND hole is furthest on specified direction, or if holes exist inline while dir=nil
  9. ;                                Nil if no holes are inline OR holes are inline but pt is not furthest in specified direction
  10. (foreach j pts
  11.         (cond
  12.                 ( (= j pt) )
  13.                 ( (and (= axis "x") (null dir) (equal (cadr pt) (cadr j) fuzz)) (setq ans T) )
  14.                 ( (and (= axis "y") (null dir) (equal (car pt) (car j) fuzz)) (setq ans T) )
  15.                 ( (and (= axis "x") (= dir "left")  (equal (cadr pt) (cadr j) fuzz)                 (< (car pt) (car j))) (setq ans T) )
  16.                 ( (and (= axis "x") (= dir "left")  (equal (cadr pt) (cadr j) fuzz) (not (< (car pt) (car j)))) (setq flag T) )
  17.                 ( (and (= axis "x") (= dir "right") (equal (cadr pt) (cadr j) fuzz)                 (> (car pt) (car j))) (setq ans T) )
  18.                 ( (and (= axis "x") (= dir "right") (equal (cadr pt) (cadr j) fuzz) (not (> (car pt) (car j)))) (setq flag T) )
  19.                 ( (and (= axis "y") (= dir "bottom")  (equal (car pt) (car j) fuzz)           (< (cadr pt) (cadr j))) (setq ans T) )
  20.                 ( (and (= axis "y") (= dir "bottom")  (equal (car pt) (car j) fuzz) (not (< (cadr pt) (cadr j)))) (setq flag T) )
  21.                 ( (and (= axis "y") (= dir "top") (equal (car pt) (car j) fuzz)           (> (cadr pt) (cadr j))) (setq ans T) )
  22.                 ( (and (= axis "y") (= dir "top") (equal (car pt) (car j) fuzz) (not (> (cadr pt) (cadr j)))) (setq flag T) )
  23.         );cond
  24. );foreach
  25. (if flag (setq ans nil))
  26. ans
  27. );defun

 
drawHoleDims功能:
  1. (defun drawHoleDims (holes ofst / finalBounding i j k l maxi)
  2. ;Draws dimensions for all coordinates in the ordered coordinate list passed
  3. ;holes                :        List - Ordered list of holes to dimension (list created with addHole command)
  4. ;ofst                :        List - Two sets of coordinates ((x1 y1) (x2 y2)) for bounding box to offset dimensions to
  5. ;Returns        :        List - New sets of coordinates ((x1 y1) (x2 y2)) for bounding box of final dimensions
  6. (setq finalBounding ofst)
  7. (foreach j holes
  8.         (setq maxi 0)
  9.         (foreach k (cdr j)
  10.                 (if (> (1- (vl-list-length k)) maxi) (setq maxi (1- (vl-list-length k))))
  11.         );foreach
  12.         (foreach k (cdr j)
  13.                 (setq i maxi)
  14.                 (foreach l (reverse (cdr k))
  15.                         (setq i (1- i))
  16.                         (drawDim l (car k) (if (/= i 0) (growbound ofst (car j) (* i ofstTYP)) ofst) (car j) nil)
  17.                 );foreach
  18.         );foreach
  19.         (setq finalBounding (growbound finalBounding (car j) (* maxi ofstTYP)))
  20. );foreach
  21. );defun

 
整个代码:autoDim。lsp
测试图纸:autodimtest。图纸
 
要使用,请运行命令并选择整个未标注的边界,包括形状块和所有孔。
 
它目前只支持矩形形状,但用我的设置方式为其余部分添加逻辑将是微不足道的。
 
如果有人在看这段代码时注意到我可以进行的任何优化,请告诉我!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 12:59 , Processed in 0.648385 second(s), 76 queries .

© 2020-2025 乐筑天下

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