明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1503|回复: 3

请教各位高手,该程序错在何处?头疼!!

[复制链接]
发表于 2003-8-21 11:22:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2003-8-25 13:32:42 编辑

本人用VB编了个小程序,在AutoCAD R14中创建填充圆,代码如下,为何运行出错?请不吝赐教!

   Option Explicit
Private Sub Command1_Click()
    Dim AcadApp As AcadApplication
    Dim AcadDoc As AcadDocument
    Set AcadApp = CreateObject("autocad.application")
    AcadApp.Visible = True
    Set AcadDoc = AcadApp.ActiveDocument

    Dim hatchObj As AcadHatch
    Dim patternName As String
    Dim patternType As Long
    Dim bAssociativity As Boolean
   
    patternName = "ANSI31"
    patternType = 0
    bAssociativity = True
    Set hatchObj = AcadDoc.ModelSpace.AddHatch _           
    (patternType, patternName, bAssociativity)                    
   
    Dim outerLoop(0 To 0) As AcadEntity
    Dim center(0 To 2) As Double
    Dim radius As Double
   
    center(0) = 50: center(1) = 50: center(2) = 0
    radius = 10
   
    Set outerLoop(0) = AcadDoc.ModelSpace.AddCircle(center, radius)
    hatchObj.AppendOuterLoop (outerLoop)
    hatchObj.Evaluate
    AcadDoc.Regen True
End Sub[em00]
发表于 2003-8-23 03:43:00 | 显示全部楼层
hi,there,

i just tested the code you pasted above, it seems like something wrong with the "Acadapplication" coz it is working well when i ticked out this part. you  can also get the info about it in help file which is quoted here:
VBA class name:AcadApplication
Create using:
For VB:
GetObject("AutoCAD.Application.16")
CreateObject("AutoCAD.Application.16")
For AutoCAD VBA:      ''*******pay attention here!!
Not applicable. The application is always available.

''***********************the working code here,enjoy************
Option Explicit
Sub command1_click()
   
   
    Dim Acaddoc As AcadDocument
        
    Set Acaddoc = ThisDrawing.Application.ActiveDocument

    Dim hatchobj As AcadHatch
    Dim patternname As String
    Dim patterntype As Long
    Dim bassociativity As Boolean
   
        patternname = "ansi31"
        patterntype = 0
        bassociativity = True
   
        Set hatchobj = ThisDrawing.ModelSpace.AddHatch(patterntype, patternname, bassociativity)
   
    Dim outerloop(0 To 0) As AcadEntity
    Dim center(0 To 2) As Double
    Dim radius As Double
   
        center(0) = 50: center(1) = 50: center(2) = 0
        radius = 10
   
        Set outerloop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)
        
        hatchobj.AppendOuterLoop (outerloop)
        hatchobj.Evaluate
      
    ZoomExtents
   
End Sub
 楼主| 发表于 2003-8-25 08:43:00 | 显示全部楼层
Thanks for your help!But the vision I used is R14(CHINESE),when I run your program,it still show that "类型不匹配”!(Set outerloop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius))。What's the wrong?!
发表于 2003-8-25 18:07:00 | 显示全部楼层
sorry, i have no idea about that coz i used autocad 2004 to make it.  :-)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-28 14:53 , Processed in 0.182110 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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