乐筑天下

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

将闭合 LWPolyline 转换为 2D 折线

[复制链接]

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-6-21 22:16:25 | 显示全部楼层 |阅读模式
只是以为我会分享这个。我做了一些更改,但不记得原始代码来自哪里。
  1. Private Function polyentconvert2(polyEnt As Object) As AcadPolyline
  2. Dim entity As AcadDocument
  3. Set entity = AutoCAD_Application.ActiveDocument
  4. Dim I As Integer, j As Integer, K As Integer
  5. Dim EN2 As AcadPolyline
  6. Dim b As Double, w As Double, W2 As Double
  7. Dim PolyZPosition As Double
  8. Dim polyentx As AcadPolyline
  9. Dim FromNewPoint(0 To 2) As Double
  10. Dim MoveNewPoint(0 To 2) As Double
  11. If polyEnt.EntityName = "AcDbPolyline" Then
  12.   Dim Coords As Variant
  13.   Coords = polyEnt.Coordinates
  14.   I = Fix((UBound(Coords) + 1) * 1.5) - 1
  15.   
  16.   If I = 5 Then
  17.   
  18.   GoTo newconvert
  19.   
  20.   End If
  21.   ReDim Coords2(I) As Double
  22.   j = 0
  23.   Dim X As Double, y As Double, z As Double
  24.   
  25.   For I = LBound(Coords) To UBound(Coords) Step 2
  26.     X = Coords(I): y = Coords(I + 1): z = 0#
  27.     Coords2(j) = X:
  28.     Coords2(j + 1) = y:
  29.     Coords2(j + 2) = z:
  30.     j = j + 3
  31.   Next I
  32.   Dim Coords2V As Variant
  33.   Coords2V = Coords2
  34.   Set EN2 = entity.ModelSpace.AddPolyline(Coords2V)
  35.   EN2.Closed = polyEnt.Closed
  36.   EN2.Color = polyEnt.Color
  37.   EN2.Linetype = polyEnt.Linetype
  38.   EN2.Thickness = polyEnt.Thickness
  39.     EN2.Layer = polyEnt.Layer
  40.    
  41.   
  42.   For I = 0 To UBound(Coords) Step 2
  43.     j = I / 2
  44.     b = polyEnt.GetBulge(j)
  45.     polyEnt.GetWidth j, w, W2
  46.     EN2.SetBulge j, b
  47.     EN2.SetWidth j, w, W2
  48.   Next I
  49.   
  50.   
  51.   Set polyentx = EN2
  52.   
  53.   polyEnt.GetBoundingBox minExt, maxExt
  54.   PolyZPosition = Round(maxExt(2), 5)
  55.                
  56.                
  57.   polyEnt.Delete
  58.   
  59.     FromNewPoint(0) = 0
  60.     FromNewPoint(1) = 0
  61.     FromNewPoint(2) = 0
  62.     MoveNewPoint(0) = 0
  63.     MoveNewPoint(1) = 0
  64.     MoveNewPoint(2) = PolyZPosition
  65.     EN2.Move FromNewPoint, MoveNewPoint
  66. End If
  67. GoTo endhere
  68. newconvert:
  69. I = I + 3
  70. ReDim Coords2(I) As Double
  71. Dim newcords As Variant
  72. On Error Resume Next
  73. Coords2(0) = Coords(0)
  74. Coords2(1) = Coords(1)
  75. Coords2(2) = 0
  76. Coords2(3) = Coords(2)
  77. Coords2(4) = Coords(3)
  78. Coords2(5) = 0
  79. Coords2(6) = Coords(0)
  80. Coords2(7) = Coords(1)
  81. Coords2(8) = 0
  82. newcords = Coords2
  83.     Set EN2 = entity.ModelSpace.AddPolyline(newcords)
  84.     EN2.Closed = polyEnt.Closed
  85.     EN2.Color = polyEnt.Color
  86.     EN2.Linetype = polyEnt.Linetype
  87.     EN2.Thickness = polyEnt.Thickness
  88.     EN2.Layer = polyEnt.Layer
  89.   For I = 0 To UBound(Coords) Step 2
  90.     j = I / 2
  91.     b = polyEnt.GetBulge(j)
  92.     EN2.SetBulge j, b
  93.   Next I
  94.   polyEnt.GetBoundingBox minExt, maxExt
  95.   PolyZPosition = Round(maxExt(2), 5)
  96.                
  97.                
  98.   polyEnt.Delete
  99.   
  100.     FromNewPoint(0) = 0
  101.     FromNewPoint(1) = 0
  102.     FromNewPoint(2) = 0
  103.     MoveNewPoint(0) = 0
  104.     MoveNewPoint(1) = 0
  105.     MoveNewPoint(2) = PolyZPosition
  106.     EN2.Move FromNewPoint, MoveNewPoint
  107. endhere:
  108. End Function

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

10

主题

63

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
103
发表于 2006-6-22 02:21:54 | 显示全部楼层
我很好奇在什么样的情况下,人们会更喜欢2dPolyline而不是LwPolyline? 我总是以相反的方式执行转换。谢谢。
回复

使用道具 举报

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-6-22 02:39:40 | 显示全部楼层
Kelie,
我的软件的一部分在3D实体上做功能识别。一旦我有了从3D实体中分解的线条和弧线,我就运行Pedit将事物连接成折线。将 PLintype 系统变量设置为 2 时,它在复杂路径上工作得更好。这将生成一个 LWPolyline。然后,我的软件输出到13个不同的CAM软件。其中一些只能识别2DPolyline。
格伦,
只是避免命令行的另一种时间方式我希望我有一个好的例程,将片段连接成折线,而不是使用pedit,但似乎没有其他东西比我尝试过的更好。
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-6-23 09:57:14 | 显示全部楼层
试试这里http://www.theswamp.org/index.php?topic=10290.msg131276#msg13127它是用cnc编写的
回复

使用道具 举报

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-6-23 10:29:31 | 显示全部楼层

非常感谢。我知道我在这里看到了一些代码,我想尝试一下,但忘记了它在哪里。目前没有时间,但几天后我会认真检查。我确信这是任何地方最好的代码。
You RAWK!
再次感谢并保重,
Dave
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-5 23:31 , Processed in 1.500179 second(s), 62 queries .

© 2020-2025 乐筑天下

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