乐筑天下

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

反转弧的法线??

[复制链接]

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-8-3 23:41:48 | 显示全部楼层 |阅读模式
如果原始圆弧为0,0,-1,是否有人可以共享一些代码,将圆弧的法线反转到0,0,1 0 Then
               El(2) = P1(2)
               oMline.Move El, Zero
           End If
       End If
   ElseIf TypeOf Ent Is AcadCircle Then
       Set oCirc = Ent
       oCirc.Thickness = 0
       If N1(oCirc) Then
           oCirc.center = Z0(oCirc.center)
       End If
   ElseIf TypeOf Ent Is AcadArc Then
       Set oarc = Ent
       If oarc.center(2)  0 Then
            If isN(oarc) Then
                oarc.Thickness = 0
                If N1(oarc) Then
                    oarc.center = Z0(oarc.center)
                End If
            End If
       End If
   ElseIf TypeOf Ent Is AcadEllipse Then
       Set oEll = Ent
      
       If N1(oEll) Then
       Cen = oEll.center
       If Cen(2)  0 Then
           oEll.center = Z0(Cen)
        End If
           
       End If
   ElseIf TypeOf Ent Is AcadLWPolyline Then
       Set oPline = Ent
       oPline.Thickness = 0
       If N1(oPline) Then
           oPline.Elevation = 0
       End If
   ElseIf TypeOf Ent Is AcadHatch Then
       Set oHatch = Ent
       If N1(oHatch) Then
           oHatch.Elevation = 0
       End If
   ElseIf TypeOf Ent Is AcadSpline Then
       Set oSpline = Ent
       If oSpline.IsPlanar Then
           P1 = oSpline.FitPoints
           If UBound(P1)  0 Then
            If N1(oBref) Then
                oBref.InsertionPoint = Z0(ins)
                If oBref.HasAttributes Then
                    Atts = oBref.GetAttributes
                    For Each Att In Atts
                        Att.InsertionPoint = Z0(Att.InsertionPoint)
                        'Att.TextAlignmentPoint = Z0(Att.TextAlignmentPoint)
                    Next
                End If
            End If
       End If
   ElseIf TypeOf Ent Is AcadMText Or TypeOf Ent Is AcadText Then
        Dim Rot As Double
        Rot = Ent.Rotation
        If N1(Ent) Then
           If Ent.TextString = "" Then
               Ent.Delete
           Else
               ins = Ent.InsertionPoint
               If Not ins(2) = 0 Then
                   If Rot  0 Then
                    Ent.InsertionPoint = Z0(ins)
                   End If
               End If
               Ent.Rotation = Rot
           End If
       End If
   ElseIf TypeOf Ent Is AcadLeader Then
       Set oLeader = Ent
       P1 = oLeader.Normal
       If N1(oLeader) Then
           El(2) = oLeader.Coordinate(0)(2)
           oLeader.Move El, Zero
       End If
   ElseIf TypeOf Ent Is Acad3DFace Then
       Set oFace = Ent
       P1 = oFace.Coordinates
       For i = 0 To (UBound(P1) - 2) / 3
           P2 = oFace.Coordinate(i)
           P2(2) = 0
           oFace.Coordinate(i) = P2
       Next
   ElseIf TypeOf Ent Is AcadDimension Then
   'DimPointsToZero Ent
   End If
End Sub
Function Z0(P1 As Variant) As Variant
    P1(2) = 0
    Z0 = P1
End Function
Function N1(Ent As AcadEntity) As Boolean
    Dim N As Variant, Norm(2) As Double
    Dim oSpace As AcadBlock
    Dim oarc As AcadArc
    Dim newArc As AcadArc
    Dim newEll As AcadEllipse
    Dim oEll As AcadEllipse
    Dim oReg As AcadRegion
    Dim P1, P2
    Dim Sr As Double, Er As Double
    On Error GoTo Err_Control
    Norm(2) = 1
    N = Ent.Normal
    If Rd(N(0), 0) Then
        If Rd(N(1), 0) Then
            If Rd(N(2), 1) Then
                N1 = True
                If TypeOf Ent Is AcadRegion Or _
                       TypeOf Ent Is AcadLeader Then
                Else
                    Ent.Normal = Norm
                End If
            ElseIf Rd(N(2), -1) Then
                If TypeOf Ent Is AcadCircle Then
                    Ent.Normal = Norm
                    N1 = True
                ElseIf TypeOf Ent Is AcadArc Then
                    Set oarc = Ent
                    P1 = oarc.center
                    P1(2) = 0
                    Sr = Pi - oarc.endAngle
                    Er = Pi - oarc.startAngle
                    Set oSpace = ThisDrawing.ObjectIdToObject(Ent.OwnerID)
                    Set newArc = oSpace.AddArc(P1, oarc.radius, Sr, Er)
                    newArc.Layer = oarc.Layer
                    newArc.LineType = oarc.LineType
                    newArc.LinetypeScale = oarc.LinetypeScale
                    oarc.Delete
                 ElseIf TypeOf Ent Is AcadEllipse Then
                    Set oEll = Ent
                    P1 = oEll.center
                    P1(2) = 0
                    Sr = (2 * Pi) - oEll.endAngle
                    Er = (2 * Pi) - oEll.startAngle
                    
                    Set oSpace = ThisDrawing.ObjectIdToObject(Ent.OwnerID)
                    P2 = oEll.MajorAxis
                    P2(2) = 0
                    Set newEll = oSpace.AddEllipse(P1, P2, oEll.RadiusRatio)
                    With newEll
                        .startAngle = Sr
                        .endAngle = Er
                        .Layer = oEll.Layer
                        .LineType = oEll.LineType
                        .LinetypeScale = oEll.LinetypeScale
                        .TrueColor = oEll.TrueColor
                    End With
                    oEll.Delete
                ElseIf TypeOf Ent Is AcadRegion Then
                    Set oReg = Ent
                    MoveByBB oReg
                ElseIf TypeOf Ent Is AcadLeader Then
                    MoveByBB Ent
                ElseIf TypeOf Ent Is AcadBlockReference Then
                    Dim NegNorm(2) As Double
                    NegNorm(2) = -1
                    Ent.Normal = NegNorm
                    MoveByBB Ent
                    
                End If
               
            End If
        End If
    End If
Exit_Here:
    Exit Function
Err_Control:
    Select Case Err.Number
        Case -2145386371   'General modeling failure
        Debug.Print oEll.ObjectID
        Case Else
        'MsgBox Err.Description
        Debug.Print Err.Number, Err.Description
        Err.Clear
        Resume Exit_Here
    End Select
End Function
Function isN(oarc As AcadArc) As Boolean
    Dim N As Variant
    Dim NewN(2) As Double
    N = oarc.Normal
    If Abs(N(0))  0.9999 And Abs(N(2))  -1.0001 Then
                isN = True
                NewN(2) = -1
                oarc.Normal = NewN
                Exit Function
            End If
        End If
    End If
End Function
Function MoveByBB(Ent As AcadEntity)
    Dim Min, Max
    Ent.GetBoundingBox Min, Max
    If Rd(Min(2), Max(2)) Then
        Max = Min
        Max(2) = 0
        Ent.Move Min, Max
    End If
End Function
[/code]
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2006-8-4 00:04:10 | 显示全部楼层
嗨,戴夫。
也许这对你有帮助。
  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

(我认为对于region,此属性是只读模式)
~'J'~
回复

使用道具 举报

6

主题

103

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
127
发表于 2006-8-4 07:12:11 | 显示全部楼层
谢谢你们
戴夫
回复

使用道具 举报

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-8-4 07:27:07 | 显示全部楼层
布莱科,
我无法让你的代码工作。当我将 Rd 更改为 round 时,它似乎会通过,但我也必须删除 -1 行。弧线保持不变。
胖子,
我能够完成同样的事情。当您执行此操作时,弧线将移动并旋转。我想保持它看起来和位置与原始弧线完全相同。
谢谢
回复

使用道具 举报

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-8-4 10:05:08 | 显示全部楼层
这似乎有效。
  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,然后将其连接回折线,然后从折线创建一个区域。
我在我的代码中做了很多,所以这不是问题。如果有人需要一些东西,请告诉我。
回复

使用道具 举报

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-8-4 11:30:38 | 显示全部楼层
嘿,戴夫
说得好
很管用
~'J'~
回复

使用道具 举报

6

主题

103

帖子

2

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
127
发表于 2006-8-4 13:25:06 | 显示全部楼层
好办法,戴夫,我会用的
刚刚看到你的另一篇文章
  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

这对我很有用,但我仍在换你的。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-6 03:58 , Processed in 1.161502 second(s), 66 queries .

© 2020-2025 乐筑天下

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