谢谢你的想法。
我想在不向绘图中添加任何附加层的情况下完成它。经过一些思考,我想出了一个只适用于我的代码解决方案。我会把它贴在这里给任何好奇或想看它的人。
我添加的代码:
- (if (setq holes (orgCoords holes "BL"))
- (progn
- (foreach j holes
- (cond
- ( (= (nearCoor j glassBorderPts) a)
- (if (or (isInline j holes "y" "top")
- (not (isInline j holes "y" nil)))
- (setq orderedHoles (addHole j orderedHoles "bottom" a)))
- (if (or (isInline j holes "x" "right")
- (not (isInline j holes "x" nil)))
- (setq orderedHoles (addHole j orderedHoles "left" a)))
- )
- ( (= (nearCoor j glassBorderPts) b)
- (cond
- ( (isInline j holes "y" "top") (setq orderedHoles (addHole j orderedHoles "bottom" a)) )
- ( (not (isInline j holes "y" nil)) (setq orderedHoles (addHole j orderedHoles "top" b)) )
- );cond
- (if (or (isInline j holes "x" "right")
- (not (isInline j holes "x" nil)))
- (setq orderedHoles (addHole j orderedHoles "left" b)))
- )
- ( (= (nearCoor j glassBorderPts) c)
- (cond
- ( (isInline j holes "y" "top") (setq orderedHoles (addHole j orderedHoles "bottom" d)) )
- ( (not (isInline j holes "y" nil)) (setq orderedHoles (addHole j orderedHoles "top" c)) )
- );cond
- (cond
- ( (isInline j holes "x" "right") (setq orderedHoles (addHole j orderedHoles "left" b)) )
- ( (not (isInline j holes "x" nil)) (setq orderedHoles (addHole j orderedHoles "right" c)) )
- );cond
- )
- ( (= (nearCoor j glassBorderPts) d)
- (if (or (isInline j holes "y" "top")
- (not (isInline j holes "y" nil)))
- (setq orderedHoles (addHole j orderedHoles "bottom" d)))
- (cond
- ( (isInline j holes "x" "right") (setq orderedHoles (addHole j orderedHoles "left" a)) )
- ( (not (isInline j holes "x" nil)) (setq orderedHoles (addHole j orderedHoles "right" d)) )
- );cond
- )
- );cond
- );foreach
- (setq orderedHoles (orgCoords orderedHoles (list "bottom" a "LB")))
- (setq orderedHoles (orgCoords orderedHoles (list "bottom" d "RB")))
- (setq orderedHoles (orgCoords orderedHoles (list "left" a "BL")))
- (setq orderedHoles (orgCoords orderedHoles (list "left" b "TL")))
- (setq orderedHoles (orgCoords orderedHoles (list "top" b "LT")))
- (setq orderedHoles (orgCoords orderedHoles (list "top" c "RT")))
- (setq orderedHoles (orgCoords orderedHoles (list "right" c "TR")))
- (setq orderedHoles (orgCoords orderedHoles (list "right" d "BR")))
- (setq bounding (drawHoleDims orderedHoles bounding))
- );progn
- );if
isInline函数:
- (defun isInline (pt pts axis dir / j ans flag)
- ;Checks if a point is inline with any point in a list of points,
- ;and if it is the furthest point inline point in a given direction
- ;pt : List - Coordinate pair (x y) for point to check
- ;pts : List - List of coordinate pairs for points to check against
- ;axis : String - Which axis to check for other points ("x" or "y")
- ;dir : String - Direction to check if point is the furthest ("left", "bottom", etc) pass nil to check for inline only
- ;Returns : T if holes are inline AND hole is furthest on specified direction, or if holes exist inline while dir=nil
- ; Nil if no holes are inline OR holes are inline but pt is not furthest in specified direction
- (foreach j pts
- (cond
- ( (= j pt) )
- ( (and (= axis "x") (null dir) (equal (cadr pt) (cadr j) fuzz)) (setq ans T) )
- ( (and (= axis "y") (null dir) (equal (car pt) (car j) fuzz)) (setq ans T) )
- ( (and (= axis "x") (= dir "left") (equal (cadr pt) (cadr j) fuzz) (< (car pt) (car j))) (setq ans T) )
- ( (and (= axis "x") (= dir "left") (equal (cadr pt) (cadr j) fuzz) (not (< (car pt) (car j)))) (setq flag T) )
- ( (and (= axis "x") (= dir "right") (equal (cadr pt) (cadr j) fuzz) (> (car pt) (car j))) (setq ans T) )
- ( (and (= axis "x") (= dir "right") (equal (cadr pt) (cadr j) fuzz) (not (> (car pt) (car j)))) (setq flag T) )
- ( (and (= axis "y") (= dir "bottom") (equal (car pt) (car j) fuzz) (< (cadr pt) (cadr j))) (setq ans T) )
- ( (and (= axis "y") (= dir "bottom") (equal (car pt) (car j) fuzz) (not (< (cadr pt) (cadr j)))) (setq flag T) )
- ( (and (= axis "y") (= dir "top") (equal (car pt) (car j) fuzz) (> (cadr pt) (cadr j))) (setq ans T) )
- ( (and (= axis "y") (= dir "top") (equal (car pt) (car j) fuzz) (not (> (cadr pt) (cadr j)))) (setq flag T) )
- );cond
- );foreach
- (if flag (setq ans nil))
- ans
- );defun
drawHoleDims功能:
- (defun drawHoleDims (holes ofst / finalBounding i j k l maxi)
- ;Draws dimensions for all coordinates in the ordered coordinate list passed
- ;holes : List - Ordered list of holes to dimension (list created with addHole command)
- ;ofst : List - Two sets of coordinates ((x1 y1) (x2 y2)) for bounding box to offset dimensions to
- ;Returns : List - New sets of coordinates ((x1 y1) (x2 y2)) for bounding box of final dimensions
- (setq finalBounding ofst)
- (foreach j holes
- (setq maxi 0)
- (foreach k (cdr j)
- (if (> (1- (vl-list-length k)) maxi) (setq maxi (1- (vl-list-length k))))
- );foreach
- (foreach k (cdr j)
- (setq i maxi)
- (foreach l (reverse (cdr k))
- (setq i (1- i))
- (drawDim l (car k) (if (/= i 0) (growbound ofst (car j) (* i ofstTYP)) ofst) (car j) nil)
- );foreach
- );foreach
- (setq finalBounding (growbound finalBounding (car j) (* maxi ofstTYP)))
- );foreach
- );defun
整个代码:autoDim。lsp
测试图纸:autodimtest。图纸
要使用,请运行命令并选择整个未标注的边界,包括形状块和所有孔。
它目前只支持矩形形状,但用我的设置方式为其余部分添加逻辑将是微不足道的。
如果有人在看这段代码时注意到我可以进行的任何优化,请告诉我! |