乐筑天下

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

[编程交流] 交叉线列表

[复制链接]

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-6 22:34:10 | 显示全部楼层
 
您已经在AutoLISP、Visual LISP和DCL论坛上发布了此线程。
 
我已将您的线程移动到。NET、ObjectARX和VBA论坛。
回复

使用道具 举报

12

主题

175

帖子

77

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
149
发表于 2022-7-6 22:36:40 | 显示全部楼层
这是一个可能的代码
 
  1. Option Explicit
  2. Sub ListIntersectingLines()
  3.    Dim linesSset As AcadSelectionSet
  4.    Dim nIntersectingLines As Long
  5.    Dim mainLine As AcadLine, acLine As AcadLine
  6.    
  7.    Set mainLine = GetALine
  8.    
  9.    If Not GetPossiblyCrossingLines(linesSset, mainLine) Then
  10.        MsgBox "no possible intersecting lines with main line"
  11.        Exit Sub
  12.    End If
  13.    
  14.    If FilterActuallyIntersectingLines(linesSset, mainLine) Then
  15.        For Each acLine In linesSset
  16.            nIntersectingLines = nIntersectingLines + 1
  17.            MsgBox "Intersecting line #" & nIntersectingLines & " ID=" & acLine.ObjectID
  18.            acLine.color = acGreen
  19.        Next
  20.    Else
  21.        MsgBox "no intersecting lines with main line"
  22.    End If
  23. End Sub
  24. Function FilterActuallyIntersectingLines(linesSset As AcadSelectionSet, mainLine As AcadLine) As Boolean
  25.    Dim nLines As Long
  26.    Dim acLine As AcadLine
  27.    Dim removeObjectsCounter As Long      
  28.    ReDim removeObjects(0 To linesSset.Count - 1) As AcadEntity
  29.    With mainLine
  30.        For Each acLine In linesSset
  31.            If UBound(.IntersectWith(acLine, acExtendNone)) = -1 Then
  32.                Set removeObjects(removeObjectsCounter) = acLine
  33.                removeObjectsCounter = removeObjectsCounter + 1
  34.            End If
  35.        Next
  36.        If removeObjectsCounter > 0 Then
  37.            ReDim Preserve removeObjects(0 To removeObjectsCounter - 1) As AcadEntity
  38.            linesSset.RemoveItems removeObjects
  39.            FilterActuallyIntersectingLines= linesSset.Count > 0
  40.        End If
  41.    End With
  42. End Function
  43. Function GetALine() As AcadLine
  44.    Dim basePnt As Variant
  45.    
  46.    On Error Resume Next
  47.    Do While GetALine Is Nothing
  48.        ThisDrawing.Utility.GetEntity GetALine, basePnt, "Select a line"
  49.    Loop
  50. End Function
  51. Function GetPossiblyCrossingLines(linesSset As AcadSelectionSet, mainLine As AcadLine) As Boolean
  52.    Dim gpCode(0) As Integer
  53.    Dim dataValue(0) As Variant
  54.    
  55.    gpCode(0) = 0
  56.    dataValue(0) = "LINE"
  57.    On Error Resume Next
  58.    Set linesSset = ThisDrawing.SelectionSets.Add("Lines")
  59.    On Error GoTo 0
  60.    If linesSset Is Nothing Then Set linesSset = ThisDrawing.SelectionSets.Item("Lines")
  61.    
  62.    Dim corner1 As Variant, corner2 As Variant
  63.    mainLine.GetBoundingBox corner1, corner2
  64.    ZoomWindow corner1, corner2
  65.    With linesSset
  66.        .Clear
  67.        .Select acSelectionSetCrossing, corner1, corner2, gpCode, dataValue
  68.        If .Count > 1 Then
  69.            Dim removeObjects(0 To 0) As AcadEntity
  70.            Set removeObjects(0) = mainLine
  71.            .RemoveItems removeObjects
  72.            GetPossiblyCrossingLines= True
  73.        End If
  74.    End With
  75.    ZoomPrevious
  76. End Function
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 22:45:07 | 显示全部楼层
Lisp版本中,请注意,当拾取线作为选择集中的最后一个对象返回时,会出现鬼鬼祟祟的x-1,这比执行微妙的偏移和拾取点更容易。
 
  1. ; example of intersect with by Alan H Aug 2017
  2. ; to use on pline same code but need fence option to use co-ords
  3. ; need to add this option see pline co-ords code
  4. (defun c:ByBIGAL ( / obj obj2 lst ss pt ans)
  5. (setq obj (vlax-ename->vla-object (car (entsel "\nPick object"))))
  6. (if (= "AcDbLine" (vla-get-objectname obj))
  7. (progn
  8. (setq lst (list
  9. (vlax-safearray->list (vlax-variant-value(vla-get-startpoint obj)))
  10. (vlax-safearray->list (vlax-variant-value(vla-get-endpoint obj)))
  11. ))
  12. (setq ans "")
  13. (setq ss (ssget "F" lst (list (cons 0 "Line"))))
  14. (repeat (setq x (- (sslength ss)1))
  15. (setq obj2 (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  16. (setq pt (vlax-invoke obj2 'intersectWith obj acExtendThisEntity))
  17. (setq ans (strcat ans "\nX=" (rtos (car pt) 2 3) " " "Y= " (rtos (cadr pt) 2 3) ))
  18. )
  19. )
  20. (alert "Object picked is not a line")
  21. )
  22. (alert ans)c
  23. (princ)
  24. )
回复

使用道具 举报

2

主题

7

帖子

5

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 22:49:19 | 显示全部楼层
 
谢谢你的回复。当我更改custom corner1和corner2完美工作程序时。
但当两条线背靠背时,它不起作用。我添加了示例图片。line1和line2是两条交错的线。运行程序后,line1颜色再次为白色。命令行1将检测什么?
224930fz49lno1rzocy35h.jpg
224932tng8efe4setceeeh.jpg
回复

使用道具 举报

12

主题

175

帖子

77

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
149
发表于 2022-7-6 22:49:35 | 显示全部楼层
这是因为重叠的线条不会
方法捕捉任何交点
 
您可以通过尝试查看与主线段平行的任何线段是否也在许多方面重叠(因此相交)来处理此异常
 
以下是其中之一(仅显示更改的子/函数):
 
[code]函数FilterActuallyIntersectingLines(linesSset为AcadSelectionSet,mainLine为AcadLine)作为布尔Dim acLine作为AcadLine Dim removeObjects输入只要ReDim removeObjects(0到linesSset。Count-1)作为linesSset中每个acLine的mainLine的身份如果没有doestintersect(mainLine,acLine),则“0”,然后ReDim Preserve removeObjects(0以删除ObjectsCenter-1)作为身份线集。如果以FilterActuallyIntersectingLines=LinesSet结尾,则RemoveItems removeObjects结束。计数>0’
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 13:45 , Processed in 0.446538 second(s), 63 queries .

© 2020-2025 乐筑天下

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