乐筑天下

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

[编程交流] 指向相交点VB。网

[复制链接]

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:05:34 | 显示全部楼层 |阅读模式
大家好,Autocad专家,
 
我不熟悉使用VB进行Autocad自定义。网
 
我们需要从给定坐标到与任何其他线相交的点绘制一条水平线。这可能已经在论坛上讨论过了,但因为我是vb新手。net,我不能把东西放在一起。
 
感谢您对我的帮助。期待回复。
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 22:22:48 | 显示全部楼层
欢迎来到CADTutor。
 
也许你可以分享一下你的环境,以及可能帮助我们帮助你的专业知识?
 
你在开发什么版本,你在使用什么IDE,你在使用什么。NET向导或自定义模板,你如何分发你的应用程序,只是几个问题。
 
此外,请张贴您的代码。。。它不一定要有效,甚至不一定写得很好;这只是表明你已经投入了最初的努力,并且避免了另一个人从头开始编写代码(这节省了我们帮助你的时间)。
 
干杯
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 22:34:07 | 显示全部楼层
一些有帮助的理论,选取点,输入方向角,选取点作为搜索限制,使用这条“新”线,你可以得到所有相交对象,计算每个对象的交点,并进行比较,从而得到最近的点或最长的点。就像黑盒子邮政编码。
回复

使用道具 举报

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 22:49:46 | 显示全部楼层
黑盒/二进制:
 
我正在开发的版本是Autocad 2012。我使用的IDE是Visual Studio 2012。我现在打算使用命令执行方法。我从这个论坛上截取了一些代码片段,并做了一些小改动,看看它是如何工作的。下面是代码:这比我实际需要的做了更多的事情。我的要求很简单。用户将提供坐标2。应(仅)从给定坐标绘制一条水平线,直到该水平线与另一条线或对象相交。我对此很陌生,因此需要你的支持来解决这个问题。谢谢
 
  1. Imports System.Collections.Generic
  2. Imports Autodesk.AutoCAD.ApplicationServices
  3. Imports Autodesk.AutoCAD.Runtime
  4. Imports Autodesk.AutoCAD.EditorInput
  5. Imports Autodesk.AutoCAD.Geometry
  6. Imports Autodesk.AutoCAD.DatabaseServices
  7. Imports Autodesk.AutoCAD.Interop
  8. Imports System.Text.RegularExpressions
  9. Public Class Class1
  10.    <CommandMethod("pts")> _
  11.    Public Sub pts()
  12.        Dim lineCmd As Editor =
  13. Application.DocumentManager.MdiActiveDocument.Editor
  14.        Dim acadBaza As Database = lineCmd.Document.Database
  15.        Dim trans As Transaction =
  16. acadBaza.TransactionManager.StartTransaction
  17.        Dim opPoint As PromptPointOptions = New PromptPointOptions("Click on
  18. a Co-ordinate :")
  19.        Dim rePoint As PromptPointResult = lineCmd.GetPoint(opPoint)
  20.        Dim crvDict As Dictionary(Of Double, Line) = New Dictionary(Of
  21. Double, Line)()
  22.        ' confstruction of filter
  23.        Dim typeValue() As TypedValue = {New TypedValue(0, "line")}
  24.        Dim selFilter As SelectionFilter = New SelectionFilter(typeValue)
  25.        Dim selectResult As PromptSelectionResult =
  26. lineCmd.SelectAll(selFilter)
  27.        If rePoint.Status = PromptStatus.OK Then
  28.            Dim rePoint2 As Point3d = New Point3d(rePoint.Value.X + 10,
  29. rePoint.Value.Y, 0)
  30.            Dim prosta As Ray = New Ray()
  31.            Dim tmpPt As Point3d
  32.            prosta.BasePoint = rePoint.Value
  33.            prosta.SecondPoint = rePoint2
  34.            Try
  35.                Dim btr As BlockTableRecord =
  36. trans.GetObject(acadBaza.CurrentSpaceId, OpenMode.ForWrite)
  37.                btr.AppendEntity(prosta)
  38.                trans.AddNewlyCreatedDBObject(prosta, True)
  39.                If selectResult.Status = PromptStatus.OK Then
  40.                    Dim ss As SelectionSet = selectResult.Value
  41.                    Dim idTab() As ObjectId = ss.GetObjectIds()
  42.                    Dim ra As Ray = CType(trans.GetObject(prosta.Id,
  43. OpenMode.ForRead), Ray)
  44.                    Dim ptc As Point3dCollection = New
  45. Point3dCollection()
  46.                    Dim intthis As Integer
  47.                    Dim intThat As Integer
  48.                    Dim objId As ObjectId
  49.                    Dim x As Double
  50.                    For Each objId In idTab
  51.                        Dim tempptc As Point3dCollection = New
  52. Point3dCollection()
  53.                        Dim ln As Line = CType(trans.GetObject(objId,
  54. OpenMode.ForRead), Line)
  55.                        ln.IntersectWith(ra, Intersect.OnBothOperands,
  56. ln.GetPlane(), tempptc, intthis, intThat)
  57.                        If tempptc.Count > 0 Then
  58.                            MsgBox(tempptc.Count)
  59.                            For Each pt As Point3d In tempptc
  60.                                x = Math.Round(pt.X, 6)
  61.                                crvDict.Add(x, ln) 'add line to dictionary
  62. with X coordinate as Key
  63.                                ptc.Add(pt)
  64.                            Next
  65.                        End If
  66.                    Next
  67.                    'trans.Commit()
  68.                    If crvDict.Count > 0 Then
  69.                        Dim pts As Point3d
  70.                        tmpPt = ptc.Item(0)
  71.                        Dim i As Integer
  72.                        If ptc.Count > 1 Then
  73.                            For i = 0 To ptc.Count - 1
  74.                                pts = ptc(i)
  75.                                If pts.X < tmpPt.X Then
  76.                                    tmpPt = pts
  77.                                End If
  78.                            Next
  79.                        End If
  80.                        MsgBox(tmpPt.ToString)
  81.                        Dim s As String() = Regex.Split(tmpPt.ToString,
  82. ",")
  83.                        Dim value1 As Double
  84.                        Dim value2 As Double
  85.                        Double.TryParse(s(0).Substring(1), value1)
  86.                        Double.TryParse(s(1), value2)
  87.                        Dim rePoint3 As Point3d = New Point3d(value1, value2,
  88. 0)
  89.                        Dim prosta1 As Line = New Line()
  90.                        prosta1.StartPoint = rePoint.Value
  91.                        prosta1.EndPoint = rePoint3
  92.                        btr.AppendEntity(prosta1)
  93.                        trans.AddNewlyCreatedDBObject(prosta1, True)
  94.                        MsgBox(value1)
  95.                        MsgBox(value2)
  96.                        trans.Commit()
  97.                        lineCmd.WriteMessage(tmpPt.ToString)
  98.                        crvDict(Math.Round(tmpPt.X, 6)).Highlight() 'Retrieve
  99. line based on X coordinate Key equal to tmpPt.X
  100.                        lineCmd.WriteMessage(" ObjectId: " &
  101. crvDict(Math.Round(tmpPt.X, 6)).ObjectId.ToString())
  102.                    Else
  103.                        lineCmd.WriteMessage("No intersections")
  104.                    End If
  105.                End If
  106.            Catch ex As Exception
  107.                lineCmd.WriteMessage("There is a problem" + ex.Message)
  108.                MsgBox(ex.Message)
  109.            Finally
  110.                trans.Dispose()
  111.            End Try
  112.        End If
  113.    End Sub
  114. End Class

 
 
 
 
 
回复

使用道具 举报

1

主题

3

帖子

2

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 23:05:37 | 显示全部楼层
你好,
 
我尝试了一组代码,似乎在一定程度上可行。但是,水平线似乎并没有在第一个交点处停止。此外,它还存在一个限制,即它仅识别另一条线作为交点,而不是曲线或任何其他平面。请帮忙!
 
 
  1. Imports System.Collections.Generic
  2. Imports Autodesk.AutoCAD.ApplicationServices
  3. Imports Autodesk.AutoCAD.Runtime
  4. Imports Autodesk.AutoCAD.EditorInput
  5. Imports Autodesk.AutoCAD.Geometry
  6. Imports Autodesk.AutoCAD.DatabaseServices
  7. Imports Autodesk.AutoCAD.Interop
  8. Public Class Class1
  9.    <CommandMethod("dwl")> _
  10.    Public Sub pts()
  11.        Dim lineCmd As Editor =
  12. Application.DocumentManager.MdiActiveDocument.Editor
  13.        Dim acadBaza As Database = lineCmd.Document.Database
  14.        Dim opPoint As PromptPointOptions = New PromptPointOptions("Click on
  15. a Co-ordinate :")
  16.        Dim rePoint As PromptPointResult = lineCmd.GetPoint(opPoint)
  17.        Dim typeValue() As TypedValue = {New TypedValue(0, "line")}
  18.        Dim selFilter As SelectionFilter = New SelectionFilter(typeValue)
  19.        Dim selectResult As PromptSelectionResult =
  20. lineCmd.SelectAll(selFilter)
  21.        If rePoint.Status = PromptStatus.OK Then
  22.            Using trans As Transaction =
  23. acadBaza.TransactionManager.StartTransaction()
  24.                Try
  25.                    Dim prosta As Line = New Line(New
  26. Point3d(rePoint.Value.X, rePoint.Value.Y, 0), New Point3d(rePoint.Value.X * 100,
  27. rePoint.Value.Y, 0))
  28.                    prosta.SetDatabaseDefaults()
  29.                    Dim btr As BlockTableRecord =
  30. trans.GetObject(acadBaza.CurrentSpaceId, OpenMode.ForWrite)
  31.                    btr.AppendEntity(prosta)
  32.                    trans.AddNewlyCreatedDBObject(prosta, True)
  33.                    Dim ra As Line = CType(trans.GetObject(prosta.Id,
  34. OpenMode.ForWrite), Line)
  35.                    If selectResult.Status = PromptStatus.OK Then
  36.                        Dim ss As SelectionSet = selectResult.Value
  37.                        Dim idTab() As ObjectId = ss.GetObjectIds()
  38.                        Dim objId As ObjectId
  39.                        Dim x As Double
  40.                        Dim dl As Boolean = True
  41.                        For Each objId In idTab
  42.                            Dim tempptc As Point3dCollection = New
  43. Point3dCollection()
  44.                            Dim ln As Line = CType(trans.GetObject(objId,
  45. OpenMode.ForRead), Line)
  46.                            ln.IntersectWith(ra, Intersect.OnBothOperands,
  47. ln.GetPlane(), tempptc, 0, 0)
  48.                            If tempptc.Count > 0 And dl Then
  49.                                For Each pt As Point3d In tempptc
  50.                                    x = Math.Round(pt.X, 6)
  51.                                    MsgBox("Second point" & x.ToString
  52. & ":", MsgBoxStyle.Information)
  53.                                    Dim prosta2 As Line = New Line(New
  54. Point3d(rePoint.Value.X, rePoint.Value.Y, 0), New Point3d(x, rePoint.Value.Y,
  55. 0))
  56.                                    btr.AppendEntity(prosta2)
  57.                                    trans.AddNewlyCreatedDBObject(prosta2,
  58. True)
  59.                                    dl = False
  60.                                    Exit For
  61.                                Next
  62.                            End If
  63.                        Next
  64.                    End If
  65.                    ra.Erase(True)
  66.                    trans.Commit()
  67.                Catch ex As Exception
  68.                    lineCmd.WriteMessage("Error:" + ex.Message)
  69.                    MsgBox(ex.Message)
  70.                Finally
  71.                    trans.Dispose()
  72.                End Try
  73.            End Using
  74.        End If
  75.    End Sub
  76. End Class

 
 
 
 
 
 
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-6 23:14:17 | 显示全部楼层
请阅读代码发布指南并编辑您的帖子,将代码包含在代码标签中。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 11:30 , Processed in 0.466341 second(s), 64 queries .

© 2020-2025 乐筑天下

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