Baber62 发表于 2022-7-6 07:02:26

测量线路长度

你好
 
我在别处找到的一些编码有问题。如果有人能告诉我如何调整编码使其工作,我将不胜感激。
 
<br><br> (vl-load-com)(defun c:MLin()<br>                (setvar “luprec” 2)<br>                (Cre_Lay “dist” 6)<br>                (setq disttot 0)<br>                (setq lines(ssget (list (cons 0 “line,pline,lwpolyline”))))<br>                (setq ctr 0)<br>                (if (/= lines nil)<br>                           (progn<br>                                             (setq len(sslength lines))<br>                                             (repeat len<br>                                                             (setq ent(ssname lines ctr))<br>                                                             (setq pntList(ReadPline ent))<br>                                                             (setq ptCntr 0)<br>                                                             (repeat (1- (length pntList))<br>                                                                               (setq fpoint(nth ptCntr pntList))<br>                                                                               (setq epoint(nth (1+ ptCntr) pntList))<br>                                                                               (setq thr(distance fpoint epoint))<br>                                                                               (setq fou(angle fpoint epoint))<br>                                                                               (setq ang(* (/ fou pi) 180))<br>                                                                               (if (and (>= ang 90) (<= ang 270)) (setq ang(rtos (+ ang 180))) (setq ang(rtos ang)))<br>                                                                               (setq txt_ins(MidP fpoint epoint))<br>                                                                               (command “._Text” “j” “bc” txt_ins “1.75″ ang (rtos thr))<br>                                                                               (command “._Change” (entlast) “” “p” “la” “dist” “”)<br>                                                                               (setq disttot(+ disttot (distance fpoint epoint)))<br>                                                                               (setq ptCntr(1+ ptCntr))<br>                                                             )<br>                                                             (setq ctr(1+ ctr))<br>                                             )<br>                                             (princ (strcat “\nTotal distance :” (rtos disttot 2 4)))<br>                           )<br>                )<br>                (princ)<br>)<br>(princ “\nType \”MLin\” to Measure each Segment of the Polyline.”) (princ); Function to find the mid point of two points.<br>(defun MidP(midp_fpo midp_spo)<br>                (setq midp_mpo(list (/ (+ (car midp_fpo) (car midp_spo)) 2) (/ (+ (cadrmidp_fpo) (cadr midp_spo)) 2)))<br>);Function to Create a Layer with given color.<br>(defun Cre_Lay(lay_layn lay_laycol)<br>               (if (= (tblsearch “Layer” lay_layn) nil)<br>                                        (command “._Layer” “n” lay_layn “c” lay_laycol lay_layn “”)<br>                                        (command “._Layer” “t” lay_layn “on” lay_layn “c” lay_laycol lay_layn “”)<br>               )<br>               (princ)<br>);Function to Read Vertices of Selected Lines.<br>(defun ReadPline(imp_Ent)<br>               (setq glb_obj(vlax-ename->vla-object imp_Ent))<br>               (setq glb_PntCnt(vlax-curve-getEndParam glb_obj))<br>               (setq returnPTList ‘())<br>               (setq ptCntr 1)<br>               (setq glb_oName(vlax-get-property glb_obj ‘ObjectName))<br>               (setq glb_OClosed nil)<br>               (if (= glb_oName “AcDbLine”)<br>                               (progn<br>                                                   (setq glb_EnDetails(entget imp_Ent))<br>                                                   (setq big_Point3d(cdr (assoc 10 glb_EnDetails)))<br>                                                   (setq end_Point3d(cdr (assoc 11 glb_EnDetails)))<br>                                                   (setq returnPTList(append returnPTList (list big_Point3d)))<br>                                                   (setq returnPTList(append returnPTList (list end_point3d)))<br>                               )<br>                               (progn<br>                                                   (setq glb_OClosed(vlax-curve-isClosed glb_obj))<br>                                                   (setq glb_2dDist 0)<br>                                                   (setq old_Point nil)<br>                                                   (repeat (1+ (fix glb_PntCnt))<br>                                                                   (setq cur_Point3d(vlax-curve getPointAtParam glb_obj (1- ptCntr)))<br>                                                                   (setq returnPTList(append returnPTList (list cur_Point3d)))<br>                                                                   (setq ptCntr(1+ ptCntr))<br>                                                    )<br>                              )<br>               )<br>               (setq return returnPTList)<br>)<br>
 
提前感谢您的帮助。

SLW210 发表于 2022-7-6 07:49:34

什么不起作用?

Baber62 发表于 2022-7-6 08:02:34

以下是我在运行此代码时收到的错误消息
 
命令:mlin
._层
当前层:“建议使用3个储物柜”
输入选项
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile:t
输入要解冻的图层的名称列表:dist输入选项
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile:打开
输入要启用的图层的名称列表:dist输入选项
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile:c
新颜色:6
输入颜色6(洋红)的图层名称列表:dist
输入选项
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:
命令:
选择对象:找到1个
选择对象:
错误:无函数定义:READPLINE;错误:内部发生错误
*错误*functionAutoCAD变量设置被拒绝:CLAYER nil
 
 
 
一旦我在MLIN中输入命令,它就会请求扫描对象,然后从那里退出,给出上面的消息。
页: [1]
查看完整版本: 测量线路长度