获取CAD中线的每个节点坐标程序设计_第1页
获取CAD中线的每个节点坐标程序设计_第2页
获取CAD中线的每个节点坐标程序设计_第3页
获取CAD中线的每个节点坐标程序设计_第4页
获取CAD中线的每个节点坐标程序设计_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 获取cad中线的每个节点坐标,线包括polyline、3d polyline、spline等等!程序代码如下:imports systemimports system.ioimports system.mathpublic class 获取cad中点坐标public acadapp as autocad.acadapplicationpublic xx(), yy(), zz() as doublepublic count as integerpublic returnobj as objectpublic folderpath as string = c:/public stepnum a

2、s integer = 0private declare auto function setprocessworkingsetsize lib kernel32.dll (byval prochandle as intptr, byval min as int32, byval max as int32) as booleanpublic sub setprocessworkingsetsize() 节约系统内存trydim mem as processmem = process.getcurrentprocess()setprocessworkingsetsize(mem.handle, -

3、1, -1)catch ex as exceptionmsgbox(ex.tostring)end tryend subpublic sub 启动cad()on error resume nextacadapp = getobject(, autocad.application)if err.number thenerr.clear()acadapp = createobject(autocad.application)end ifacadapp.visible = trueacadapp.windowstate = autocad.acwindowstate.acmaxappactivate

4、(acadapp.caption)end subpublic sub 获取样条线节点坐标()dim i as integerfor i = 0 to 10000 step stepnumon error goto handle01count = iredim preserve xx(i)redim preserve yy(i)redim preserve zz(i)xx(i) = returnobj.coordinate(i)(0)yy(i) = returnobj.coordinate(i)(1)zz(i) = returnobj.elevationnexthandle01:count =

5、count - 1end subpublic sub 获取spline线节点坐标()dim fitpoints as objectdim i as integerfor i = 0 to returnobj.numberofcontrolpoints - 1 step stepnumfitpoints = returnobj.getcontrolpoint(i)count = iredim preserve xx(i)redim preserve yy(i)redim preserve zz(i)xx(i) = fitpoints(0)yy(i) = fitpoints(1)zz(i) = f

6、itpoints(2)nextend subpublic sub 获取spline线拟合点坐标()dim fitpoints as objectdim pp as autocad.acadsplinedim i as integerfor i = 0 to returnobj.numberoffitpoints - 1 step stepnumfitpoints = returnobj.getfitpoint(i)count = iredim preserve xx(i)redim preserve yy(i)redim preserve zz(i)xx(i) = fitpoints(0)yy

7、(i) = fitpoints(1)zz(i) = fitpoints(2)nextend subpublic sub 获取line线节点坐标()dim startpoints as objectdim endpoints as objectredim preserve xx(1)redim preserve yy(1)redim preserve zz(1)count = 1returnobj.highlight(true)startpoints = returnobj.startpointendpoints = returnobj.endpointxx(0) = startpoints(0

8、)yy(0) = startpoints(1)zz(0) = startpoints(2)xx(1) = endpoints(0)yy(1) = endpoints(1)zz(1) = endpoints(2)end subpublic sub 获取2dpolyline节点坐标()dim sss as autocad.acadlwpolylinereturnobj.highlight(true)dim i as integerfor i = 0 to 10000 step stepnumon error goto handle01count = iredim preserve xx(i)red

9、im preserve yy(i)redim preserve zz(i)xx(i) = returnobj.coordinate(i)(0)yy(i) = returnobj.coordinate(i)(1)zz(i) = returnobj.elevationnexthandle01:count = count - 1end subprivate sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.clickon error goto handle01ca

10、ll 启动cad()dim basepnt as objectacadapp.activedocument.utility.getentity(returnobj, basepnt)returnobj.highlight(true)判断线的类型dim linetypenname as stringlinetypenname = returnobj.objectname.tostring()if linetypenname = acdbline thencall 获取line线节点坐标()elseif linetypenname = acdbspline thencall 获取spline线节点

11、坐标()elseif linetypenname = acdbpolyline thencall 获取样条线节点坐标()else : exit subend ifif textbox1.text 0 or textbox2.text 0 or textbox4.text 0 thencall calculatecoordinate()end ifdim i as integerdim s as string = for i = 0 to counts = s + xx(i).tostring() + , + yy(i).tostring() + , + zz(i).tostring() + c

12、hr(13)nextrichtextbox1.text = sbutton3.enabled = trueappactivate(me.text)exit subhandle01:msgbox(err.description)end subprivate sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.clickon error goto handle01dim dg as new openfiledialogdg.filter = cad files (

13、*.dwg)|*.dwg|all files (*.*)|*.*dg.showdialog()dim s as string = dg.filenameif s = then exit sub启动cad()acadapp.application.documents.open(s)acadapp.activedocument.windowstate = autocad.acwindowstate.acmaxappactivate(me.text)button1.enabled = trueexit subhandle01:msgbox(err.description)end subprivate

14、 sub button3_click(byval sender as system.object, byval e as system.eventargs) handles button3.clickon error goto handle01dim dg as new savefiledialogdg.filter = txt files (*.txt)|*.txt|dat files (*.dat)|*.datdg.showdialog()dim s as string = dg.filenamedim i as integerdim s1 as string = using sw as

15、streamwriter = new streamwriter(s)for i = 0 to counts1 = xx(i).tostring() + , + yy(i).tostring() + , + zz(i).tostring()sw.writeline(s1)nextsw.close()end usingexit subhandle01:msgbox(err.description)end subprivate sub button4_click(byval sender as system.object, byval e as system.eventargs) handles b

16、utton4.clickacadapp.activedocument.regen(autocad.acregentype.acactiveviewport)end subpublic sub calculatecoordinate()on error goto handle01dim x0, y0, rotangle as doublex0 = textbox1.texty0 = textbox2.textrotangle = (textbox4.text) * 3.1415926 / 180dim i as integerdim x1, y1 as doubleif cos(rotangle

17、) = 0 thenfor i = 0 to countx1 = xx(i)xx(i) = yy(i) - y0yy(i) = x0 - x1nextexit subend iffor i = 0 to county1 = (yy(i) - y0 - (xx(i) - x0) * tan(rotangle) * cos(rotangle)x1 = (xx(i) - x0) / cos(rotangle) + y1 * tan(rotangle)if abs(x1) 0.00001 then x1 = 0 设置精度if abs(y1) 0.00001 then y1 = 0xx(i) = x1y

18、y(i) = y1nextexit subhandle01:msgbox(err.description)end subprivate sub textbox2_textchanged(byval sender as system.object, byval e as system.eventargs) handles textbox2.textchangedend subprivate sub 批量获取节点坐标button_click(byval sender as system.object, byval e as system.eventargs) handles 批量获取节点坐标but

19、ton.clickstatic exitnum as integeron error goto handle01static savenum as integercall 启动cad()dim basepnt as objectacadapp.activedocument.utility.getentity(returnobj, basepnt)returnobj.highlight(true)acadapp.activedocument.sendcommand(选取下一条线!连续在空白地方点击两次将会自动退出批量存储状态! + vbcr)判断线的类型dim linetypenname as

20、stringlinetypenname = returnobj.objectname.tostring()if linetypenname = acdbline thencall 获取line线节点坐标()elseif linetypenname = acdbspline thencall 获取spline线节点坐标()elseif linetypenname = acdbpolyline thencall 获取样条线节点坐标()end ifif textbox1.text 0 or textbox2.text 0 or textbox4.text 0 thencall calculateco

21、ordinate()end ifdim j as integerdim s1 as string = using sw as streamwriter = new streamwriter(folderpath + savenum.tostring() + .txt)for j = 0 to counts1 = xx(j).tostring() + , + yy(j).tostring() + , + zz(j).tostring()sw.writeline(s1)nextsw.close()savenum = savenum + 1end usingexitnum = 0call 批量获取节

22、点坐标button_click(sender, e)exit subhandle01:exitnum = exitnum + 1if exitnum = 2 thenexitnum = 0exit subelse : call 批量获取节点坐标button_click(sender, e)end ifend subprivate sub 设置文件保存路径button5_click(byval sender as system.object, byval e as system.eventargs) handles 设置文件保存路径button5.clickdim fdg as folderbr

23、owserdialogfdg = new folderbrowserdialogfdg.showdialog()if fdg.selectedpath = then exit subfolderpath = fdg.selectedpathend subprivate sub button5_click(byval sender as system.object, byval e as system.eventargs) handles button5.clickon error goto handle01call 启动cad()dim sset as autocad.acadselectio

24、nsetsset = acadapp.activedocument.selectionsets.add(newselectionset) 提示用户选择对象sset.selectonscreen()dim ent as objectdim sss as autocad.acadpointcount = -1for each ent in ssetif ent.objectname = acdbpoint thencount = count + 1redim preserve xx(count)redim preserve yy(count)redim preserve zz(count)xx(c

25、ount) = ent.coordinates(0)yy(count) = ent.coordinates(1)zz(count) = ent.coordinates(2)end ifnext entif textbox1.text 0 or textbox2.text 0 or textbox4.text 0 thencall calculatecoordinate()end ifdim i as integerdim s as string = for i = 0 to counts = s + xx(i).tostring() + , + yy(i).tostring() + , + z

26、z(i).tostring() + chr(13)nextrichtextbox1.text = sacadapp.activedocument.selectionsets.item(newselectionset).delete()appactivate(me.text)button3.enabled = trueexit subhandle01:acadapp.activedocument.selectionsets.item(newselectionset).delete()button5_click(sender, e)msgbox(err.description)end subpri

27、vate sub button6_click_1(byval sender as system.object, byval e as system.eventargs) handles button6.clickon error goto handle01acadapp.activedocument.save()handle01:msgbox(err.description)end subprivate sub button7_click(byval sender as system.object, byval e as system.eventargs) handles button7.cl

28、ickcall 启动cad()dim basepnt as objectacadapp.activedocument.utility.getentity(returnobj, basepnt)returnobj.highlight(true)appactivate(acadapp.caption)dim i as integerfor i = 0 to 500on error goto handle01count = iredim preserve xx(i)redim preserve yy(i)redim preserve zz(i)xx(i) = returnobj.coordinate

29、(i)(0)yy(i) = returnobj.coordinate(i)(1)zz(i) = returnobj.coordinate(i)(2)nexthandle01:count = count - 1dim j as integerdim s as string = for j = 0 to counts = s + xx(j).tostring() + , + yy(j).tostring() + , + zz(j).tostring() + chr(13)nextrichtextbox1.text = sbutton3.enabled = trueappactivate(me.te

30、xt)end subprivate sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.loadcall setprocessworkingsetsize()end subprivate sub button8_click(byval sender as system.object, byval e as system.eventargs) handles button8.clickon error goto handle01call 启动cad()dim basep

31、nt as objectacadapp.activedocument.utility.getentity(returnobj, basepnt)returnobj.highlight(true)call 获取2dpolyline节点坐标()if textbox1.text 0 or textbox2.text 0 or textbox4.text 0 thencall calculatecoordinate()end ifdim i as integerdim s as string = for i = 0 to counts = s + xx(i).tostring() + , + yy(i

32、).tostring() + , + zz(i).tostring() + chr(13)nextrichtextbox1.text = sbutton3.enabled = trueappactivate(me.text)exit subhandle01:msgbox(err.description)end subprivate sub button9_click(byval sender as system.object, byval e as system.eventargs) handles button9.clickcall 启动cad()dim basepnt as objectb

33、asepnt = acadapp.activedocument.utility.getpoint()msgbox(当前点击坐标位置为: + basepnt(0).tostring() + , + basepnt(1).tostring()end subprivate sub 打开cad文件otoolstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 打开cad文件otoolstripmenuitem.clickon error goto handle01dim dg as

34、 new openfiledialogdg.filter = cad files (*.dwg)|*.dwg|all files (*.*)|*.*dg.showdialog()dim s as string = dg.filenameif s = then exit sub启动cad()acadapp.application.documents.open(s)acadapp.activedocument.windowstate = autocad.acwindowstate.acmaxappactivate(me.text)button1.enabled = trueexit subhand

35、le01:msgbox(err.description)end subprivate sub 保存cad文件ctoolstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 保存cad文件ctoolstripmenuitem.clickon error goto handle01acadapp.activedocument.save()exit subhandle01:msgbox(err.description)end subprivate sub 保存坐标数据文件stoo

36、lstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 保存坐标数据文件stoolstripmenuitem.click on error goto handle01 dim dg as new savefiledialog dg.filter = txt files (*.txt)|*.txt|dat files (*.dat)|*.dat dg.showdialog() dim s as string = dg.filename dim i as integer dim

37、 s1 as string = using sw as streamwriter = new streamwriter(s) for i = 0 to count s1 = xx(i).tostring() + , + yy(i).tostring() + , + zz(i).tostring() sw.writeline(s1) next sw.close() end using exit sub handle01: msgbox(err.description) end subprivate sub 刷新cad图形rtoolstripmenuitem_click(byval sender

38、as system.object, byval e as system.eventargs) handles 刷新cad图形rtoolstripmenuitem.click on error goto handle01 acadapp.activedocument.regen(autocad.acregentype.acactiveviewport) exit sub handle01: msgbox(err.description) end sub private sub 退出etoolstripmenuitem1_click(byval sender as system.object, b

39、yval e as system.eventargs) handles 退出etoolstripmenuitem1.click on error goto handle01 application.exit() exit sub handle01: msgbox(err.description) end sub private sub 获取线条上节点坐标ltoolstripmenuitem1_click(byval sender as system.object, byval e as system.eventargs) handles 获取线条上节点坐标ltoolstripmenuitem1

40、.click on error goto handle01 call 启动cad() dim basepnt as object acadapp.activedocument.utility.getentity(returnobj, basepnt) returnobj.highlight(true) 判断线的类型 dim linetypenname as string linetypenname = returnobj.objectname.tostring() if linetypenname = acdbline then call 获取line线节点坐标() elseif linety

41、penname = acdbspline then call 获取spline线拟合点坐标() elseif linetypenname = acdbpolyline then call 获取样条线节点坐标() else : exit sub end if if textbox1.text 0 or textbox2.text 0 or textbox4.text 0 then call calculatecoordinate() end if dim i as integer dim s as string = for i = 0 to count s = s + xx(i).tostrin

42、g() + , + yy(i).tostring() + , + zz(i).tostring() + chr(13) next richtextbox1.text = s button3.enabled = true appactivate(me.text) exit sub handle01: msgbox(err.description) end sub private sub 获取多段线上节点坐标stoolstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 获取多

43、段线上节点坐标stoolstripmenuitem.click on error goto handle01 call 启动cad() dim basepnt as object acadapp.activedocument.utility.getentity(returnobj, basepnt) returnobj.highlight(true) 判断线的类型 dim linetypenname as string linetypenname = returnobj.objectname.tostring() if linetypenname = acdbpolyline then cal

44、l 获取样条线节点坐标() else : exit sub end if if textbox1.text 0 or textbox2.text 0 or textbox4.text 0 then call calculatecoordinate() end if dim i as integer dim s as string = for i = 0 to count s = s + xx(i).tostring() + , + yy(i).tostring() + , + zz(i).tostring() + chr(13) next richtextbox1.text = s button3.enabled = true appactivate(me.text) exit sub handle01: msgbox(err.description) end sub private sub 获取样条线上节点坐标toolstripmenuitem_click(byval sender as system.object, byval e as system.eventargs) handles 获取样

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论