amb2301 发表于 2022-7-5 15:53:03

更改文本时需要帮助

嗨,朋友们,
所附lisp由Bigal提供,其工作原理,
现在我想把text1和text2旋转到可读角度。
请检查所附的lisp并帮助我更改它。
 
提前谢谢。
bigal-复制。lsp

Grrr 发表于 2022-7-5 16:11:03

Google for a subfunction LM:可读。

amb2301 发表于 2022-7-5 16:21:20

 
您好,Grr,
我在谷歌上搜索了LM:Readable,但我无法理解,你能告诉我,在所附的lisp中,在哪里替换行以使其旋转到可读的角度,请在急需时帮助我
 
 
谢谢

ronjonp 发表于 2022-7-5 16:31:27

如果你看一下你发布的代码,有一行有(vla put rotation Tp ang),你需要得到Lee的LM:readable函数,将其添加到lisp并更改为(vla put rotation Tp(LM:readable ang))。

Grrr 发表于 2022-7-5 16:49:57

我修改了一点BIGAL的代码,并对其进行了评论:
 


; pick 3 texts and align to a block                                 ;; Write what the code does, so you won't have to figure out what was this
(vl-load-com) (princ)                                             ;; Load all visual lisp extensions
(defun c:trt                                                      ;; Define a command function, call with "TRT" (this is the main command)
( / blockent blockobj oldang oldunit oldsnap ang ins xscale bname ;; Localise all the used code variables
   len off textent1 textobj1 pt1 textent2 textobj2 pt1
)
; Example by BIGAL                                                ;; Write in the author in case you have further questions
(and                                                            ;; wrap all evaluations with (and) function - this means if somewhere nil is returned, the program will stop
   (setq blockent (car (entsel "\nPick Block object")))            ;; Prompt to select block entity
   (setq blockobj (vlax-ename->vla-object blockent))               ;; convert the block entity to vla-object
   (if (= Objname "AcDbBlockReference")                            ;; check if block was selected
   T                                                             ;; return True if block was selected
   (alert "You have not Picked a block\n\nPress ok ")            ;; prompt alert message (alert returns nil)
   ); if
   (mapcar 'set '(oldang oldunit oldsnap) ; store some system variables
   (mapcar '(lambda (a b / c) (setq c (getvar a)) (setvar a b) c)
       '(angdir aunits osmode) '(0 3 0)
   )
   ); mapcar
   (mapcar 'set '(ang ins xscale bname) ; store some properties from the block's object
   (mapcar '(lambda (x) (vlax-get blockobj x))
       '(Rotation InsertionPoint XScaleFactor EffectiveName)
   )
   ); mapcar
   
   (cond                                                         ;; set a codition to determine what value to assign for 'len', depending on the block name
   ( (= bname "TERM_AER_E") (setq len 6) ) ; as per sample
   ( (= bname "Block1") (setq len 10) ) ; other blocks change len value
   ( (= bname "Block2") (setq len 10) ) ; other blocks change len value
   ( (setq len 20) ) ; for unknown block change len value
   ); cond
   (setq off 8.0)                                                ;; set offset value
   
   (setq textent1 (car (entsel "\nPick text1")))                   ;; Prompt to select a text entity
   (setq textobj1 (vlax-ename->vla-object textent1))               ;; convert the text entity into a vla-object
   (setq pt1 (polar ins (+ ang (/ pi 2.0)) off))                   ;; calculate the new base point for the text
   (vla-put textobj1 'insertionpoint pt1)                        ;; set the new base point for the text
   (vla-put-rotation textobj1 (MakeReadable ang))                  ;; set the text rotation, by recalculating the angle with (MakeReadable) subfunction
   (setq textent2 (car (entsel "\nPick text2")))                   ;; Prompt to select a text entity
   (setq textobj2 (vlax-ename->vla-object textent2 ))            ;; convert the text entity into a vla-object
   (setq pt1 (polar ins ang (* len 2.0)))                        ;; calculate the new base point for the text
   (vlax-put textobj2 'insertionpoint pt1)                         ;; set the new base point for the text
   (vla-put-rotation textobj2 (MakeReadable ang))                  ;; set the text rotation, by recalculating the angle with (MakeReadable) subfunction
); and
(mapcar '(lambda (a b) (and a b (setvar a b))) ; Restore the system variables
   '(angdir aunits osmode) (list oldang oldunit oldsnap)
); mapcar
(princ)                                                         ;; Exit Cleanly
); defun

;; Define subfunctions that the main program uses:

;; Make Angle Readable by: ymg
(defun MakeReadable (a)
(setq a (rem (+ a pi pi) (+ pi pi)))
(rem (if (< (* pi 0.5) a (* pi 1.5))
   (+ a pi)
   a
)
(+ pi pi)
)
)


 
从中尽可能多地学习,如果有任何问题,请提问。
希望下次你能发布你的尝试。

amb2301 发表于 2022-7-5 16:53:47

 
您好,GRR,
非常感谢您的帮助,您的解释对我非常有帮助,我尝试使用您提供的lisp,但由于某些原因,左对齐不能与该lisp正常工作,右对齐工作完美,因此我创建了两个独立的lisp,用于左对齐和右对齐,如附件中的lisp文件所示,请检查该文件并提供您的反馈。
另外,请建议,是否可以在一个lisp中完成?
grr。lsp
页: [1]
查看完整版本: 更改文本时需要帮助