乐筑天下

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

[编程交流] 指向VB线。净额

[复制链接]

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 12:58:43 | 显示全部楼层 |阅读模式
你好
我有一个简单的问题,我想,但我是vba的新手,所以我问
我画了一条线,我选了一个点,我想画一条从我的点到这条线的水平线,但我不知道怎么画
希望有人能帮忙
回复

使用道具 举报

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 13:08:13 | 显示全部楼层
我想我可以用光线在点和线之间画一条线,但是我怎么才能找到它穿过另一条线的点呢?在lisp中,类似inters的东西,但在vb中,我不知道如何使用
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 13:10:45 | 显示全部楼层
在给出可能不合适的建议之前:你对哪种口味的vb感兴趣,VBA/VB6还是vb。网络?
 
我想一个示例文件(最好是2007年格式)说明之前和之后也会很有帮助。
回复

使用道具 举报

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 13:21:58 | 显示全部楼层
我试着在vb网络中写(很抱歉vba),我在绘图中有一条线,我知道如何使用宏绘制光线,但我不知道如果它们相交,我怎么能找到相交点
thx回复
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 13:23:52 | 显示全部楼层
直线和光线都派生自数据库曲线类,而数据库曲线类又派生自数据库实体。作为实体,两者都可以使用该实体。与方法相交。
 
 
  1.     <CommandMethod("LRInt")> _
  2. Public Sub LineRayIntersect()
  3.        Dim db As Database = HostApplicationServices.WorkingDatabase
  4.        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  5.        db.Pdmode = 66 'just to make the points more visible
  6.        Dim peo As PromptEntityOptions = New PromptEntityOptions("Select a Line: ")
  7.        peo.SetRejectMessage("Select only a line!")
  8.        peo.AddAllowedClass(GetType(Line), False)
  9.        Dim tr As Transaction = db.TransactionManager.StartTransaction()
  10.        Using tr
  11.            Try
  12.                Dim per As PromptEntityResult = ed.GetEntity(peo)
  13.                If per.Status <> PromptStatus.OK Then Exit Sub
  14.                Dim ln As Line = tr.GetObject(per.ObjectId, OpenMode.ForRead)
  15.                peo.SetRejectMessage("Select only a Ray!")
  16.                peo.Message = "Select a Ray: "
  17.                peo.RemoveAllowedClass(GetType(Line))
  18.                peo.AddAllowedClass(GetType(Ray), False)
  19.                per = ed.GetEntity(peo)
  20.                If per.Status <> PromptStatus.OK Then Exit Sub
  21.                Dim ry As Ray = tr.GetObject(per.ObjectId, OpenMode.ForRead)
  22.                Dim ptc As Point3dCollection = New Point3dCollection()
  23.                Dim intthis As Integer
  24.                Dim intThat As Integer
  25.                ln.IntersectWith(ry, Intersect.OnBothOperands, ln.GetPlane(), ptc, intthis, intThat)
  26.                If ptc.Count < 1 Then Exit Sub
  27.                Dim ptAtInters As DBPoint = New DBPoint(ptc(0))
  28.                Dim btr As BlockTableRecord = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
  29.                btr.AppendEntity(ptAtInters)
  30.                tr.AddNewlyCreatedDBObject(ptAtInters, True)
  31.                tr.Commit()
  32.            Catch
  33.                ed.WriteMessage("Error during execution!")
  34.                tr.Abort()
  35.            End Try
  36.        End Using
  37.    End Sub
回复

使用道具 举报

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 13:34:13 | 显示全部楼层
谢谢你的帮助,但我想知道是否有可能不用用户选择线,通过射线本身找到该点
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 13:39:17 | 显示全部楼层
这是可能的,但必须设置例程以迭代活动空间中满足所需标准的所有曲线。请参阅:
 
编辑SelectAll方法(SelectionFilter)
 
 
 
然后,将在所有以光线为基础的过滤曲线上使用我上一篇文章中所示的相同过程。i、 e.,ry.IntersectWith(curve,Intersect.OnBothOperands,ry.GetPlane(),ptc,intThis,intThat)。
 
如果您在设置时遇到问题,请发布您的代码,我们将尽力提供建议。
回复

使用道具 举报

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 13:43:33 | 显示全部楼层
好的,谢谢你的帮助,但我会尽力自己做。如果我失败了,我会回来的;]
回复

使用道具 举报

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 13:51:42 | 显示全部楼层
您好,我再一次做了这样的事情,光线在它的路上找到了第一条线(一条线上的点)。任何建议,我怎么能得到那条线的id,这就是我写的
  1. <CommandMethod("pts")> _
  2.    Public Sub pts()
  3.        Dim lineCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  4.        Dim acadBaza As Database = lineCmd.Document.Database
  5.        Dim trans As Transaction = acadBaza.TransactionManager.StartTransaction
  6.        Dim opPoint As PromptPointOptions = New PromptPointOptions("Kliknij srodek pomieszczenia :")
  7.        Dim rePoint As PromptPointResult = lineCmd.GetPoint(opPoint)
  8.        ' confstruction of filter
  9.        Dim typeValue() As TypedValue = {New TypedValue(0, "line")}
  10.        Dim selFilter As SelectionFilter = New SelectionFilter(typeValue)
  11.        Dim selectResult As PromptSelectionResult = lineCmd.SelectAll(selFilter)
  12.        If rePoint.Status = PromptStatus.OK Then
  13.            Dim rePoint2 As Point3d = New Point3d(rePoint.Value.X + 10, rePoint.Value.Y, 0)
  14.            Dim prosta As Ray = New Ray()
  15.            prosta.BasePoint = rePoint.Value
  16.            prosta.SecondPoint = rePoint2
  17.            Try
  18.                Dim btr As BlockTableRecord = trans.GetObject(acadBaza.CurrentSpaceId, OpenMode.ForWrite)
  19.                btr.AppendEntity(prosta)
  20.                trans.AddNewlyCreatedDBObject(prosta, True)
  21.                If selectResult.Status = PromptStatus.OK Then
  22.                    Dim ss As SelectionSet = selectResult.Value
  23.                    Dim idTab() As ObjectId = ss.GetObjectIds()
  24.                    Dim ra As Ray = CType(trans.GetObject(prosta.Id, OpenMode.ForRead), Ray)
  25.                    Dim ptc As Point3dCollection = New Point3dCollection()
  26.                    Dim intthis As Integer
  27.                    Dim intThat As Integer
  28.                    Dim objId As ObjectId
  29.                    For Each objId In idTab
  30.                        Dim ln As Line = CType(trans.GetObject(objId, OpenMode.ForRead), Line)
  31.                        ln.IntersectWith(ra, Intersect.OnBothOperands, ln.GetPlane(), ptc, intthis, intThat)
  32.                    Next
  33.                    Dim pts As Point3d
  34.                    Dim tmpPt As Point3d
  35.                    tmpPt = ptc.Item(0)
  36.                    Dim i As Integer
  37.                    If ptc.Count > 1 Then
  38.                        For i = 0 To ptc.Count - 1
  39.                            pts = ptc(i)
  40.                            If pts.X < tmpPt.X Then
  41.                                tmpPt = pts
  42.                            End If
  43.                        Next
  44.                    End If
  45.                    lineCmd.WriteMessage(tmpPt.ToString)
  46.                End If
  47.                trans.Commit()
  48.            Catch ex As Exception
  49.                lineCmd.WriteMessage("Wywalilo sie jakis wyjatek" + ex.Message)
  50.            Finally
  51.                trans.Dispose()
  52.            End Try
  53.        End If
  54.    End Sub

 
如果有人能纠正我在某些方面的错误,那就太好了
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 13:53:42 | 显示全部楼层
代码不错。
 
这里有一种可能的方法来检索适当的行。
 
 
包括:
 
导入系统。收藏。通用的
 
  1.     <CommandMethod("pts")> _
  2.        Public Sub pts()
  3.        Dim lineCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  4.        Dim acadBaza As Database = lineCmd.Document.Database
  5.        Dim trans As Transaction = acadBaza.TransactionManager.StartTransaction
  6.        Dim opPoint As PromptPointOptions = New PromptPointOptions("Kliknij srodek pomieszczenia :")
  7.        Dim rePoint As PromptPointResult = lineCmd.GetPoint(opPoint)
  8.        Dim crvDict As Dictionary(Of Double, Line) = New Dictionary(Of Double, Line)()
  9.        ' confstruction of filter
  10.        Dim typeValue() As TypedValue = {New TypedValue(0, "line")}
  11.        Dim selFilter As SelectionFilter = New SelectionFilter(typeValue)
  12.        Dim selectResult As PromptSelectionResult = lineCmd.SelectAll(selFilter)
  13.        If rePoint.Status = PromptStatus.OK Then
  14.            Dim rePoint2 As Point3d = New Point3d(rePoint.Value.X + 10, rePoint.Value.Y, 0)
  15.            Dim prosta As Ray = New Ray()
  16.            Dim tmpPt As Point3d
  17.            prosta.BasePoint = rePoint.Value
  18.            prosta.SecondPoint = rePoint2
  19.            Try
  20.                Dim btr As BlockTableRecord = trans.GetObject(acadBaza.CurrentSpaceId, OpenMode.ForWrite)
  21.                btr.AppendEntity(prosta)
  22.                trans.AddNewlyCreatedDBObject(prosta, True)
  23.                If selectResult.Status = PromptStatus.OK Then
  24.                    Dim ss As SelectionSet = selectResult.Value
  25.                    Dim idTab() As ObjectId = ss.GetObjectIds()
  26.                    Dim ra As Ray = CType(trans.GetObject(prosta.Id, OpenMode.ForRead), Ray)
  27.                    Dim ptc As Point3dCollection = New Point3dCollection()
  28.                    Dim intthis As Integer
  29.                    Dim intThat As Integer
  30.                    Dim objId As ObjectId
  31.                    Dim x As Double
  32.                    For Each objId In idTab
  33.                        Dim tempptc As Point3dCollection = New Point3dCollection()
  34.                        Dim ln As Line = CType(trans.GetObject(objId, OpenMode.ForRead), Line)
  35.                        ln.IntersectWith(ra, Intersect.OnBothOperands, ln.GetPlane(), tempptc, intthis, intThat)
  36.                        If tempptc.Count > 0 Then
  37.                            For Each pt As Point3d In tempptc
  38.                                x = Math.Round(pt.X, 6)
  39.                                crvDict.Add(x, ln) 'add line to dictionary with X coordinate as Key
  40.                                ptc.Add(pt)
  41.                            Next
  42.                        End If
  43.                    Next
  44.                    trans.Commit()
  45.                    If crvDict.Count > 0 Then
  46.                        Dim pts As Point3d
  47.                        tmpPt = ptc.Item(0)
  48.                        Dim i As Integer
  49.                        If ptc.Count > 1 Then
  50.                            For i = 0 To ptc.Count - 1
  51.                                pts = ptc(i)
  52.                                If pts.X < tmpPt.X Then
  53.                                    tmpPt = pts
  54.                                End If
  55.                            Next
  56.                        End If
  57.                        lineCmd.WriteMessage(tmpPt.ToString)
  58.                        crvDict(Math.Round(tmpPt.X, 6)).Highlight() 'Retrieve line based on X coordinate Key equal to tmpPt.X
  59.                        lineCmd.WriteMessage(" ObjectId: " & crvDict(Math.Round(tmpPt.X, 6)).ObjectId.ToString())
  60.                    Else
  61.                        lineCmd.WriteMessage("No intersections")
  62.                    End If
  63.                End If
  64.            Catch ex As Exception
  65.                lineCmd.WriteMessage("Wywalilo sie jakis wyjatek" + ex.Message)
  66.            Finally
  67.                trans.Dispose()
  68.            End Try
  69.        End If
  70.    End Sub
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-5 06:18 , Processed in 0.762487 second(s), 72 queries .

© 2020-2025 乐筑天下

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