欢迎来到天天文库
浏览记录
ID:35623721
大小:283.75 KB
页数:33页
时间:2019-04-03
《vb6.0与autocad2006编程教程整理》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、1.用VB6.0打开AutoCAD2006(1)新建工程,在VisualBasic下引用AutoCAD对象模型库;工程——引用(勾选AutoCAD2006TypeLibrary),如图1.1所示。图1.1勾选AutoCAD2006TypeLibrary(2)在工程中添加按钮1,修改其caption为“打开CAD”,如图1.2所示。图1.2添加按钮(3)双击按钮,并添加代码。DimmyAcadAppAsAutoCAD.AcadApplicationDimactiveDocAsAutoCAD.AcadDocumentDimacMSAsAu
2、toCAD.AcadModelSpacePrivateSubCommand1_Click()OnErrorResumeNextSetmyAcadApp=GetObject(,"Autocad.Application")'检查AutoCAD是否已经打开IfErr<>0Then'没有打开Err.ClearSetmyAcadApp=CreateObject("Autocad.Application")'打开CADIfErrThenMsgBoxErr.Number&":"&Err.Description'打开失败ExitSubEndIfEnd
3、IfOnErrorGoToprcERRmyAcadApp.Visible=True'显示CADSetactiveDoc=myAcadApp.ActiveDocumentprcERR:SetactiveDoc=NothingSetmyAcadApp=NothingEndSub或如下代码(下面所有代码均基于此代码):DimacadappAsAcadApplication'定义为Acad的好像都该放在前面DimactiveDocAsAcadDocument'用于复制线(DimLineObjAsAcadLine'要放到前面,否则无法运行Pri
4、vateSubCommand1_Click()OnErrorResumeNextSetacadapp=GetObject(,"AutoCAD.Application")'如果AutoCAD已经运行,则获取AutoCAD的Application对象IfErrThenErr.ClearSetacadapp=CreateObject("AutoCAD.Application")'如果AutoCAD没有运行,则启动AutoCAD,创建Application对象IfErrThenMsgBoxErr.DescriptionExitSubEndIf
5、EndIfacadapp.Visible=TrueEndSub(4)运行→启动(F5),点击按钮,打开AutoCAD2006。2.画直线(1)添加按钮2“画直线”,双击按钮,输入下列代码。SubCommand2_Click()DimstartPoint(0To2)AsDoubleDimendPoint(0To2)AsDoubleDimLineObjAsAcadLineSetactiveDoc=acadapp.ActiveDocumentstartPoint(0)=0:startPoint(1)=0:startPoint(2)=0end
6、Point(0)=30:endPoint(1)=20:endPoint(2)=0SetLineObj=activeDoc.ModelSpace.AddLine(startPoint,endPoint)'画线EndSub(2)运行→启动(F5),点击按钮(先点击“打开CAD”,再点击“画直线”,若直接点击“画直线”会出错),画线。3.画弧(1))添加按钮3“画弧”,双击按钮,输入下列代码。SubCommand3_Click()DimarcObjAsAcadArcDimcenterPoint(0To2)AsDoubleDimradiusA
7、sDoubleDimstartAngleInDegreeAsDoubleDimendAngleInDegreeAsDoubleSetactiveDoc=acadapp.ActiveDocumentcenterPoint(0)=0#:centerPoint(1)=0#:centerPoint(2)=0#radius=5#startAngleInDegree=10#endAngleInDegree=230#DimstartAngleInRadianAsDoubleDimendAngleInRadianAsDoublestartAngleI
8、nRadian=startAngleInDegree*3.141592/180#endAngleInRadian=endAngleInDegree*3.141592/180#SetarcObj=activeDoc.Mod
此文档下载收益归作者所有