乐筑天下

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

[编程交流] Lisp程序有点小问题!!!

[复制链接]

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 06:27:30 | 显示全部楼层 |阅读模式
我对下面的lisp代码有点问题。。。
当Lisp程序的时候,让我调整一下音阶
  1. Drawing scale factor 1= 1:100, 2 = 1:200, 3 = 1:500

 
1.当我选择1(比例1:100)时,文字高度为0.35
2.当我选择1(比例1:200)时,文字高度为0.70
3.当我选择1(比例1:100)时,文字高度为1.05
 
我需要在比例(1:200)的文字高度是0.35,或者我不知道有多容易手动给文字高度,(问我….给文字大小:)
 
请帮忙。。。
 
  1. ;------------------------------------------------------------------------------
  2. ; CAD Concepts Limited
  3. ;
  4. ; BEARING DISTANCE TEXT
  5. ;
  6. ; Copyright (C) 2011 CAD Concepts Limited.
  7. ; BEARING DISTANCE TEXT by CAD Concepts Ltd is licensed under
  8. ; a Creative Commons Attribution-ShareAlike 3.0 Unported License.
  9. ; http://creativecommons.org/licenses/by-sa/3.0/nz/deed.en
  10. ; For options available to you under this license.
  11. ; This software is provided "as is". No liability is taken of
  12. ; FITNESS FOR ANY PARTICULAR PURPOSE.
  13. ;------------------------------------------------------------------------------
  14. ; File          : BD.lsp
  15. ; Author        : Jason Bourhill
  16. ; Email         : jason@cadconcepts.co.nz
  17. ; Web                        : http://www.cadconcepts.co.nz
  18. ; Date          : 20/Mar/2011
  19. ; CAD Ver(s)        : Tested on AutoCAD 2010 & Bricscad V11
  20. ; Purpose       : Places Bearing & Distance text above and below selected lines
  21. ;
  22. ; Usage         : To load type (load "BD.LSP") from the command line or drag
  23. ;                                  and drop the file onto your drawing using explorer. Will
  24. ;                                  automatically run on loading.
  25. ;
  26. ;                                  Select a LINES or LIGHT WEIGHT POLYLINES on your drawing. Text
  27. ;                                  placed above the line will give the Bearing. Text placed
  28. ;                                  below the line gives the distance.
  29. ;                               
  30. ;                                  If you use inside a viewport from paperspace the routine will
  31. ;                                  automatically work out the scale factor. If you use in model
  32. ;                                  space you will be prompted for a scale factor.
  33. ;
  34. ;                                  Bearing given is always between 0 - 180 deg irrespective of
  35. ;                                  the direction the line has been drawn in.
  36. ;
  37. ;                                  Text is placed on the current layer using the default text
  38. ;                                  style. Text height is based on the text height for the
  39. ;                                  current dimension style.
  40. ;                                  
  41. ;                                  To run the routine again type BD at the command line.
  42. ;
  43. ;                                  NOTE in AutoCAD bearing gives a D instead of the degree symbol
  44. ;                                  in Bricscad you get the degree symbol.
  45. ;
  46. ; Requires      : Nothing else
  47. ;------------------------------------------------------------------------------
  48. ; Rev no   : A
  49. ; Reason   : First release
  50. ; Rev Date : 20/Mar/2011
  51. ; Rev by   : Jason Bourhill
  52. ; Email    : jason@cadconcepts.co.nz
  53. ;
  54. ; Description:
  55. ; First release.
  56. ;------------------------------------------------------------------------------
  57. (defun C:BD ( / ASK GETDWGSCALE  TEXTPOSITION LISTPLINEVER PLACETEXT sset num scalefac ent startpt endpt VerLst Ctr lstlen)
  58. ;ASK
  59. ;This routine allows default prompt issuing
  60. (defun ASK (typ prmpt def / val vt)
  61.    (setq vt (type def))
  62.    (cond ((null vt) (princ (strcat prmpt ": ")))
  63.          ((= vt 'STR) (princ (strcat prmpt " <" def ">: ")))
  64.          ((= typ 'ANG) (princ (strcat prmpt " <" (rtd def) ">: ")))
  65.          ((= vt 'REAL) (princ (strcat prmpt " <" (rtos def 2 2) ">: ")))
  66.          ((= vt 'INT) (princ (strcat prmpt " <" (itoa def) ">: ")))
  67.    )
  68.    (cond ((= typ 'R) (setq val (getreal)))
  69.          ((= typ 'S) (setq val (getkword)))
  70.          ((= typ 'ANG) (setq val (getangle)))
  71.          ((= typ 'DIST) (setq val (getdist)))
  72.          ((= typ 'INT) (setq val (getint)))
  73.          ((= typ 'STR) (setq val (getstring)))
  74.          ((= typ 'STRT)(setq val (getstring T)))
  75.    )
  76.    (if (or (= val "")(= val ())) def val)
  77. )
  78. ; find Drawing scale
  79. ; if user is inside a paperspace vport will work out dwgscale automatically
  80. ; if in paperspace set dwgscale = 1
  81. ; if in modelspace as user for dwgscale value
  82. ; Required as Bricscad doesn't support annotative text scaling
  83. (defun getdwgscale ( )
  84. (cond
  85. ((and (= 0 (getvar "TILEMODE")) (= 1 (getvar "CVPORT"))) ; in paperspace not inside a vport
  86.         (setq dwgscale 1)
  87. )
  88. ((and (= 0 (getvar "TILEMODE")) (> (getvar "CVPORT") 1)) ; in paperspace and inside a vport
  89.         (setq dwgscale (/ 1.0 (caddr (trans '(0 0 1) 2 3))))
  90. )
  91. ((= 1 (getvar "TILEMODE")) ; in modelspace, ask user for dwgscale
  92.         (if (not dwgscale) (setq dwgscale 0.5)) ; if not set, set dwgscale to 1:2000 assumes modelspace is in metres, and paperspace is mm
  93.         (setq dwgscale (ask 'R "Drawing scale factor 1= 1:100, 2 = 1:200, 3 = 1:500" dwgscale))
  94. )
  95. )
  96. dwgscale ; return dwgscale value
  97. ) ; end getdwgscale
  98. ; Find and return the Text postion and angle value
  99. ; adjusts position and angle based on which quadrant the angle falls in
  100. ; Note internally Lisp uses radians, with 0 at East position and measures anticlockwise.
  101. (defun textposition (LineMpt Langle TextOff / TestPos Langle)
  102. (cond
  103.          ((and (>= Langle 0 )(<= Langle (/ pi 2.0))) ; Langle between 0 - 90 degrees
  104.                 (setq TextPos (polar LineMpt (+ Langle (/ pi 2.0)) TextOff))
  105.                 (setq Langle Langle)
  106.          )
  107.          ((and (> Langle (/ pi 2.0))(<= Langle pi)) ; Langle between 90 - 180 degrees
  108.                 (setq TextPos (polar LineMpt (- Langle (/ pi 2.0)) TextOff))
  109.                 (setq Langle (- Langle pi))                       
  110.          )
  111.          ((and (> Langle pi)(<= Langle (* pi 1.5)))  ; Langle between 180 - 270 degrees
  112.                 (setq TextPos (polar LineMpt (- Langle (/ pi 2.0)) TextOff))
  113.                 (setq Langle (- Langle pi))                       
  114.          )
  115.          ((and (> Langle (* pi 1.5))(<= Langle (* pi 2.0)))  ; Langle between 270 - 360 degrees
  116.                 (setq TextPos (polar LineMpt (+ Langle (/ pi 2.0)) TextOff))
  117.                 (setq Langle Langle)
  118.          )
  119. )
  120. (list Textpos Langle) ; return the text position and angle as a list
  121. ) ; end textpostion
  122. ; List LWpline Vertices
  123. ; Iterates through presented list retaining only Lwpline vertices
  124. ; returns the vertices found as a list.
  125. (defun ListPlineVer (ent)
  126.    (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) ent))
  127. ) ;end ListPlineVer
  128. (defun PlaceText (startpt endpt dwgscale / Bunits Bprec Dunits Dprec dwgscale txtoff)
  129. ; Set BEARING display preferences
  130. ; Bunit Options are:
  131. ; 0 Degrees, 1 Degrees/minutes/seconds, 2 Grads, 3 Radians, 4 Surveyor's units
  132. (setq Bunits 1) ; Degrees/minutes/seconds
  133. (setq Bprec 4) ; Angle Precision, specifies the number of decimal places
  134. ; Set DISTANCE display preferences
  135. ; Dunit Options are:
  136. ; 1 Scientific, 2 Decimal, 3 Engineering (feet and decimal inches),
  137. ; 4 Architectural (feet and fractional inches), 5 Fractional
  138. (setq Dunits 2) ; Decimal
  139. (setq Dprec 2) ; Linear Precision, specifies the number of decimal places
  140. ; Set TEXT display options
  141. ; Text OFFSET. Distance that the text is offset from the line
  142. (setq txtoff (* 0.25 dwgscale))
  143. ;(setq txtoff (* (getvar dimgap) dwgscale)) could use dimgap if it is set to a reasonable value
  144. ; Text HEIGHT.
  145. (setq txtheight (* (getvar "DIMTXT") dwgscale)) ; use dimension text height
  146. (setq
  147.         ang (angle startpt endpt) ; find angle between two points
  148.         dis (distance startpt endpt) ; find distance between two points
  149.         midpt (polar startpt ang (/ dis 2.0)) ; find the midpoint between the two ponts
  150.         angtxtval (textposition midpt ang txtoff) ; Find Bearing Text Position and Angle
  151.         angtxtpos (car angtxtval) ; Bearing text position
  152.         angtxt (angtos (cadr angtxtval) 2 Bprec) ; returns angle as a text string
  153.         distxtpos (car (textposition midpt ang (* -1.0 (+ txtoff txtheight)))) ; Find Distance Text position below line, taking text height into account
  154.         distxt (rtos dis Dunits Dprec) ; returns distance as a text string
  155. )
  156. (entmake (list (cons 0 "TEXT") (cons 10 angtxtpos) (cons 40 txtheight) (cons 1 angtxt) (cons 50 (cadr angtxtval)) (cons 72 1) (cons 11 angtxtpos)))
  157. (entmake (list (cons 0 "TEXT") (cons 10 distxtpos) (cons 40 txtheight) (cons 1 distxt) (cons 50 (cadr angtxtval)) (cons 72 1) (cons 11 distxtpos)))
  158. ) ; end PlaceText
  159. ; Begin Main Program
  160. ;------------------------------------------------------------------------------
  161. (princ "\nSelect LINES or LWPOLYLINES to attach Bearing Distance to") ; Provide prompt
  162. (setq sset (ssget '((-4 . "<or")(0 . "LINE")(0 . "LWPOLYLINE")(-4 . "or>")))) ; select only LINES or Light Weight Polylines
  163. (if sset
  164.         (progn
  165.                 (setq num 0) ; zero counter
  166.                 ; Scale factor. Find drawing scale factor
  167.                 (setq scalefac (getdwgscale))
  168.                 (repeat (sslength sset) ; repeat for each object in the selection set
  169.                         (setq ent (entget(ssname sset num))) ; find entity properties
  170.                         (cond
  171.                                 ((= (cdr (assoc 0 ent)) "LINE")
  172.                                         (setq startpt (cdr (assoc 10 ent))) ; find the start point of the line
  173.                                         (setq endpt (cdr (assoc 11 ent))) ; find the end point of the line
  174.                                         (PlaceText startpt endpt scalefac) ; Place Bearing Distance Text
  175.                                 )
  176.                                 ((= (cdr (assoc 0 ent)) "LWPOLYLINE")
  177.                                         (setq VerLst (ListPlineVer ent)) ; find all the vertices for the pline
  178.                                         (setq ctr 0) ; Zero Counter
  179.                                         ; Step through each vertice in list and place bearing distance text accordingly
  180.                                         (if (= 1 (boole 1 1 (cdr (assoc 70 ent)))) ; check if the pline is Open or Closed
  181.                                                 (repeat (setq lstlen (length VerLst)) ; Assoc 70 = 1 pline Closed
  182.                                                         (if (= (1+ ctr) lstlen) ; Check if we are at the last vertice in the list
  183.                                                                 (setq
  184.                                                                         startpt (nth ctr verlst)
  185.                                                                         endpt (nth 0 verlst) ; endpoint = 1st vertice in list
  186.                                                                 )
  187.                                                                 (setq
  188.                                                                         startpt (nth ctr verlst)
  189.                                                                         endpt (nth (1+ ctr) verlst)
  190.                                                                 )
  191.                                                         )
  192.                                                         (PlaceText startpt endpt scalefac) ; Place Bearing Distance Text
  193.                                                         (setq ctr (1+ ctr)) ; iterate counter to next vertice in point list
  194.                                                 )
  195.                                                 (repeat (1- (length VerLst)) ; Assoc 70 = 0 pline Open
  196.                                                         (setq
  197.                                                                 startpt (nth ctr verlst)
  198.                                                                 endpt (nth (1+ ctr) verlst)
  199.                                                         )
  200.                                                         (PlaceText startpt endpt scalefac) ; Place Bearing Distance Text
  201.                                                         (setq ctr (1+ ctr)) ; iterate counter to next vertice in point list
  202.                                                 )
  203.                                         )
  204.                                 )
  205.                         )
  206.                         (setq num (1+ num)) ; Iterate counter to next object in selection set
  207.                 )
  208.         )
  209.         (princ "\nNo lines selected\n")
  210. )
  211. ) ;end main function
  212. ;(C:BD) ; run automatically on loading
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 06:46:18 | 显示全部楼层
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 07:02:31 | 显示全部楼层
 
Why not use TEXTSIZE System Variable, or annotative text style instead?
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 07:07:53 | 显示全部楼层
i dont know how
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 07:19:59 | 显示全部楼层
can anyone convert this lisp to give manualy the text size ????????????
回复

使用道具 举报

107

主题

615

帖子

575

银币

中流砥柱

Rank: 25

铜币
521
发表于 2022-7-6 07:28:59 | 显示全部楼层
the easy way is to do this
 
  1. (setq dwgscale (ask 'R "Drawing scale factor 1= 1:200, 2 = 1:500, 3 = 1:1000" dwgscale))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 18:33 , Processed in 0.561645 second(s), 64 queries .

© 2020-2025 乐筑天下

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