明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1365|回复: 0

GetEntity获得ObjectID,到Excel程序

[复制链接]
发表于 2007-7-28 17:13:00 | 显示全部楼层 |阅读模式

AutoCAD调用excel的功能函数

Function xlSheet() As Object

    Dim xlApp As Object  ' This Line ,Not set Excel , run Excel
    'Dim xlsheet As Object
   
    ' 发生错误时跳到下一个语句继续执行
    On Error Resume Next
    ' 连接Excel应用程序
    Set xlApp = GetObject(, "Excel.Application")
   
    If Err.Number <> 0 Then
        Set xlApp = CreateObject("Excel.Application")
        xlApp.Visible = True
        xlApp.Workbooks.Add
    End If

    ' 返回当前活动的工作表
    Set xlSheet = xlApp.ActiveSheet
End Function

主程序, 获取Entity的ObjectID,传输到Excel

Sub lls()
    ' Begin the selection
    Dim returnObj As AcadObject
    Dim basePnt As Variant
   
    On Error Resume Next
    ii = 1
    ' The following example waits for a selection from the user
RETRY:
    ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select an object"
   
    If Err <> 0 Then
        Err.Clear
        MsgBox "Program ended.", , "GetEntity Example"
        Exit Sub
    Else
        returnObj.Update
        MsgBox "The object type is: " & returnObj.EntityName, , "GetEntity Example"
        returnObj.Update
    End If
   
    xlSheet.cells(ii, 5).Value = returnObj.ObjectID
    ii = ii + 1
    GoTo RETRY

 
End Sub

以下是一个辅助程序

Sub Example_GetEntity()
    ' This example creates several objects in model space. It then
    ' prompts the user to select an object. The example continues to
    ' have the user select objects until the user selects in empty space.
   
    ' Create a Ray object in model space
    Dim rayObj As AcadRay
    Dim basePoint(0 To 2) As Double
    Dim SecondPoint(0 To 2) As Double
    basePoint(0) = 3#: basePoint(1) = 3#: basePoint(2) = 0#
    SecondPoint(0) = 1#: SecondPoint(1) = 3#: SecondPoint(2) = 0#
    Set rayObj = ThisDrawing.ModelSpace.AddRay(basePoint, SecondPoint)
   
    ' Create a polyline object in model space
    Dim plineObj As AcadLWPolyline
    Dim points(0 To 5) As Double
    points(0) = 3: points(1) = 7
    points(2) = 9: points(3) = 2
    points(4) = 3: points(5) = 5
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    plineObj.Closed = True

    ' Create a line object in model space
    Dim lineObj As AcadLine
    Dim startPoint(0 To 2) As Double
    Dim endPoint(0 To 2) As Double
    startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0
    endPoint(0) = 2: endPoint(1) = 2: endPoint(2) = 0
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)
   
    ' Create a circle object in model space
    Dim circObj As AcadCircle
    Dim centerPt(0 To 2) As Double
    Dim radius As Double
    centerPt(0) = 20: centerPt(1) = 30: centerPt(2) = 0
    radius = 3
    Set circObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)

    ' Create an ellipse object in model space
    Dim ellObj As AcadEllipse
    Dim majAxis(0 To 2) As Double
    Dim center(0 To 2) As Double
    Dim radRatio As Double
    center(0) = 5#: center(1) = 5#: center(2) = 0#
    majAxis(0) = 10: majAxis(1) = 20#: majAxis(2) = 0#
    radRatio = 0.3
    Set ellObj = ThisDrawing.ModelSpace.AddEllipse(center, majAxis, radRatio)

    ZoomExtents
   
End Sub

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-30 02:50 , Processed in 0.171956 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表