乐筑天下

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

[编程交流] 路径阵列

[复制链接]

6

主题

25

帖子

19

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 03:45:14 | 显示全部楼层 |阅读模式
大家好,
 
我试图沿路径排列一个块,使块上的两个点与路径相交,并且这些点彼此重合。
 
与下图类似,如果线所在的地方有块。
 
044520g46jioin8npjzyog.jpg
 
我尝试了内置的路径数组以及测量和除法命令,但没有成功。
 
感谢您的帮助。
 
当做
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 04:02:56 | 显示全部楼层
这是一个vba程序,允许沿pline插入块。它基本上可以满足您的需要,但需要修改以满足您的块长度需要。我将代码作为源代码发布,它基本上需要2个点,并使用intersectwith来计算块角度。我们用它来检查车辆的车道。
 
  1. Sub draw_vehicle()
  2. Dim CAR As String
  3. Dim arcobj As AcadArc
  4. Dim oPoly As AcadEntity
  5. Dim blkobj As AcadEntity
  6. Dim retVal As Variant
  7. Dim snapPt As Variant
  8. Dim oCoords As Variant
  9. Dim blpnt1() As Variant
  10. ReDim blpnt1(100)
  11. Dim blpnt2() As Variant
  12. ReDim blpnt2(100)
  13. Dim vertPt(0 To 2) As Double
  14. Dim Pt1(0 To 2) As Double
  15. Dim Pt2(0 To 2) As Double
  16. Dim newPt(0 To 2) As Double
  17. Dim iCnt, w, x, y, z As Integer
  18. Dim cRad, interval, blkangle As Double
  19. Dim circObj As AcadCircle
  20. Dim lineObj As AcadLine
  21. On Error GoTo Something_Wrong
  22. If ThisDrawing.ActiveSpace = acModelSpace Then
  23. Set Thisspace = ThisDrawing.ModelSpace
  24. Else: Set Thisspace = ThisDrawing.PaperSpace
  25. End If
  26. For Each Item In ThisDrawing.Blocks
  27. If Item.Name = "holden" Then GoTo continue_on
  28. Next Item
  29. ' insert holden block
  30. InsertBlock "p:\Autodesk\vba\holdencar.dwg", 0
  31. continue_on:
  32. w = 1
  33. ThisDrawing.Utility.GetEntity oPoly, snapPt, vbCr & "Select polyline :"
  34. If oPoly.ObjectName = "AcDbPolyline" Then
  35. oCoords = oPoly.Coordinates
  36. Else: MsgBox "This object is not a polyline! Please do again"
  37. Exit Sub
  38. End If
  39. interval = CDbl(InputBox("Enter interval:", , 1#))
  40. If interval < 1 Then
  41. interval = 1
  42. End If
  43. For iCnt = 0 To UBound(oCoords) - 2 Step 2
  44. Pt1(0) = oCoords(iCnt): Pt1(1) = oCoords(iCnt + 1): Pt1(2) = 0#
  45. newPt(0) = Pt1(0)
  46. newPt(1) = Pt1(1)
  47. newPt(2) = 0#
  48. iCnt = iCnt + 2
  49. Pt2(0) = oCoords(iCnt): Pt2(1) = oCoords(iCnt + 1): Pt2(2) = 0#
  50. x = (Pt1(0) - Pt2(0)) / interval
  51. y = (Pt1(1) - Pt2(1)) / interval
  52. 'reset back 2 values
  53. iCnt = iCnt - 2
  54. cRad = 3.05
  55. startang = 4.71239
  56. endang = 1.570796
  57. CAR = "HOLDEN"
  58. For z = 1 To interval
  59. vertPt(0) = newPt(0) - x
  60. vertPt(1) = newPt(1) - y
  61. vertPt(2) = 0#
  62. 'blpnt1(w) = vertPt
  63. 'Set arcobj = ThisDrawing.ModelSpace.AddArc(vertPt, cRad, endang, startang)
  64. Set arcobj = Thisspace.AddArc(vertPt, cRad, endang, startang)
  65. retval2 = arcobj.IntersectWith(oPoly, acExtendOtherEntity)
  66. arcobj.Delete
  67. Set arcobj = Nothing
  68. blkangle = ThisDrawing.Utility.AngleFromXAxis(retval2, vertPt)
  69. 'Set blkobj = ThisDrawing.ModelSpace.InsertBlock(vertPt, CAR, 1#, 1#, 1#, blkangle)
  70. Set blkobj = Thisspace.InsertBlock(vertPt, CAR, 1#, 1#, 1#, blkangle)
  71. Set blkobj = Nothing
  72. w = w + 1
  73. newPt(0) = newPt(0) - x
  74. newPt(1) = newPt(1) - y
  75. Next z
  76. Next iCnt
  77. GoTo Exit_out
  78. Something_Wrong:
  79. MsgBox Err.Description
  80. Exit_out:
  81. End Sub
  82.    Function InsertBlock(ByVal blockpath As String, ByVal rotation As Double)
  83.    Dim blockobj As AcadBlockReference
  84.    Dim insertionPnt As Variant
  85.    Dim prompt1 As String
  86.    'set rotation Angle
  87.    rotateAngle = rotation
  88.    'rotateAngle = rotation * 3.141592 / 180#
  89.    'Prompt is used to show instructions in the command bar
  90.    prompt1 = vbCrLf & "Enter block insert point: "
  91.    'ThisDrawing.ActiveSpace = acModelSpace
  92.    insertionPnt = ThisDrawing.Utility.GetPoint(, prompt1)
  93.    Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, blockpath, 1#, 1#, 1#, rotateAngle)
  94.    'Change Modelspace into Paperspace to insert the block into Paperspace
  95.    End Function
回复

使用道具 举报

6

主题

25

帖子

19

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 04:22:00 | 显示全部楼层
谢谢比格尔,这是一个很好的开始。我可以看到明显的变化,如路径和块名称等,但我想我会坚持修改,以适应我的块相交点是11590mm的距离。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 04:36:34 | 显示全部楼层
只需更改Crad 3.05是车轮之间的距离,为了更准确,请使用PI的真实值作为VBA变量。Startang Endang,创建一个11590mm的块水平线给它你的名字,而不是霍尔顿应该工作的话。
回复

使用道具 举报

6

主题

25

帖子

19

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 04:46:17 | 显示全部楼层
好的,我设法让VBA运行,改变了一些事情,但没有任何运气得到它太阵列。该程序似乎不允许我在块上选择2个点,这将是路径上的交点,对吗?
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 18:25 , Processed in 0.786871 second(s), 65 queries .

© 2020-2025 乐筑天下

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