乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 68|回复: 19

[编程交流] 旋转文字以对齐线条

[复制链接]

63

主题

242

帖子

181

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
319
发表于 2022-7-6 11:02:20 | 显示全部楼层 |阅读模式
大家好
我想旋转单个文本,以获取图形中现有线条的角度
谢谢
回复

使用道具 举报

18

主题

434

帖子

422

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
94
发表于 2022-7-6 11:06:47 | 显示全部楼层
像这样的?
  1. (defun c:textalign()
  2. (setq line (car (entsel "Pick a line"))
  3.          text (car (entsel "...and a text"))
  4.          ang (angle (cdr (assoc 10 (entget line)))
  5.                         (cdr (assoc 11 (entget line)))
  6.                  )
  7.          tl (entget text)
  8.          tl (subst (cons 50 ang) (assoc 50 tl) tl)
  9.          tl (entmod tl)
  10.   )
  11.   (progn)
  12. )

这是一个非常简单的例程-仅用于演示-如果用户没有选择例程期望的内容,它将崩溃
回复

使用道具 举报

2

主题

439

帖子

536

银币

限制会员

铜币
-14
发表于 2022-7-6 11:11:52 | 显示全部楼层
了解了。我今天生病了,没有去上班,决定写信。
 
  1. (defun c:talong(/ actDoc actSp cText curAng curDer curPar
  2.         curStr curTxt lChr oldMode oldOff oldSize
  3.         oldSnap pt1 pt2 rLst selObj selPt stFlag
  4.         tmpLn tStr txTpt unStart whatDo)
  5. (vl-load-com)
  6. (defun asmi_EntselWithOptions(Message / grLst filPt selSet)
  7. (if Message
  8.    (princ Message)
  9.    (princ "\nSelect object: ")
  10.    ); end if
  11.     (setq lChr ""
  12.           grLst(list 2 678)
  13.           tStr ""
  14.           ); end setq
  15.     (while
  16.       (and
  17.           (not
  18.             (member lChr '(" " "\r")))
  19.           (/= 3(car grLst))
  20.         ); end or
  21.   (if
  22.     (setq grLst(grread nil 4 2))
  23.     (progn
  24.       (cond
  25.           ((= 3(car grLst))
  26.            (setq filPt(cadr grLst)
  27.                  selSet(ssget filPt)
  28.                  ); end setq
  29.            (if selSet
  30.                (setq outVal
  31.                 (list(ssname selSet 0)filPt))
  32.              ); end if
  33.            ); end cond #1
  34.           ((= 2(car grLst))
  35.            (setq lChr(chr(cadr grLst)))
  36.            (if
  37.              (not
  38.                (member lChr '(" " "\r")))
  39.                      (progn
  40.                      (setq tStr(strcat tStr lChr)
  41.                            outVal tStr); end setq
  42.                      (princ lChr)
  43.                ); end progn
  44.              ); end if
  45.            ); end cond #2
  46.         ); end cond
  47.        ); end progn
  48.       ); end if
  49.      ); end while
  50.     outVal
  51.    ); end of asmi_EntselWithOptions
  52. (defun asmi_LayersUnlock(/ restLst)
  53. (setq restLst '())
  54. (vlax-for lay
  55.    (vla-get-Layers
  56.             (vla-get-ActiveDocument
  57.               (vlax-get-acad-object)))
  58.    (setq restLst
  59.     (append restLst
  60.       (list
  61.         (list
  62.          lay
  63.           (vla-get-Lock lay)
  64.   (vla-get-Freeze lay)
  65.          ); end list
  66.         ); end list
  67.       ); end append
  68.    ); end setq
  69.    (vla-put-Lock lay :vlax-false)
  70.    (if
  71.      (vl-catch-all-error-p
  72. (vl-catch-all-apply
  73. 'vla-put-Freeze(list lay :vlax-false)))
  74.      t)
  75.    ); end vlax-for
  76. restLst
  77. ); end of asmi_LayersUnlock
  78. (defun asmi_LayersStateRestore(StateList)
  79. (foreach lay StateList
  80.    (vla-put-Lock(car lay)(cadr lay))
  81.     (if
  82.      (vl-catch-all-error-p
  83. (vl-catch-all-apply
  84.   'vla-put-Freeze(list(car lay)(nth 2 lay))))
  85.       t)
  86.    ); end foreach
  87. (princ)
  88.     ); end of asmi_LayersStateRestore
  89. ;;===========================================================
  90. ;; UNFORMAT.LSP (c)2003, John F. Uhden, Cadlantic/CADvantage
  91. ;; v1.0 (04-01-03)
  92. ;; Removes MTEXT formatting with option to retain the "\\P" LineFeeds
  93. ;;
  94. ;; Arguments:
  95. ;; Mtext - either an Ename or VLA-Object
  96. ;; KeepLF - nil (discard LineFeeds) non-nil (retain LineFeeds)
  97. ;;
  98. ;; NOTES:
  99. ;; Only R15 or higher.
  100. ;; v1.0 is only the first attempt.
  101. ;; We can always embellish the code with additional options.
  102. ;; Yes, it can probably be sped up using integers, but this is legible.
  103. ;;
  104. (defun UnFormat (Mtext KeepLF / Text Str)
  105. (vl-load-com)
  106. (cond
  107.     ((= (type Mtext) 'VLA-Object)); end condition #1
  108.     ((= (type Mtext) 'ENAME)
  109.      (setq Mtext (vlax-ename->vla-object Mtext))
  110.      ); end condition #2
  111.    (1 (setq Mtext nil)) ; end condition #3
  112. ); end cond
  113.     (and
  114.   Mtext
  115.   (= (vlax-get Mtext 'ObjectName) "AcDbMText")
  116.   (setq Mtext (vlax-get Mtext 'TextString))
  117.   (setq Text "")
  118. (while (/= Mtext "")
  119. (cond
  120.    ((wcmatch (strcase
  121.         (setq Str
  122.            (substr Mtext 1 2))) "\\[\\{}`~]")
  123.     (setq Mtext (substr Mtext 3)
  124.           Text (strcat Text Str)
  125.           ); end setq
  126.       ); ed condition #1
  127.    ((wcmatch (substr Mtext 1 1) "[{}]")
  128.      (setq Mtext (substr Mtext 2))
  129.      ); end condition #2
  130.    ((and KeepLF (wcmatch (strcase (substr Mtext 1 2)) "\\P"))
  131.      (setq Mtext (substr Mtext 3)
  132.            Text (strcat Text "\\P")
  133.            ); end setq
  134.      ); end condition #3
  135.    ((wcmatch (strcase (substr Mtext 1 2)) "\\[LOP]")
  136.      (setq Mtext (substr Mtext 3))
  137.      ); end condition #4
  138.     ((wcmatch (strcase (substr Mtext 1 2)) "\\[ACFHQTW]")
  139.        (setq Mtext
  140.       (substr Mtext (+ 2 (vl-string-search ";" Mtext))))
  141.      ); end condition #5
  142.     ((wcmatch (strcase (substr Mtext 1 2)) "\\S")
  143.        (setq Str
  144.        (substr Mtext 3
  145.                (- (vl-string-search ";" Mtext) 2))
  146.              Text (strcat Text
  147.                    (vl-string-translate "#^\" " " Str))
  148.              Mtext (substr Mtext (+ 4 (strlen Str)))
  149.              ); end setq
  150.         (print Str)
  151.       ); end condition #6
  152.     (1
  153.       (setq Text (strcat Text (substr Mtext 1 1))
  154.             Mtext (substr Mtext 2)
  155.            ); end setq
  156.       ); end condition #7
  157.     ); end cond
  158. ); end while
  159. ); end and
  160. Text
  161. ); end of UnFormat
  162. (defun asmi_GetActiveSpace(/ actDoc spFlag)
  163.      (setq actDoc(vla-get-ActiveDocument
  164.                     (vlax-get-acad-object))
  165.            spFlag(vla-get-ActiveSpace actDoc)
  166.           ); end setq
  167.       (if(= 0 spFlag)
  168.          (setq actSp(vla-get-PaperSpace actDoc))
  169.          (setq actSp(vla-get-ModelSpace actDoc))
  170.        ); end if
  171.    ); end of asmi_GetActiveSpace
  172. (asmi_GetActiveSpace)
  173. (defun EnvironmentRestore()
  174.    (if oldSnap
  175.      (setvar "OSMODE" oldSnap)
  176.      ); end if
  177.    (if unStart
  178.      (vla-EndUndoMark actDoc)
  179.      ); end if
  180.    (if tmpLn
  181.      (vla-Delete tmpLn)
  182.      ); end if
  183.    (if rLst
  184.      (asmi_LayersStateRestore rLst)
  185.      ); end if
  186.    (if selObj
  187.      (vla-Highlight selObj :vlax-false)
  188.      ); end if
  189.    (princ)
  190.    ); end of EnvironmentRestore
  191. (defun *error*(msg)
  192.    (EnvironmentRestore)
  193.    (princ "\n<<< Console break. Quit. >>> ")
  194.    (princ)
  195.    ); end of *error*
  196. (if(not tal:mode)(setq tal:mode "Type"))
  197. (if(not tal:off)(setq tal:off 1.5))
  198. (if(not tal:size)(setq tal:size(getvar "TEXTSIZE")))
  199. (setq oldSnap(getvar "OSMODE"))
  200. (while
  201.      (and
  202. (/= 'LIST(type whatDo))
  203. (not stFlag)
  204.      ); end or
  205.      (princ
  206.        (strcat
  207.      "\n<<< Mode = " tal:Mode ", Text size = " (rtos tal:size)
  208.      ", Offset = " (rtos tal:off) " >>> ") ; end strcat
  209.       ); end princ
  210. (setq whatDo
  211. (asmi_EntselWithOptions
  212.    "\nSelect curve or [settings/Quit] > ")
  213. ); end setq
  214.    (cond
  215.      ((= 'LIST(type whatDo))
  216.       (setq selObj
  217.       (vlax-ename->vla-object
  218.         (car whatDo))
  219.      selPt T
  220.      txtPt T
  221.      ); end setq
  222.       (if
  223. (member
  224.    (vla-get-ObjectName selObj)
  225.    '("AcDbLine" "AcDbPolyline" "AcDb3dPolyline"
  226.      "AcDbSpline" "AcDbCircle" "AcDbEllipse"
  227.      "AcDbArc" "AcDbRay" "AcDbXline")
  228.    ); end menber
  229. (progn
  230.    (vla-Highlight selObj :vlax-true)
  231.    (setq rLst(asmi_LayersUnlock))
  232.    (while
  233.      (and selPt txtPt)
  234.      (vla-StartUndoMark
  235.        (setq actDoc
  236.           (vla-get-ActiveDocument
  237.             (vlax-get-acad-object))))
  238.      (setq unStart T)
  239.      (setvar "OSMODE" 3071)
  240.      (if
  241.        (setq selPt
  242.             (getpoint
  243.               "\nPick point on curve or Right Click to Quit > "); end getpoint
  244.            ); end setq
  245.        (progn
  246.      (if
  247.        (setq curPar
  248.               (vlax-curve-GetParamAtPoint selObj
  249.                 (setq selPt(trans selPt 1 0))))
  250.        (progn
  251.           (setq curDer
  252.                  (vlax-curve-GetFirstDeriv selObj
  253.                              curPar)
  254.                 ); end setq
  255.                 (if(=(cadr curDer) 0.0)
  256.                    (setq curAng (/ pi 2))
  257.                      (setq curAng
  258.                         (- pi
  259.                          (atan
  260.                           (/(car curDer)
  261.                             (cadr curDer)))))
  262.                   ); end if
  263.          (setq pt1
  264.                 (polar selPt curAng (* tal:size tal:off))
  265.                pt2
  266.                 (polar selPt curAng (-(* tal:size tal:off)))
  267.                tmpLn(vla-AddLine actSp
  268.                       (vlax-3D-point pt1)(vlax-3D-point pt2)
  269.                       ); end vla-AddLine
  270.                ); end setq
  271.          (vla-put-Color tmpLn acRed)
  272.          (setvar "OSMODE" 1)
  273.          (if
  274.            (setq txtPt
  275.                   (getpoint
  276.                     "\nPick middle point of text or Right Click to Quit > ")
  277.                  ); end setq
  278.            (progn
  279.              (setq txtPt
  280.                     (vlax-3d-point
  281.                       (trans txtPt 1 0))
  282.                    curStr nil); end setq
  283.              (while(not curStr)
  284.              (if
  285.                (= tal:mode "Type")
  286.                (progn
  287.                  (setq curStr
  288.                       (getstring T
  289.                         "\nEnter text: "); end getstring
  290.                      ); end setq
  291.                  (if(= "" curStr)(setq curStr nil))
  292.                ); end progn
  293.                (progn
  294.                  (if
  295.                    (and
  296.                      (setq cText
  297.                           (nentsel
  298.                             "\nCopy text > "))
  299.                      (setq cText
  300.                             (vlax-ename->vla-object(car cText)))
  301.                      (member
  302.                        (vla-get-ObjectName cText)
  303.                        '("AcDbText" "AcDbMText" "AcDbAttribute")
  304.                        ); end member
  305.                    ); end and
  306.                    (if
  307.                      (= "AcDbMText"
  308.                         (vla-get-ObjectName cText))
  309.                        (setq curStr
  310.                             (UnFormat cText nil)); end setq
  311.                        (setq curStr
  312.                               (vla-get-TextString cText)); end setq
  313.                      ); end if
  314.                    ); end if
  315.                  ); end progn
  316.                ); end if
  317.                (if(not curStr)
  318.                  (princ "\n>>> Empty input! <<< ")
  319.                  (progn
  320.                  (setq curTxt
  321.                         (vla-addText actSp curStr
  322.                           txtPt tal:size)); end setq
  323.                  (if
  324.                    (and(< curAng(* 2 pi))(> curAng pi))
  325.                          (vla-put-Rotation curTxt (+ curAng(/ pi 2)))
  326.                          (vla-put-Rotation curTxt (- curAng(/ pi 2)))
  327.                    ); end if
  328.                          (vla-put-Alignment curTxt acAlignmentMiddleCenter)
  329.                          (vla-Move curTxt
  330.                                    (vla-get-TextAlignmentPoint curTxt)
  331.                                    txtPt); end move
  332.                    ); end progn
  333.                  ); end if
  334.               ); end while
  335.              ); end progn
  336.            (princ "\n<<< Quit >>> ")
  337.            ); end if

 
在下一篇文章中继续。。。
120221wx6tll16y1uuct6j.jpg
回复

使用道具 举报

2

主题

439

帖子

536

银币

限制会员

铜币
-14
发表于 2022-7-6 11:13:11 | 显示全部楼层
  1.                  (vla-Delete tmpLn)
  2.          (setq tmpLn nil)
  3.          ); end progn
  4.         (progn
  5.          (princ "\n>>> Point isn't at curve! Quit. <<< ")
  6.          (setq selPt nil)
  7.         ); end progn
  8.        ); end if
  9.      ); end progn
  10.        (princ "\n<<< Quit >>> ")
  11.        ); end if
  12.      (vla-EndUndoMark actDoc)
  13.      (setq unStart nil)
  14.      ); end while
  15.    (vla-Highlight selObj :vlax-false)
  16.    (asmi_LayersStateRestore rLst)
  17.    ); end progn
  18. (princ "\n>>> This isn't curve! Quit. <<< ")
  19. ); end if
  20.       ); end condition #1
  21.      ((= "S" (strcase whatDo))
  22.       (initget "Type Copy")
  23.        (setq oldMode tal:mode
  24.       oldOff tal:off
  25.       oldSize tal:size
  26.       tal:mode
  27.        (getkword
  28.          (strcat
  29.            "\nSpecify text creation mode [Type/Copy] <"
  30.            tal:mode ">: "); end strcat
  31.          ); end getkword
  32.       tal:size
  33.        (getreal
  34.          (strcat
  35.            "\nSpecify text size <"
  36.            (rtos tal:size) ">: "); end strcat
  37.          ); end getreal
  38.       tal:off
  39.        (getreal
  40.          (strcat
  41.            "\nSpecify text offset from line. TEXT SIZE * <"
  42.            (rtos tal:off) ">: "); end strcat
  43.          ); end getreal
  44.       ); end setq
  45.       (if(null tal:mode)(setq tal:mode oldMode))
  46.       (if(null tal:size)(setq tal:size oldSize))
  47.       (if(null tal:off)(setq tal:off oldOff))
  48.       ); end condition #2
  49.      ((= "Q" (strcase whatDo))
  50.       (princ "\n<<< Quit >>> ")
  51.       (setq stFlag T)
  52.       ); end condition #3
  53.      (T
  54.        (princ "\nInvalid option keyword. ")
  55.       ); end condition #4
  56.      ); end cond
  57.    ); end while
  58. (EnvironmentRestore)
  59. (princ)
  60. ); end of c:talong
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 11:16:23 | 显示全部楼层
谢谢朋友们的回复
还有一件事,除了输入新文本(可选)之外,您是否可以修改routin,使我能够拾取图形中的现有文本
非常感谢你
回复

使用道具 举报

63

主题

242

帖子

181

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
319
发表于 2022-7-6 11:20:31 | 显示全部楼层
>出租车
 
你好精细Lisp程序。我喜欢通过“entsel”和带有“vlax curve getClosestPointTo”的精确坐标同时选择点和曲线的想法。然而,我认为这是完全有可能做到的。在“grread”的基础上查看我的函数“asmi\u EntselWithOptions”。可以查询类型“选择曲线上的点或[镜像(最后)/移动(最后)/(更改)边/设置]:”。可以根据需要更改最后一个文本的侧面、移动它、更改所有下一个文本的侧面和更改设置(文本大小、与曲线的距离,以及选择模式[键入/复制]),而无需中断命令和多余的查询。对于那些不需要选项的人,不能像不存在选项一样使用它。
 
你喜欢这样的想法吗?
 
不幸的是,现在绝对没有时间了。我已经过了两天的工作,我有一些更重要的问题。
回复

使用道具 举报

2

主题

439

帖子

536

银币

限制会员

铜币
-14
发表于 2022-7-6 11:21:37 | 显示全部楼层
Asmi,
是的,我喜欢这个主意,我也很喜欢你的Lisp程序。
我的只是一个简单的Lisp程序的spacific pourpose。
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 11:25:58 | 显示全部楼层
这很简单,你为什么不试试呢。
发布你的代码,有人会帮你完成。
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 11:29:59 | 显示全部楼层
好的,试试这个。
  1. ;;  TextAlignWithObject.lsp
  2. ;;  CAB   02/19/2007
  3. ;;
  4. ;;  Add text to DWG at angle of selected object
  5. (defun c:tao() (c:TextAlignWithObject)) ; shortcut
  6. (defun c:TextAlignWithObject (/ tmp ang p@pt parA parB pt start txtht
  7.               FixTextAngle addtext)
  8. (vl-load-com)
  9. ;;  Returns a text angle in radians, flops text at >90 and <270
  10. (defun FixTextAngle (ang)
  11.    (if (and (> ang (* 0.5 pi)) (< ang (* 1.5 pi)))
  12.      (+ ang pi)
  13.      ang
  14.    )
  15. )
  16. ;;  Create a text object
  17. (defun addtext (ipt hgt text ang lay / txtObj)
  18.    (setq txtObj
  19.           (vla-addtext
  20.             (if (= (getvar 'cvport) 1)
  21.               (vla-get-paperspace (vla-get-activedocument (vlax-get-acad-object)))
  22.               (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
  23.             )
  24.             text
  25.             (vlax-3d-point ipt)
  26.             hgt
  27.           )
  28.    )
  29.    (vla-put-layer txtObj lay)
  30.    (vla-put-rotation txtObj ang)
  31.    (vla-put-alignment txtObj acalignmentbottomcenter)
  32.    (vla-put-textalignmentpoint txtobj (vlax-3d-point ipt))
  33. )
  34. ;;  -=< START HERE  >=-
  35. ;;  Get text string to insert
  36. (or txtstr (setq txtstr "Default Text"))
  37. (if (/= (setq tmp (getstring t (strcat "\nEnter text string: < " txtstr " > "))) "")
  38.    (setq txtstr tmp)
  39. )
  40. ;;  Get object to align text & insert point
  41. ;;  Object must have curve data
  42. (if (and (setq ent (entsel "\nSelect point on object to label."))
  43.           (not (vl-catch-all-error-p
  44.                  (setq pt (vl-catch-all-apply
  45.                                'vlax-curve-getClosestPointTo
  46.                                (list (car ent) (cadr ent))
  47.                              )
  48.                  )
  49.                )
  50.           )
  51.      )
  52.    (progn
  53.      (setq ent  (car ent)
  54.            p@pt (vlax-curve-getParamAtPoint ent pt)
  55.            parA (max 0.0 (- p@pt 0.05))
  56.            parB (min (+ p@pt 0.05) (vlax-curve-getEndParam ent))
  57.            ang  (angle (vlax-curve-getPointAtParam ent parA)
  58.                        (vlax-curve-getPointAtParam ent ParB)
  59.                 )  ; aprox angle of curve at pick point
  60.            ang  (FixTextAngle ang)
  61.      )
  62.      ;;  Text height by style or current Text Size
  63.      (if (zerop (setq txtht (getvar 'textsize)))
  64.        (setq txtht (getvar "TextSize"))
  65.      )
  66.      (addtext pt txtht txtstr ang (getvar "clayer")) ; ins hgt text ang
  67.    )
  68.    (prompt "\n**  Missed or no curve data for object.")
  69. )
  70. (princ)
  71. )
  72. (prompt "\nTextAlignWithObject.lsp loaded enter TAO to run.")
  73. (princ)
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 11:33:23 | 显示全部楼层
我试着把在图中选择的文本移动到线上的点
(命令“_move”ss?lst)
这里我不知道文本的基点,那么另一个是正确的吗
谢谢你,出租车
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-6 11:43 , Processed in 0.454855 second(s), 74 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表