您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 其它办公文档 > CAD中自动求和与自动求面积的解决方案
AutoCAD中数值自动求和与多段线自动计算面积和及长度和的解决方案一、数值的自动求和解决将下方阴影区程序复制,另建文本文档,打开粘贴后另存为“数值求和.lsp”,保存在常用软件备份目录下。在CAD启动完成后在命令行输入“ap”命令,在弹出的“加载/卸载应用程序”对话框中,查找存放的“数值求和.lsp”并点击“加载”,并可在启动组中填加该lsp文件。加载成功后,需要求和时,在命令行输入“sum”命令,然后选择需求和的数值,回车确认后即可在命令行见到求和结果。程序(阴影区全部复制);=============================Sumfunction=============================(DefunC:Sum(/cmdmodessetsslnssettempssl1total)(if*error*quit);ExitCADwhenerrorexists(setqcmdmode(getvarcmdecho));storethecontentofcmdechoinvariablecmdmode(setvarcmdecho0);(prompt\nSelectnumbers:)(setqsset(ssget))(if(nullsset)(progn(princ\nError:Nothingselected!\n)(princ))(progn(setqssl(sslengthsset));returnthelengthofsset(setqnsset(ssadd));constructanewnullselectionsset(while(ssl0)(setqtemp(ssnamesset(setqssl(1-ssl))));assignthess1thmembernameofssettotemp(if(=(cdr(assoc0(entgettemp)))TEXT)(ssaddtempnsset);addtemptonsset))(setqssl(sslengthnsset))(printssl)(princtextentitiesarefound.)(setqtotal0)(setqssl1ssl)(while(ssl0)(setqtemp(ssnamensset(setqssl(1-ssl))))(setqnumber(atof(cdr(assoc1(entgettemp)))))(if(=0number)(setqssl1(1-ssl1))(setqtotal(+totalnumber))))(princ\nTheSumofthe)(princssl1)(princnumbersselectedis)(princtotal)))(setqcmdechocmdmode)(princ));=============================End=======================================二、面积自动求和及多段线长度求和将下方阴影区程序复制,另建文本文档,打开粘贴后另存为“面积求和.lsp”,保存在常用软件备份目录下。在CAD启动完成后在命令行输入“ap”命令,在弹出的“加载/卸载应用程序”对话框中,查找存放的“面积求和.lsp”并点击“加载”,并可在启动组中填加该lsp文件。加载成功后,需要求和时,在命令行输入“am”命令,然后选择需求和的多段线,回车确认后即可在命令行见到求和结果。程序(阴影区全部复制)(defunC:am(/sslitotalareaenameobjentarea)(if(setqss(ssget))(progn(vl-load-com)(setqmodelspace(vla-get-Modelspace(vla-get-activeDocument(vlax-get-acad-object))))(setql(sslengthss)i0totalarea0totlength0)(repeatl(setqename(ssnamessi))(setqobj(vlax-ename-vla-objectename));;(vlax-dump-objectobjT)(if(vlax-property-available-pobjarea)(setqtotalarea(+(vlax-get-propertyobj'area)totalarea)))(if(=(cdr(assoc0(entgetename)))MLINE)(setqtotlength(+totlength(ml-lengthename)))(setqtotlength(+totlength(vlax-curve-getdistatparamename(vlax-curve-getendparamename)))))(setqi(1+i)))(setqtext1(strcat总面积为:(rtostotalarea24)平方毫米)text2(strcat总长度为:(rtostotlength24)毫米))(if(setqinsertpt(getpoint\n请输入文字插入点:))(if(setqheight(getdist\n请输入文字高度:))(setqinsertp1(vlax-3d-pointinsertpt)insertp2(vlax-3d-point(polarinsertpt(*1.5Pi)(*1.5height)))textobj1(vla-addtextmodelspacetext1insertp1height)textobj2(vla-addtextmodelspacetext2insertp2height)))))))(defunml-length(ename/jdptlist)(foreachn(entgetename)(if(=(carn)11)(setqptlist(cons(cdrn)ptlist))))(reverseptlist)(setqj0d0)(repeat(1-(lengthptlist))(setqd(+d(distance(nthjptlist)(nth(1+j)ptlist))))(setqj(1+j)))d)本文仅供交流学习
本文标题:CAD中自动求和与自动求面积的解决方案
链接地址:https://www.777doc.com/doc-5801634 .html