乐筑天下

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

[编程交流] 多行文字即兴标记

[复制链接]

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 23:45:49 | 显示全部楼层 |阅读模式
您好,感谢您抽出时间查看我的帖子。
感谢大家为像我这样的初学者提供了如此有用的知识体系,供他们学习。
 
我一直在搜索有关在AutoLISP中使用多行文字的课程
(不可否认,我发现了一些令人惊讶的例子)李-麦克对类似的问题发表了几条回复。很抱歉再次提起,但我有点不知所措。我希望有人会花时间将多行文字解决方案应用到附加的Lisp,我目前确实理解。它使用Text命令。。。我意识到使用命令是业余的,但我仍在学习
 
  1. ; Northing & Easting labeling
  2. ; Ryan Anderson December 2013
  3. ; The Label will use the current Text Style and current Units Settings
  4. ; This Lisp borrows ideas from the tutorials I have been working through.
  5. ; http://www.afralisp.net/ http://lee-mac.com/ http://www.cadtutor.net/ http://www.cad-notes.com/
  6. (defun c:gln (/ p x y TxtPos)
  7. (command "_.MSPACE")
  8. (while
  9. (setq p (getpoint "Select a Northing Gridline:"))
  10. (command "_.PSPACE")
  11. (setq TxtPos (getpoint "Pick Label Location: "))
  12. (setq y (rtos (cadr p)))
  13. (setq y (strcat "N " y))
  14. (command "_TEXT" TxtPos "0" y "") ; I would prefer to use MText with a backbround mask and an offset
  15. )
  16. (princ)
  17. )
  18. (princ)
  19. (defun c:gle (/ p x y TxtPos)
  20. (command "_.MSPACE")
  21. (while
  22. (setq p (getpoint "
  23. Select an Easting Gridline:"))
  24. (command "_.PSPACE")
  25. (setq TxtPos (getpoint "
  26. Pick Label Location: "))
  27. (setq x (rtos (car p)))
  28. (setq x (strcat "E " x))
  29. (command "_TEXT" TxtPos "90" x "") ; I would prefer to use MText with a backbround mask and an offset
  30. )
  31. (princ)
  32. )
  33. (princ "Use GLN for Northings, and GLE for Eastings") ;Could both Northings and Eastings be done from one command?
  34. (princ)

 
干杯
再次感谢您抽出时间。
安迪。
回复

使用道具 举报

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-5 23:55:04 | 显示全部楼层
好的,我已经找到了一些解决方法。我用了李的测试程序
http://www.cadtutor.net/forum/showthread.php?39325-AutoLISP中的多行文字
  1. (defun c:test (/ ent)
  2. (if (setq ent (car (entsel "\nSelect MTEXT: ")))
  3.    (foreach x (entget ent)
  4.      (print x)))
  5. (textscr)
  6. (princ))

把适合我需要的一对点着的多行文字扔掉。在使用entmake时,反复试验让我更好地理解了多行文字
我的Lisp程序现在看起来像这样。
  1. ; Northing & Easting labeling with MText
  2. ; Ryan Anderson December 2013
  3. ; This Lisp borrows ideas from the tutorials I have been working through.
  4. ; http://www.afralisp.net/ http://lee-mac.com/ http://www.cadtutor.net/ http://www.cad-notes.com/
  5. (defun c:gln (/ p x y TxtPos)
  6. (command "_.MSPACE")
  7. (while
  8. (setq p (getpoint "Select a Northing Gridline: "))
  9. (command "_.PSPACE")
  10. (setq TxtPos (getpoint "Pick Label Location: "))
  11. (setq y (rtos (cadr p)))
  12. (setq y (strcat "N " y))
  13. (entmake
  14. (list
  15. (cons 0 "MTEXT")
  16. (cons 5 "549c")
  17. (cons 100 "AcDbEntity")
  18. (cons 67 1)
  19. (cons 410 "Layout1")                        ;Model space or layout tab to place MText on
  20. (cons 8 "TXT-GEN")                        ;Layer
  21. (cons 100 "AcDbMText")
  22. (cons 10 TxtPos)                        ;Location of text
  23. (cons 40 5.0)                                ;Font Height
  24. ; (cons 41 50)                                ;length of MText Field, if unspecified it will grow or shrink with the input length
  25. (cons 46 0.0)
  26. (cons 71 7)                                ;Text Justification inside MText (1 is top left 7 is bottom left)
  27. (cons 72 5)
  28. (cons 1 y)                                        ;Text Writen in MText Field
  29. (cons 7 "Text-03")                        ;Text Style
  30. (cons 210 '(0.0 0.0 1.0))
  31. (cons 11 '(1.0 0.0 0.0))
  32. (cons 43 5)
  33. (cons 50 0.0)                                ;Rotation of Text for North Coordinate labels
  34. (cons 73 1)
  35. (cons 44 1.0)
  36. (cons 90 3)                                ;Mask color 3 is "use drawing background color"
  37. (cons 63 256)                                ;Turns on background Mask
  38. (cons 45 1.5)                                ;Border offset Factor of Background Mask
  39. (cons 441 0)                                ;Something to do with background Mask
  40. )
  41. )
  42. (command "_.MSPACE")
  43. )
  44. (princ)
  45. )
  46. (princ)
  47. (defun c:gle (/ p x y TxtPos)
  48. (command "_.MSPACE")
  49. (while
  50. (setq p (getpoint "Select an Easting Gridline: "))
  51. (command "_.PSPACE")
  52. (setq TxtPos (getpoint "Pick Label Location: "))
  53. (setq x (rtos (car p)))
  54. (setq x (strcat "E " x))
  55. (entmake
  56. (list
  57. (cons 0 "MTEXT")
  58. (cons 5 "549c")
  59. (cons 100 "AcDbEntity")
  60. (cons 67 1)
  61. (cons 410 "Layout1")                        ;Model space or layout tab to place MText on
  62. (cons 8 "TXT-GEN")                        ;Layer
  63. (cons 100 "AcDbMText")
  64. (cons 10 TxtPos)                        ;Location of text
  65. (cons 40 5.0)                                ;Font Height
  66. ; (cons 41 50)                                ;length of MText Field, if unspecified it will grow or shrink with the input length
  67. (cons 46 0.0)
  68. (cons 71 7)                                ;Text Justification inside MText (1 is top left 7 is bottom left)
  69. (cons 72 5)
  70. (cons 1 x)                                        ;Text Writen in MText Field
  71. (cons 7 "Text-03")                        ;Text Style
  72. (cons 210 '(0.0 0.0 1.0))
  73. (cons 11 '(1.0 0.0 0.0))
  74. (cons 43 5)
  75. (cons 50 1.5708)                        ;Rotation of Text for East Coordinate labels
  76. (cons 73 1)
  77. (cons 44 1.0)
  78. (cons 90 3)                                ;Mask color 3 is "use drawing background color"
  79. (cons 63 256)                                ;Turns on background Mask
  80. (cons 45 1.5)                                ;Border offset Factor of Background Mask
  81. (cons 441 0)                                ;Something to do with background Mask
  82. )
  83. )
  84. (command "_.MSPACE")
  85. )
  86. (princ)
  87. )
  88. (princ "Use GLN for Northings, and GLE for Eastings") ;Could both Northings and Eastings be done from one command?
  89. (princ)

我还有最后一个问题。我希望有人能帮我。标签的位置存储在变量TxtPos中。我想要的是能够偏移文本,使其不直接位于我选择的网格线上。例如,对于北距,将TxtPos的Y值增加5mm,对于东距,将X值增加5mm。
 
任何帮助都将不胜感激,如果有更简单的方法来做这一切,请不要犹豫纠正我。
最后,如果代码对任何人都有用,请随时使用。
干杯
安迪。
回复

使用道具 举报

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-6 00:03:15 | 显示全部楼层
 
如果我的回答正确,您希望在模型空间中拾取一个点,检索北距和东距,然后切换到活动布局并放置文本。
 
我可以提供一种不同的方式来切换模型和布局吗?
 
  1. (vl-load-com);Load Visual Lisp Extensions
  2. (setq *acad* (vlax-get-acad-object));Get the ACAD Object
  3. (setq *ad* (vla-get-ActiveDocument *acad*));Get the Active Document
  4. (vlax-put-property *ad* 'ActiveSpace 1);For ModelSpace
  5. (vlax-put-property *ad* 'ActiveSpace 0);For Paperspace
  6. (vlax-release-object *acad*);release object when done using it
  7. (vlax-release-object *ad*);release object when done using it

 
我甚至建议使用这些对象来创建多行文字。
回复

使用道具 举报

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 00:18:34 | 显示全部楼层
谢谢你的回复。
要明确的是。我确实希望在模型空间中拾取一个点并检索北距和东距,但我是通过位于Layout1上的视口来执行此操作的。
 
很抱歉,根本没有记录。(希望这能帮助其他阅读本文的人)
 
绘图板上的绘图板位于布局1上
图纸空间(布局1)中存在一个或多个视口,用于查看模型空间。
所有注释都需要在图纸空间中。
所有网格线都存在于模型空间中。
 
因此,工作流程是:
-键入GLE(东距)或GLN(北距)
-Lisp将切换到视口中的模型空间
-提示选择网格线
-Lisp将切换回视口中的图纸空间
-提示选择标签位置
-使用前缀“E”表示东距,或使用前缀“N”表示北距
-在图纸空间中的拾取点创建多行文字
-类似于“E 1500.000”或“N 2400.000”
-东距文本旋转为垂直
-应用与背景色相同的背景遮罩
 
感谢您提供有关Visual Lisp扩展的代码。
我目前并不完全理解,但我会深入研究。
如果你有时间(或者其他人想帮忙),我想知道这种格式的多行文字是什么样子的。
 
干杯
安迪。
回复

使用道具 举报

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-6 00:21:34 | 显示全部楼层
也许试试这个?我希望这有助于理解VLA对象。
 
  1. (vl-load-com);Load Visual Lisp Extensions
  2. (defun c:glne ()
  3. (setq *acad* (vlax-get-acad-object));Get the acad object
  4. (setq *ad* (vlax-get-property *acad* 'ActiveDocument));Get the Active Document
  5. (setq *PS* (vlax-get-property *ad* 'PaperSpace));Get the Active Paper Space
  6. (vlax-put-property *ad* 'ActiveSpace 1);Go to Model Space
  7. (setq pnt (getpoint "\Select Point on Grid: "));Prompt User to Select Point:
  8. (if pnt
  9.    (progn ;If Point Exists
  10.      (vlax-put-property *ad* 'ActiveSpace 0);Go to Paper Space
  11.      
  12.      (setq x (car pnt));Get the X value of Point
  13.      
  14.      (setq y (cadr pnt));Get the Y Value of Point
  15.      (initget 1 "Northing Easting");Initialize getkword
  16.      (setq ret (getkword "Label Northing or Easting?"));Ask user if they are labeling Northing or Easting
  17.      (cond
  18. ((= ret "Northing")(setq str (strcat "N:" (rtos y 2 2)) rot 0))
  19. ((= ret "Easting")(setq str (strcat "E:" (rtos x 2 2)) rot (/ pi 2.0))));Format the string accordingly and Set the Roation
  20.      (setq txtpos (getpoint "\nSelect Label Position:"));Prompt User for Label Position
  21.      (if txtpos
  22. (progn ;If Point Exists
  23.   (setq MTEXT-OBJECT (vlax-invoke-method *PS* 'AddMText (vlax-3d-point txtpos) 1 str));Create the MTEXT Object
  24.   (vlax-put-property MTEXT-OBJECT 'Layer "TXT-GEN");Set the layer for the MText
  25.   (vlax-put-property MTEXT-OBJECT 'Height 0.12);Set the Text Height
  26.   (vlax-put-property MTEXT-OBJECT 'BackgroundFill :vlax-true);Set the BackgroundFill to true
  27.   (vlax-put-property MTEXT-OBJECT 'AttachmentPoint acAttachmentPointBottomLeft);Set the Jusstification
  28.   (vlax-put-property MTEXT-OBJECT 'InsertionPoint (vlax-3d-Point txtpos));Reset the InsertionPoint
  29.   (vlax-put-property MTEXT-OBJECT 'Rotation rot);Set the rotation
  30.   
  31.   (vlax-release-object *acad*)
  32.   (vlax-release-object *ad*)
  33.   (vlax-release-object *PS*)
  34.   (vlax-release-object MTEXT-OBJECT)
  35.   ;Not sure if its necessary to release every object or just *acad*
  36.   ;either way... it doesn't hurt to just release it
  37.   
  38.   );end progn
  39. ;if Point doesn't exist
  40. );end if
  41.      );end progn
  42.    ;if Point doesn't exist
  43.    );end if
  44. );end defun
回复

使用道具 举报

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-6 00:32:23 | 显示全部楼层
这将有助于将实体视为对象。
 
  1. (vl-load-com)
  2. (defun c:dmpobj ()
  3. (vlax-dump-object (vlax-ename->vla-object (car (entsel "\nSelect Object:"))) T)
  4. (command "TextScr")
  5. (princ)
  6. )
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 00:38:06 | 显示全部楼层
几点建议
 
  1. ; use POLAR to work out a new insert pt for the text
  2. (setq txtpos (polar (polar P 5.0 0.0) -5.0 1.5707963)
  3. (setq y (rtos (cadr p)))
  4. (setq y (rtos (cadr p) 2 0)) ; this is integer
  5. (setq y (rtos (cadr p)1 1)) ; this is 1 decimal place
回复

使用道具 举报

2

主题

10

帖子

8

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 00:51:45 | 显示全部楼层
谢谢Hippe013和BIGAL
这些代码片段看起来非常有用。
 
当我在本周晚些时候有更多的时间时,我将尝试使用VLA方法再次解决这个问题。这一次有了offets
干杯,伙计们!
安迪
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 21:26 , Processed in 0.516054 second(s), 68 queries .

© 2020-2025 乐筑天下

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