明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2082|回复: 3

[求助]请帮修改自编的多段线与曲线相互转换程序(lisp)

[复制链接]
发表于 2007-12-5 22:59:00 | 显示全部楼层 |阅读模式

自编一段多段线与曲线相互转换程序,想将转换后的线保持和原线一样的颜色、线型、线型比例、线宽和图层。但只能改变颜色,其它的不能改变,不知什么原因,请高手帮看看错在哪能里?
程序如下:
(defun c:lpsp ()

    (setq ss (car(entsel"\n请选择曲线、多段线: ")))
    (setq endata (entget ss))               ;取出对象(多段线)ssn的信息列表赋于endata
    (setq s0 (cdr (assoc 0 endata)))        ;取得原实体线型名称
    (entdel ss)                             ;删除要修改的线
    (if (= s0 "LWPOLYLINE") (progn          ;如果是多段线
        (setq kd 10)                        ;判断坐标的参数为10
        (command "_spline")                 ;启动画曲线命令
    ))
    (if (= s0 "SPLINE") (progn              ;如果是曲线
        (setq kd 11)                        ;判断坐标的参数为11
        (command "_pline")                  ;启动画多段线命令
    ))
    (setq n 0 ptn '())
    (repeat (length endata)
            (setq pt (nth n endata))          ;依次取得信息列表的子表
            (setq x (car pt))                
            (if (= x kd) (command (cdr pt)))  ;判断是否是坐标点,是就画线
            (setq n (+ n 1))
    )
    (if (= s0 "LWPOLYLINE") (command "" "" ""))   ;多段线画线结束
    (if (= s0 "SPLINE") (command ""))             ;曲线画线结束
    (setq f1 (cdr (assoc 62 endata)))    ;取得ss的颜色
    (setq f2 (cdr (assoc 6 endata)))     ;取得ss的线型
    (setq f3 (cdr (assoc 48 endata)))    ;取得ss的线型比例
    (setq f4 (cdr (assoc 370 endata)))   ;取得ss的线宽
    (setq f5 (cdr (assoc 8 endata)))     ;取得ss的图层
    (command "_chprop" (entlast) "" "c" f1 "")          ;新线的颜色
    (command "_chprop" (entlast) "" "it" f2 "")         ;新线的线型
    (command "_chprop" (entlast) "" "s" f3 "")          ;新线的线型比例
    (command "_chprop" (entlast) "" "lw" f4 "")         ;新线的线宽
    (command "_chprop" (entlast) "" "la" f5 "")         ;新线的图层
)
 

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2007-12-5 23:47:00 | 显示全部楼层
LT写成it了。有时用大写字母有优势,可以看出是否写错了。
  1. (defun c:lpsp ()
  2. (setq ss (car(entsel "\n请选择曲线、多段线: ")))
  3. (setq endata (entget ss))               ;取出对象(多段线)ssn的信息列表赋于endata
  4. (setq s0 (cdr (assoc 0 endata)))        ;取得原实体线型名称
  5. (entdel ss)                             ;删除要修改的线
  6. (if (= s0 "LWPOLYLINE") (progn          ;如果是多段线
  7.   (setq kd 10)                        ;判断坐标的参数为10
  8.   (setq ff (= (cdr (assoc 70 endata)) 1))
  9.   (command "_spline")                 ;启动画曲线命令
  10. ))
  11. (if (= s0 "SPLINE") (progn              ;如果是曲线
  12.   (setq kd 11)                        ;判断坐标的参数为11
  13.   (setq ff (= (cdr (assoc 70 endata)) 1))
  14.   (command "_pline")                  ;启动画多段线命令
  15. ))
  16. (setq n 0 ptn '())
  17. (repeat (length endata)
  18.   (setq pt (nth n endata))          ;依次取得信息列表的子表
  19.   (setq x (car pt))                 
  20.   (if (= x kd) (command (cdr pt)))  ;判断是否是坐标点,是就画线
  21.   (setq n (+ n 1))
  22. )
  23. (if (= s0 "LWPOLYLINE") (command (if ff "c" "") "" ""))   ;多段线画线结束
  24. (if (= s0 "SPLINE") (command (if ff "c" "")))             ;曲线画线结束
  25. (setq f1 (cdr (assoc 62 endata)))    ;取得ss的颜色
  26. (setq f2 (cdr (assoc 6 endata)))     ;取得ss的线型
  27. (setq f3 (cdr (assoc 48 endata)))    ;取得ss的线型比例
  28. (setq f4 (cdr (assoc 370 endata)))   ;取得ss的线宽
  29. (setq f5 (cdr (assoc 8 endata)))     ;取得ss的图层
  30. (command "_chprop" "L" "" "C" f1)          ;新线的颜色
  31. (command "_chprop" "L" "" "LT" f2)         ;新线的线型
  32. (command "_chprop" "L" "" "S" f3)          ;新线的线型比例
  33. (command "_chprop" "L" "" "LW" f4)         ;新线的线宽
  34. (command "_chprop" "L" "" "LA" f5 "")         ;新线的图层
  35. (princ)
  36. )
 楼主| 发表于 2007-12-6 11:48:00 | 显示全部楼层
谢谢楼上朋友的细心,我总以为是什么大问题,谁知问题出在细节上。
发表于 2011-10-27 14:19:47 | 显示全部楼层
东西不错。很实用
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-25 05:00 , Processed in 0.170592 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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