乐筑天下

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

[编程交流] 文本问题

[复制链接]

12

主题

44

帖子

32

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
60
发表于 2022-7-5 15:46:11 | 显示全部楼层 |阅读模式
我有这些lisps函数,应该在多段线顶点上绘制圆并命名它们。
我知道代码看起来可能非常业余。我留下了一些垃圾,不检查错误等。现在不要担心(除非这是导致问题的原因),好吗?
 
我在命名方面遇到了一些麻烦。应该有前缀、加零(使所有名称具有相同的位数)和顺序编号。
 
有时代码有效,有时无效。当文件是新的时,它保证工作,当我有一个被很多人弄乱的旧文件时,我永远不知道会出现什么。
所以我一直在将多段线复制到新文件中,并将结果导出到完整、混乱的文件中。
当文本出现错误时,它通常会反转(比如90度)并显示“0.0000000”-我不知道有多少位小数。
 
我认为弦被角度放错了位置,角度应该是“0”。
我还认为,有时,根据文件的不同,“text”命令的参数应该更少。
如何确保这是问题所在,如何解决?
 
代码:
 
  1. ;Setup the variables - variable names and comments in portuguese, sorry
  2. (setq raio 2.0)
  3. (setq altura 1.5)
  4. (setq dx 1.0)
  5. (setq dy 3.0)
  6. (setq angulo 0.0)
  7. (setq prefixo "PV")
  8. (setq proximopv 1)
  1. (defun c:criaPVs(/ pts e pt pvmax);
  2. (vl-load-com); Garante que o ActiveX esteja ligado
  3. (setq e (car (entsel "\nClique na polyline")))
  4. ; cria uma lista com os pontos
  5. ; os pontos são os elementos da polilinha sob o índice 10
  6. (setq pts (mapcar 'cdr; elimina os primeiros elementos - os índices - de cada ponto da lista a ser criada
  7.         ; cria uma lista com as propriedades da polilinha, removendo tudo o que não for ponto
  8.         (vl-remove-if-not
  9.                 (function (lambda (pt) (= (car pt) 10)))
  10.                 (entget e)
  11.         )
  12.         );esse parêntese é do mapcar
  13. )
  14. (setq pvmax (+ (length pts) (- proximopv 1)))
  15. (foreach pt pts
  16.         (setq txt (settexto proximopv pvmax)); define o texto a colocar no PV
  17.         (despv pt raio altura dx dy angulo txt);cria o PV
  18. )
  19. )
  1. (defun despv(ponto raio altura dx dy angulo texto); desenha o pv, com círculo e texto
  2. (if (> raio 0)
  3.         (command "circle" ponto raio)
  4. )
  5. (command "text" (mapcar '+ ponto (list dx dy)) altura angulo texto)
  6. (setq proximopv (+ proximopv 1));atualiza o contador
  7. )
  1. (defun addzeros(nz / tx);cria um texto com tantos zeros quanto entrados em nz
  2. (setq tx "")
  3. (while (> nz 0)
  4.         (setq tx (strcat tx "0"))
  5.         (setq nz (- nz 1))
  6. )
  7. tx
  8. )
  1. (defun countdigits(n / nd); conta quantos dígitos tem um número
  2. (if (< n 10)
  3.         (setq nd 1)
  4.         (setq nd (+ 1 (countdigits (/ n 10))))
  5. )
  6. nd
  7. )
  1. (defun settexto(cont vlrmax / txt); define o texto a ser escrito no pv
  2. ;concatena o prefixo, os zeros que compõem o número e o número
  3. (setq txt (strcat prefixo (addzeros(- (countdigits vlrmax) (countdigits cont))) (itoa cont)))
  4. txt
  5. )
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 17:36:34 | 显示全部楼层
我的尝试
 
  1. ; pline co-ords example
  2. ; By Alan H
  3. (defun getcoords (ent)
  4. (vlax-safearray->list
  5.    (vlax-variant-value
  6.      (vlax-get-property
  7.    (vlax-ename->vla-object ent)
  8.    "Coordinates"
  9.      )
  10.    )
  11. )
  12. )
  13. (defun co-ords2xy ()
  14. ; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
  15. (setq len (length co-ords))
  16. (setq numb (/ len 2)) ; even and odd check required
  17. (setq I 0)
  18. (repeat numb
  19. (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
  20. ; odd (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
  21. (setq co-ordsxy (cons xy co-ordsxy))
  22. (setq I (+ I 2))
  23. )
  24. )
  25. ; program starts here
  26. (defun c:labelpoly ( / ent x y co-ordsxy pt )
  27. (while (setq ent (car (entsel "\nPlease pick pline <Cr> to exit")))
  28. (setq co-ords (getcoords ent))
  29. (co-ords2xy) ; list of 2d points making pline
  30. (setq co-ordsxy (reverse co-ordsxy))
  31. (setq x (Getint "Enter start number"))
  32. (setq y 0)
  33. (repeat (length co-ordsxy)
  34. (setq pt (list (nth 0 (nth y co-ordsxy))(nth 1 (nth y co-ordsxy))))
  35. (if (< x 10)
  36. (setq newstr2 (strcat "0" (rtos x 2 0)))
  37. (setq newstr2 (rtos x 2 0))
  38. )
  39. (command "-text" pt 2.5 90 newstr2)
  40. (command "circle" pt 5)
  41. (setq y (+ y 1))
  42. (setq x (+ x 1))
  43. )
  44. )
  45. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 00:10 , Processed in 0.415632 second(s), 67 queries .

© 2020-2025 乐筑天下

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