田草博客

互联网田草博客


网友交流QQ群:11740834 需注明申请加入原因

微信 公众号:ByCAD

邮箱:tiancao1001x126.com
ByCAD,微信公众号
首页 | 普通 | 电脑 | AutoCAD | VB/VB.NET | FLash | 结构 | 建筑 | 电影 | BIM | 规范 | 软件 | ID
-随机-|-分布-
-博客论坛-|-﨣﨤﨧﨨-
-网站导航-|-规范下载-
-BelovedFLash欣赏-

用户登陆
用户:
密码:
 

站点日历
73 2024 - 4 48
 123456
78910111213
14151617181920
21222324252627
282930


站点统计

最新评论



按住宅质量通病标准一键统一连梁腰筋 vb6.0中app.path转换到vb.net是什么
未知 CAD二次开发 CAD动画 蝴蝶曲线 Butterfly curve VB.net源码   [ 日期:2024-02-16 ]   [ 来自:本站原创 ]  HTML
B站视频:https://www.bilibili.com/video/BV1Hm411X7Rc/

按此在新窗口打开图片
按此在新窗口打开图片
程序代码:

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Public Class Butterfly_curve1
    ReadOnly R As Double = 100 '比例(半径)
    ReadOnly T_Total As Integer = 4320 '= 24*180 
    ReadOnly Pi As Double = Math.PI
    ReadOnly e As Double = Math.E

    ReadOnly acDc As Document = Application.DocumentManager.MdiActiveDocument
    ReadOnly acDb As Database = acDc.Database

    ReadOnly T1 As New Timer
    Dim I As Integer
    Dim Ps As New Point3d(0, 0, 0)
    <CommandMethod("TcHuDie")>
    Public Sub TcHuDie()
        '绘制之前清除以前绘制的,遍历所有对象并删除
        Using acTr As Transaction = acDb.TransactionManager.StartTransaction()
            Dim Block_Table As BlockTable = acTr.GetObject(acDb.BlockTableId, OpenMode.ForRead)
            Dim BlockRecord As BlockTableRecord = acTr.GetObject(Block_Table(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

            For Each EntId As ObjectId In BlockRecord
                Dim Ent As Entity = acTr.GetObject(EntId, OpenMode.ForWrite)
                Try
                    Ent.Erase()
                Catch ex As Exception
                    acDc.Editor.WriteMessage(vbCrLf & ex.Message)
                    Continue For
                End Try
            Next
            acTr.Commit()
        End Using

        '调整当前视口中心点为Point2d(0, 0)
        Dim viewTableRecord As ViewTableRecord = acDc.Editor.GetCurrentView()
        viewTableRecord.CenterPoint = New Point2d(0, 0)
        viewTableRecord.Height = 800
        viewTableRecord.Width = 800
        acDc.Editor.SetCurrentView(viewTableRecord)
        acDc.Editor.UpdateScreen()

        T1.Enabled = True
        T1.Interval = 5
        AddHandler T1.Tick, New EventHandler(AddressOf Timer1_Tick)
        T1.Start()
    End Sub
    Public Sub Timer1_Tick(ByVal sender As Object, ByVal _e As EventArgs)
        Dim docLock As Autodesk.AutoCAD.ApplicationServices.DocumentLock = acDc.LockDocument()
        I += 1 '增加1度(角度制)
        Dim T As Double = I * Pi / 180 '公式中的变量t
        Dim Sint As Double = Math.Sin(T)
        Dim Cost As Double = Math.Cos(T)
        Dim Cos4t As Double = Math.Cos(4 * T)
        Dim Sint5 As Double = Math.Sin(T / 24) ^ 5
        Dim x As Double = Sint * (e ^ Cost - 2 * Cos4t - Sint5) * R
        Dim y As Double = Cost * (e ^ Cost - 2 * Cos4t - Sint5) * R

        Dim Pe As New Point3d(x, y, 0)

        Dim L As New Line(Ps, Pe) With {
                .Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0)
            }
        AddEnt(L)

        Ps = Pe '紧接上一点

        '移动鼠标至当前点
        Dim point2 As System.Drawing.Point
        Dim handle As System.IntPtr = acDc.Window.Handle
        point2 = TcFunctions.CAD.ScreenFromWCSPoint_DPI(acDc.Editor, handle, Pe, 0)
        WinAPI_USER32.SetCursorPos(point2.X, point2.Y)

        acDc.Editor.UpdateScreen()

        '当t=24*Pi时 停止绘图
        If I >= T_Total Then
            I = 0
            RemoveHandler T1.Tick, New EventHandler(AddressOf Timer1_Tick)
        End If
    End Sub

    Public Shared Sub AddEnt(ByVal E As Entity)
        Dim acDc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acDb As Database = acDc.Database
        Using acTr As Transaction = acDc.TransactionManager.StartTransaction()
            Dim acBt As BlockTable
            acBt = acTr.GetObject(acDb.BlockTableId, OpenMode.ForWrite)
            Dim acBtRec As BlockTableRecord
            acBtRec = acTr.GetObject(acDb.CurrentSpaceId, OpenMode.ForWrite)
            acBtRec.AppendEntity(E)
            acTr.AddNewlyCreatedDBObject(E, True)
            acTr.Commit()
        End Using
    End Sub

    Private Declare Function ClientToScreen Lib "user32.dll" (ByVal hWnd As System.IntPtr,
                                                              ByRef pt As System.Drawing.Point) As Boolean
    Public Shared Function ScreenFromWCSPoint_DPI(ByVal acEd As Editor,
                                                  ByVal hWnd As System.IntPtr,
                                                  ByVal wcsPt As Point3d, ByVal _
                                                  vpNum As Short) As System.Drawing.Point
        Dim point1 As System.Windows.Point = acEd.PointToScreen(wcsPt, CInt(vpNum))
        Dim point2 As New System.Drawing.Point(CInt(point1.X * CurrentDPI()), CInt(point1.Y * CurrentDPI()))
        ClientToScreen(hWnd, point2)
        Return point2
    End Function

    'Dpi
    Public Shared Function CurrentDPI() As Double
        Return CDec((Graphics.FromHwnd(IntPtr.Zero).DpiX / 96.0F))
    End Function
End Class


[本日志由 tiancao1001 于 2024-02-16 10:08 PM 编辑]


暂时没有评论
发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:   注册? 验证:  防止恶意留言请输入问题答案:1*5=?  
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字

字体样式 文字大小 文字颜色
插入粗体文本 插入斜体文本 插入下划线
左对齐 居中对齐 右对齐
插入超级链接 插入邮件地址 插入图像
插入 Flash 插入代码 插入引用
插入列表 插入音频文件 插入视频文件
插入缩进符合
点击下载按钮 下标 上标
水平线 简介分割标记
表  情
 
Tiancao Blog All Rights Reserved 田草博客 版权所有
Copyright ©