乐筑天下

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

反转弧的法线??

[复制链接]

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-8-3 23:41:48 | 显示全部楼层 |阅读模式
如果原始弧为0,0,-1,是否有人可以共享一些代码,将弧的法线反转为0.0,1
谢谢,戴夫
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-8-4 00:04:10 | 显示全部楼层
戴夫,我认为有3种观点认为,改变正常的生活方式是没有反应的。弧,区域,某物
你必须做一个新的,很烦人
请仔细阅读下面的代码
  1. Sub FlattenThis(Ent As AcadEntity)
  2.    
  3.     Dim obj As AcadEntity
  4.     Dim oLine As AcadLine
  5.     Dim oMline As AcadMLine
  6.     Dim oCirc As AcadCircle
  7.     Dim oarc As AcadArc
  8.     Dim oEll As AcadEllipse
  9.     Dim oPline As AcadLWPolyline
  10.     Dim oHatch As AcadHatch
  11.     Dim oSpline As AcadSpline
  12.     Dim oReg As AcadRegion
  13.     Dim oPoint As AcadPoint
  14.     Dim oBref As AcadBlockReference
  15.     Dim oMt As AcadMText
  16.     Dim oLeader As AcadLeader
  17.     Dim Atts, Att
  18.     Dim P1, P2, P3
  19.     Dim Min, Max
  20.     Dim ins, Cen
  21.     Dim Zero(2) As Double, El(2) As Double
  22.     Dim i As Integer
  23.     Dim oFace As Acad3DFace
  24.    
  25.    If TypeOf Ent Is AcadLine Then
  26.        Set oLine = Ent
  27.        oLine.Thickness = 0
  28.        oLine.StartPoint = Z0(oLine.StartPoint)
  29.        oLine.EndPoint = Z0(oLine.EndPoint)
  30.        If oLine.Length = 0 Then oLine.Delete
  31.    ElseIf TypeOf Ent Is AcadMLine Then
  32.        Set oMline = Ent
  33.        P1 = oMline.Coordinates
  34.        If P1(2) = P1(5) Then
  35.            If P1(2)  0 Then
  36.                El(2) = P1(2)
  37.                oMline.Move El, Zero
  38.            End If
  39.        End If
  40.    ElseIf TypeOf Ent Is AcadCircle Then
  41.        Set oCirc = Ent
  42.        oCirc.Thickness = 0
  43.        If N1(oCirc) Then
  44.            oCirc.center = Z0(oCirc.center)
  45.        End If
  46.    ElseIf TypeOf Ent Is AcadArc Then
  47.        Set oarc = Ent
  48.        If oarc.center(2)  0 Then
  49.             If isN(oarc) Then
  50.                 oarc.Thickness = 0
  51.                 If N1(oarc) Then
  52.                     oarc.center = Z0(oarc.center)
  53.                 End If
  54.             End If
  55.        End If
  56.    ElseIf TypeOf Ent Is AcadEllipse Then
  57.        Set oEll = Ent
  58.       
  59.        If N1(oEll) Then
  60.        Cen = oEll.center
  61.        If Cen(2)  0 Then
  62.            oEll.center = Z0(Cen)
  63.         End If
  64.            
  65.        End If
  66.    ElseIf TypeOf Ent Is AcadLWPolyline Then
  67.        Set oPline = Ent
  68.        oPline.Thickness = 0
  69.        If N1(oPline) Then
  70.            oPline.Elevation = 0
  71.        End If
  72.    ElseIf TypeOf Ent Is AcadHatch Then
  73.        Set oHatch = Ent
  74.        If N1(oHatch) Then
  75.            oHatch.Elevation = 0
  76.        End If
  77.    ElseIf TypeOf Ent Is AcadSpline Then
  78.        Set oSpline = Ent
  79.        If oSpline.IsPlanar Then
  80.            P1 = oSpline.FitPoints
  81.            If UBound(P1)  0 Then
  82.             If N1(oBref) Then
  83.                 oBref.InsertionPoint = Z0(ins)
  84.                 If oBref.HasAttributes Then
  85.                     Atts = oBref.GetAttributes
  86.                     For Each Att In Atts
  87.                         Att.InsertionPoint = Z0(Att.InsertionPoint)
  88.                         'Att.TextAlignmentPoint = Z0(Att.TextAlignmentPoint)
  89.                     Next
  90.                 End If
  91.             End If
  92.        End If
  93.    ElseIf TypeOf Ent Is AcadMText Or TypeOf Ent Is AcadText Then
  94.         Dim Rot As Double
  95.         Rot = Ent.Rotation
  96.         If N1(Ent) Then
  97.            If Ent.TextString = "" Then
  98.                Ent.Delete
  99.            Else
  100.                ins = Ent.InsertionPoint
  101.                If Not ins(2) = 0 Then
  102.                    If Rot  0 Then
  103.                     Ent.InsertionPoint = Z0(ins)
  104.                    End If
  105.                End If
  106.                Ent.Rotation = Rot
  107.            End If
  108.        End If
  109.    ElseIf TypeOf Ent Is AcadLeader Then
  110.        Set oLeader = Ent
  111.        P1 = oLeader.Normal
  112.        If N1(oLeader) Then
  113.            El(2) = oLeader.Coordinate(0)(2)
  114.            oLeader.Move El, Zero
  115.        End If
  116.    ElseIf TypeOf Ent Is Acad3DFace Then
  117.        Set oFace = Ent
  118.        P1 = oFace.Coordinates
  119.        For i = 0 To (UBound(P1) - 2) / 3
  120.            P2 = oFace.Coordinate(i)
  121.            P2(2) = 0
  122.            oFace.Coordinate(i) = P2
  123.        Next
  124.    ElseIf TypeOf Ent Is AcadDimension Then
  125.    'DimPointsToZero Ent
  126.    End If
  127. End Sub
  128. Function Z0(P1 As Variant) As Variant
  129.     P1(2) = 0
  130.     Z0 = P1
  131. End Function
  132. Function N1(Ent As AcadEntity) As Boolean
  133.     Dim N As Variant, Norm(2) As Double
  134.     Dim oSpace As AcadBlock
  135.     Dim oarc As AcadArc
  136.     Dim newArc As AcadArc
  137.     Dim newEll As AcadEllipse
  138.     Dim oEll As AcadEllipse
  139.     Dim oReg As AcadRegion
  140.     Dim P1, P2
  141.     Dim Sr As Double, Er As Double
  142.     On Error GoTo Err_Control
  143.     Norm(2) = 1
  144.     N = Ent.Normal
  145.     If Rd(N(0), 0) Then
  146.         If Rd(N(1), 0) Then
  147.             If Rd(N(2), 1) Then
  148.                 N1 = True
  149.                 If TypeOf Ent Is AcadRegion Or _
  150.                        TypeOf Ent Is AcadLeader Then
  151.                 Else
  152.                     Ent.Normal = Norm
  153.                 End If
  154.             ElseIf Rd(N(2), -1) Then
  155.                 If TypeOf Ent Is AcadCircle Then
  156.                     Ent.Normal = Norm
  157.                     N1 = True
  158.                 ElseIf TypeOf Ent Is AcadArc Then
  159.                     Set oarc = Ent
  160.                     P1 = oarc.center
  161.                     P1(2) = 0
  162.                     Sr = Pi - oarc.endAngle
  163.                     Er = Pi - oarc.startAngle
  164.                     Set oSpace = ThisDrawing.ObjectIdToObject(Ent.OwnerID)
  165.                     Set newArc = oSpace.AddArc(P1, oarc.radius, Sr, Er)
  166.                     newArc.Layer = oarc.Layer
  167.                     newArc.LineType = oarc.LineType
  168.                     newArc.LinetypeScale = oarc.LinetypeScale
  169.                     oarc.Delete
  170.                  ElseIf TypeOf Ent Is AcadEllipse Then
  171.                     Set oEll = Ent
  172.                     P1 = oEll.center
  173.                     P1(2) = 0
  174.                     Sr = (2 * Pi) - oEll.endAngle
  175.                     Er = (2 * Pi) - oEll.startAngle
  176.                     
  177.                     Set oSpace = ThisDrawing.ObjectIdToObject(Ent.OwnerID)
  178.                     P2 = oEll.MajorAxis
  179.                     P2(2) = 0
  180.                     Set newEll = oSpace.AddEllipse(P1, P2, oEll.RadiusRatio)
  181.                     With newEll
  182.                         .startAngle = Sr
  183.                         .endAngle = Er
  184.                         .Layer = oEll.Layer
  185.                         .LineType = oEll.LineType
  186.                         .LinetypeScale = oEll.LinetypeScale
  187.                         .TrueColor = oEll.TrueColor
  188.                     End With
  189.                     oEll.Delete
  190.                 ElseIf TypeOf Ent Is AcadRegion Then
  191.                     Set oReg = Ent
  192.                     MoveByBB oReg
  193.                 ElseIf TypeOf Ent Is AcadLeader Then
  194.                     MoveByBB Ent
  195.                 ElseIf TypeOf Ent Is AcadBlockReference Then
  196.                     Dim NegNorm(2) As Double
  197.                     NegNorm(2) = -1
  198.                     Ent.Normal = NegNorm
  199.                     MoveByBB Ent
  200.                     
  201.                 End If
  202.                
  203.             End If
  204.         End If
  205.     End If
  206. Exit_Here:
  207.     Exit Function
  208. Err_Control:
  209.     Select Case Err.Number
  210.         Case -2145386371   'General modeling failure
  211.         Debug.Print oEll.ObjectID
  212.         Case Else
  213.         'MsgBox Err.Description
  214.         Debug.Print Err.Number, Err.Description
  215.         Err.Clear
  216.         Resume Exit_Here
  217.     End Select
  218. End Function
  219. Function isN(oarc As AcadArc) As Boolean
  220.     Dim N As Variant
  221.     Dim NewN(2) As Double
  222.     N = oarc.Normal
  223.     If Abs(N(0))  0.9999 And Abs(N(2))  -1.0001 Then
  224.                 isN = True
  225.                 NewN(2) = -1
  226.                 oarc.Normal = NewN
  227.                 Exit Function
  228.             End If
  229.         End If
  230.     End If
  231. End Function
  232. Function MoveByBB(Ent As AcadEntity)
  233.     Dim Min, Max
  234.     Ent.GetBoundingBox Min, Max
  235.     If Rd(Min(2), Max(2)) Then
  236.         Max = Min
  237.         Max(2) = 0
  238.         Ent.Move Min, Max
  239.     End If
  240. End Function

回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-8-4 07:12:11 | 显示全部楼层
嗨,Dave,也许这对你有帮助
  1. Sub PutArcNormal()
  2. Dim oArc As AcadEntity
  3. Dim pickPnt As Variant
  4. Dim norVec As Variant
  5. Dim vecStr As String
  6. ThisDrawing.Utility.GetEntity oArc, pickPnt, vbCr & "Select arc"
  7. If TypeOf oArc Is AcadArc Then
  8. norVec = oArc.Normal
  9.    vecStr = Replace(CStr(norVec(0)), ",", ".") & "," & _
  10.             Replace(CStr(norVec(1)), ",", ".") & "," & _
  11.             Replace(CStr(norVec(2)), ",", ".")
  12. MsgBox "Current normal is: " & vecStr
  13. norVec(0) = 0#: norVec(1) = 0#: norVec(2) = 1#:
  14. oArc.Normal = norVec
  15. oArc.Update
  16.    vecStr = Replace(CStr(norVec(0)), ",", ".") & "," & _
  17.             Replace(CStr(norVec(1)), ",", ".") & "," & _
  18.             Replace(CStr(norVec(2)), ",", ".")
  19. MsgBox "Normal changed to: " & vecStr
  20. Else
  21. MsgBox "This is not an arc"
  22. Exit Sub
  23. End If
  24. End Sub

(我认为对于区域,此属性是只读模式)
<fatty~&039;J#039~
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-8-4 07:27:07 | 显示全部楼层
谢谢大家
几小时后我会试一试
戴夫
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-8-4 10:05:08 | 显示全部楼层
Bryco,
我无法让你使用代码。当我将Rd改为圆形时,它似乎已经通过了,但我也不得不删除-1行。弧保持不变
脂肪,
我能够完成同样的事情。当你这样做时,弧线将移动和漫游。我想保持它的外观和位置与原来的弧完全相同。谢谢
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-8-4 11:30:38 | 显示全部楼层
这似乎有效
  1. Sub ReverseArcNormal()
  2.    
  3. Dim oArc As AcadArc
  4. Dim ent As AcadEntity
  5. Dim STPoint(0 To 2) As Double
  6. Dim ENPoint(0 To 2) As Double
  7. Dim rotateAngle As Double
  8. Dim midpoint(0 To 2) As Double
  9. rotateAngle = 180
  10. rotateAngle = rotateAngle * 3.14159265358979 / 180#
  11.    
  12. For Each ent In thisdrawing.ModelSpace
  13.    
  14.   If TypeOf ent Is AcadArc Then
  15.        Set oArc = ent
  16.             
  17.        STPoint(0) = oArc.StartPoint(0)
  18.        STPoint(1) = oArc.StartPoint(1)
  19.        STPoint(2) = oArc.StartPoint(2)
  20.       
  21.        ENPoint(0) = oArc.EndPoint(0)
  22.        ENPoint(1) = oArc.EndPoint(1)
  23.        ENPoint(2) = oArc.EndPoint(2)
  24.            
  25.        oArc.Rotate3D STPoint, ENPoint, rotateAngle
  26.        midpoint(0) = (STPoint(0) + ENPoint(0)) / 2
  27.        midpoint(1) = (STPoint(1) + ENPoint(1)) / 2
  28.        midpoint(2) = (STPoint(2) + ENPoint(2)) / 2
  29.       
  30.        oArc.Rotate midpoint, rotateAngle
  31.   
  32.    End If
  33.            
  34. Next
  35. End Sub
对于没有样条线的区域,需要分解该区域,将直线和圆弧法线(2)设置为1,并将其连接回多段线,然后从多段线创建一个区域
我在代码中经常这样做,所以这不是问题。如果有人需要什么,请告诉我
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-8-4 13:25:06 | 显示全部楼层
嘿,戴夫,好点子,很有魅力;J#039~
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-8-4 17:24:49 | 显示全部楼层
好的解决方案Dave,I&#039;我要用它
刚刚看到你的另一篇帖子
  1. Sub d()
  2. Dim ent As AcadEntity, v
  3. ThisDrawing.Utility.GetEntity ent, v
  4. FlattenThis ent
  5. End Sub
  6. Function Rd(num1 As Variant, num2 As Variant) As Boolean
  7.     Dim dRet As Double
  8.     dRet = num1 - num2
  9.     If Abs(dRet) < 0.00000001 Then Rd = True
  10. End Function
这对我来说很有效,但我&#039;我还在换你的。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-6 03:07 , Processed in 0.830873 second(s), 68 queries .

© 2020-2025 乐筑天下

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