GetEntity获得ObjectID,到Excel程序
<p>从AutoCAD调用excel的功能函数</p><p>Function xlSheet() As Object</p><p> Dim xlApp As Object ' This Line ,Not set Excel , run Excel<br/> 'Dim xlsheet As Object<br/> <br/> ' 发生错误时跳到下一个语句继续执行<br/> On Error Resume Next<br/> ' 连接Excel应用程序<br/> Set xlApp = GetObject(, "Excel.Application")<br/> <br/> If Err.Number <> 0 Then<br/> Set xlApp = CreateObject("Excel.Application")<br/> xlApp.Visible = True<br/> xlApp.Workbooks.Add<br/> End If</p><p> ' 返回当前活动的工作表<br/> Set xlSheet = xlApp.ActiveSheet<br/>End Function</p><p>主程序, 获取Entity的ObjectID,传输到Excel</p><p>Sub lls()<br/> ' Begin the selection<br/> Dim returnObj As AcadObject<br/> Dim basePnt As Variant<br/> <br/> On Error Resume Next<br/> ii = 1<br/> ' The following example waits for a selection from the user<br/>RETRY:<br/> ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select an object"<br/> <br/> If Err <> 0 Then<br/> Err.Clear<br/> MsgBox "Program ended.", , "GetEntity Example"<br/> Exit Sub<br/> Else<br/> returnObj.Update<br/> MsgBox "The object type is: " & returnObj.EntityName, , "GetEntity Example"<br/> returnObj.Update<br/> End If<br/> <br/> xlSheet.cells(ii, 5).Value = returnObj.ObjectID<br/> ii = ii + 1<br/> GoTo RETRY</p><p> <br/>End Sub</p><p>以下是一个辅助程序</p><p>Sub Example_GetEntity()<br/> ' This example creates several objects in model space. It then<br/> ' prompts the user to select an object. The example continues to<br/> ' have the user select objects until the user selects in empty space.<br/> <br/> ' Create a Ray object in model space<br/> Dim rayObj As AcadRay<br/> Dim basePoint(0 To 2) As Double<br/> Dim SecondPoint(0 To 2) As Double<br/> basePoint(0) = 3#: basePoint(1) = 3#: basePoint(2) = 0#<br/> SecondPoint(0) = 1#: SecondPoint(1) = 3#: SecondPoint(2) = 0#<br/> Set rayObj = ThisDrawing.ModelSpace.AddRay(basePoint, SecondPoint)<br/> <br/> ' Create a polyline object in model space<br/> Dim plineObj As AcadLWPolyline<br/> Dim points(0 To 5) As Double<br/> points(0) = 3: points(1) = 7<br/> points(2) = 9: points(3) = 2<br/> points(4) = 3: points(5) = 5<br/> Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)<br/> plineObj.Closed = True</p><p> ' Create a line object in model space<br/> Dim lineObj As AcadLine<br/> Dim startPoint(0 To 2) As Double<br/> Dim endPoint(0 To 2) As Double<br/> startPoint(0) = 0: startPoint(1) = 0: startPoint(2) = 0<br/> endPoint(0) = 2: endPoint(1) = 2: endPoint(2) = 0<br/> Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)<br/> <br/> ' Create a circle object in model space<br/> Dim circObj As AcadCircle<br/> Dim centerPt(0 To 2) As Double<br/> Dim radius As Double<br/> centerPt(0) = 20: centerPt(1) = 30: centerPt(2) = 0<br/> radius = 3<br/> Set circObj = ThisDrawing.ModelSpace.AddCircle(centerPt, radius)</p><p> ' Create an ellipse object in model space<br/> Dim ellObj As AcadEllipse<br/> Dim majAxis(0 To 2) As Double<br/> Dim center(0 To 2) As Double<br/> Dim radRatio As Double<br/> center(0) = 5#: center(1) = 5#: center(2) = 0#<br/> majAxis(0) = 10: majAxis(1) = 20#: majAxis(2) = 0#<br/> radRatio = 0.3<br/> Set ellObj = ThisDrawing.ModelSpace.AddEllipse(center, majAxis, radRatio)</p><p> ZoomExtents<br/> <br/>End Sub<br/></p>
页:
[1]