jondoeiowa 发表于 2022-7-6 09:05:03

文本编辑lisp例程

是否可以编写一个lisp例程,该例程将获取单行文本并将其向上或向下调整?当我起草一条线和标签是10-0,我想能够建立一个例程,通过绘图点击对象,并有它向下调整2,使其9-10。如果可能的话,有人有什么建议或想法吗?

MSasu 发表于 2022-7-6 09:12:38

首先,请让版主将你的帖子移动到适当的部分。你的问题会得到更多的支持。
 
第二,标签是什么类型的实体?你说的是文本还是维度?
 
当做
米尔恰

MSasu 发表于 2022-7-6 09:22:16

你的日常生活将是:
 
;select entity to edit (ENTSEL)
;get the associated list of the entity (ENTGET)
;get the label content (ASSOC)
;convert that value to a double taking care of format (DISTOF)
;perform the math
;convert back the value to string taking care of format (RTOS)
;modify the associated list of the entity (SUBST)
;update the entity (ENTMOD)
 
请尝试遵循上述方案,并询问您的问题所在。祝你好运
 
当做
米尔恰

fuccaro 发表于 2022-7-6 09:31:40

谢谢你的提示,米尔恰。移动线程。

Tharwat 发表于 2022-7-6 09:36:15

我猜你的意思是反转字符串。
 
(defun c:TesT (/ ss sset lst e)
;; Tharwat 04. 08. 2011
(prompt "\n Select Texts to reverse >> ...")
(if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
   (while
   (setq sset (ssname ss 0))
      (setq lst (vl-string->list (cdr (assoc 1 (setq e (entget sset))))))
      (entmod (subst (cons 1 (vl-list->string (reverse lst)))(assoc 1 e)e ))
      (ssdel sset ss)
   )
   (princ)
)
(princ)
)

 
塔瓦特

MSasu 发表于 2022-7-6 09:44:10

 
抱歉@Tharwat,但在我看来,OP并不是在寻找反转字符串例程。
 
当做
米尔恰

pBe 发表于 2022-7-6 09:54:20

 
你是说“调低”是10-0减2是9-10。那么10-1就是9-11?,如果“上升”,9-11将是10-1?
 
10-2到10-0?

MSasu 发表于 2022-7-6 10:04:09

@pBe:OP讨论的是英制值:10’-0”(10英尺,11英寸)减去2”(2英寸)将是9’-10”(9英尺,10英寸)。
 
(rtos (- (distof "10'0\"" 4) (distof "2\"" 4)) 4)
 
(或者,也许我不明白你的问题?)
 
当做
米尔恰

pBe 发表于 2022-7-6 10:08:00

 
我想你是对的,msasu。。我觉得比这更复杂
页码,即第9页,共10页或第13页,共19页,所以第一个和第二个数字会有很大的不同,
 
这将是一个有趣的代码编写
 
编辑:
虽然很奇怪,但试试看
 
(defun c:Addless ( / DoTheMath strs str j intval)
(defun AddSub (ent symnum / strs g DoTheMath ft)
   (setq strs (vla-get-textstring ent))
   (setq g (read (strcat "(" (vl-string-subst " " "-" strs) ")")))
   (setq DoTheMath (/
                ((eval (read sym))
                      (+ (* (car g) 12.0)
                         (cadr g))
                      num) 12))(vla-put-textstring ent
      (strcat (itoa (setq ft (fix DoTheMath))) "-"
            (rtos (* (- DoTheMath ft) 12) 2 0)))
)
   (cond ((and
(setq strs (ssget ":L" '((0 . "*TEXT"))))

               (progn
                     (initget 7)
                     (setq IntVal (getint "\nEnter Value to Add\Subtact: "))

                     )

       (princ "\nPress [+/-] Any key to Exit")
(while (member (setq j (grread nil 10)) '((2 45)(2 43)))
(if (member j '((2 45) (2 43)))
   (repeat (setq i (sslength strs))
                        (setq str (vlax-ename->vla-object (ssname strs (setq i (1- i)))))
                     (Addsub str (chr (cadr j)) IntVal))
                   )
                     )
            )
            )
         )
   (princ)
      )      
 
注意到我做数学的方式有多混乱吗?
我想你大概明白了
页: [1]
查看完整版本: 文本编辑lisp例程