吴琦 发表于 2013-1-2 19:50:51

求高手帮忙,判断文字在段范围内

本帖最后由 吴琦 于 2013-1-3 15:22 编辑

小弟初学lisp,实在想不明白怎么判断,求助明经各位大侠,第一次发帖,多支持下新手
条件是这样的
1.未知数目文字在同一直线上且旋转角度相同,文字角度0~360度都有可能
2.有多段直线段平行文字(可以简单的认为这多条直线在同一直线上),文字到线的距离可能正数,可能负数,也可能为零
3.文字无序分布在各条线段上

问题:如何判断哪些文字在哪些线段上?
然后怎么把这些文字分配到这些直线呢
因为lisp的变量好像不能带自变量的,比如L(i)这种表示方法行不通,
怎么把这线直线进行编号,然后把文字列出来,像下面这样
Line1-----text1.....text3
Line2-----text4text5 text6 text6 text7
Line3-----text8
...........
Linen----..........-textm









USER2128 发表于 2013-1-2 19:50:52

本帖最后由 USER2128 于 2013-1-3 18:13 编辑


(defun c:tt ()
(setq line-pts '()
cnt 0)
(if (setq lines (ssget '((0 . "line"))))
    (progn
      (repeat (sslength lines)
(setq ent (entget (ssname lines cnt))
       line-pts (cons (list (cdr (assoc 10 ent))
       (cdr (assoc 11 ent)))
      line-pts)
       cnt (1+ cnt)
       ))
      (setq line-pts (reverse line-pts))
      (setq txtent (mapcar '(lambda(u)
(progn
   (setq x (car u)
y (cadr u))
   (setq dist (* (distance x y) 0.5)
ang(angle x y))
   (setq pt1 (polar x (+ (* pi 1.5) ang) dist)
pt2 (polar pt1 ang (* dist 2))
pt3 (polar y (+ (* pi 0.5) ang) dist)
pt4 (polar pt3 (+ ang pi) (* dist 2))
)
   (setq txtmp (ssget "_WP" (list pt1 pt2 pt3 pt4) '((0 . "TEXT"))))
   txtmp
   )) line-pts))
      (setq txts (mapcar '(lambda(x)
      (progn
   (setq cnt 0
txtmp '())
   (repeat (if x (sslength x) 0)
   (setq txtmp (cons (cdr (assoc 1 (entget (ssname x cnt))))
         txtmp))
   (setq cnt (1+ cnt))
   )
   txtmp)) txtent))
      (setq cnt 1)
      (mapcar '(lambda(x y z)
(progn
   (setq h (cdr (assoc 40 (entget (ssname y 0))))
h (/ h 1.25)
tmp (polar (car x) (angle (cadr x) (car x)) h)
)
   
   (entmake (list '(0 . "CIRCLE") (cons 10 tmp) (cons 40 h)))
   (entmake (list '(0 . "TEXT") (cons 1 (itoa cnt))
    (cons 40 (* h 1.25))
    (cons 50 0.0) '(71 . 0) '(72 . 1) '(73 . 2)
    (cons 10 tmp) (cons 11 tmp)))
   (princ (strcat "\nLine" (itoa cnt) ":\t"))
   (mapcar '(lambda(u) (princ u) (princ "\t")) z)
   (setq cnt (1+ cnt))
   )) line-pts txtent txts)
      )
    (princ "\n未选取直线!!!")
    )
txtent
)

USER2128 发表于 2013-1-2 20:22:54

判断出来后,接下来要干什么?是移开、文字与对应线连线...

吴琦 发表于 2013-1-2 21:29:54

USER2128 发表于 2013-1-2 20:22 static/image/common/back.gif
判断出来后,接下来要干什么?是移开、文字与对应线连线...

谢谢回复,是要对每条线上的数字求最大值

吴琦 发表于 2013-1-2 22:29:32

没人理我,自己想到方法了

xiabin68 发表于 2013-1-2 23:07:04

吴琦 发表于 2013-1-2 22:29
没人理我,自己想到方法了

什么办法,,,说来听听你怎么做到的

吴琦 发表于 2013-1-2 23:26:30

作垂线,分析垂点是否在该直线上

USER2128 发表于 2013-1-3 08:04:55

吴琦 发表于 2013-1-2 23:26 static/image/common/back.gif
作垂线,分析垂点是否在该直线上

作垂线是较困难的,建议你分析线段中点到文字距离,分析出最短距离者为对应关系。
如只对文字求最大值,没必要理会直线的

Gu_xl 发表于 2013-1-3 09:38:08

用 (ssget "_CP" pt_list '((0 . “*text") )) 即可!

pt_list 根据直线的两个端点和文字大小与直线距离相应计算而来!

zyhandw 发表于 2013-1-3 09:43:25

嗯,按G版的思路比较可行
页: [1] 2
查看完整版本: 求高手帮忙,判断文字在段范围内