乐筑天下

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

[编程交流] Autocad doesn't read my l

[复制链接]

17

主题

72

帖子

55

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 18:12:37 | 显示全部楼层 |阅读模式
Hellow, i'm trying to write a very simple code from scratch, i want it to read the angle position and width of a mtext. and if the angle is 0 (means the text is horizontal), then he performs a couple of replacements in code groups.
This is what I've manage to do:
 
  1. (defun c:ter2 ( / entitysel enty position angle newposition newangle substituteangle substituteposition)(setq entitysel  (car (entsel))             enty  (entget entitysel)              angle  (assoc 50 enty)               position (assoc 10 enty)           mtextwidth (assoc 41 enty))(if(= angle 0)                     (setq                               newposition '(10 . (cadr(position)) (- caddr(position) 0.25)) ;gets the coordinate x and y and for y lowers 0.25, all of this in the variable newposition                                  substituteposition (subst newposition position enty) ;defines something like a "method" that entmod will apply.        )                                (entmod substituteposition)         ;replaces the position)(princ))   
 
I know i can limit the object to mtext and i will implement a ssget later. But for now what i wanna know is why can't this code perform as i think he should, replacing the positioning of my text when he is horizontal
回复

使用道具 举报

17

主题

72

帖子

55

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 18:41:34 | 显示全部楼层
does it have to do with scope? maybe variable angle only has meaning inside the first setq parameters? but that would be dumb
回复

使用道具 举报

95

主题

477

帖子

383

银币

后起之秀

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

铜币
475
发表于 2022-7-5 18:57:35 | 显示全部楼层
I would instead make use of the vla-get-TextRotation function.
  1. (if (= (vla-get-TextRotation (vlax-ename->vla-object enty)) 0)Put rest of code)
This was just a quick code writing so I'm sorry if there is a mistake.
回复

使用道具 举报

1

主题

475

帖子

481

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 19:09:25 | 显示全部楼层
Perhaps something like this:
  1. (defun c:ter2 ( / entitysel enty position _angle newposition newangle substituteangle substituteposition)(setq entitysel  (car (entsel))             enty  (entget entitysel)              _angle  (cdr (assoc 50 enty))               position (assoc 10 enty)           mtextwidth (cdr (assoc 41 enty)))(if (= _angle 0)          (progn             (setq newposition (cons 10 (list (cadr position) (- (caddr position) 0.25))) ;gets the coordinate x and y and for y lowers 0.25, all of this in the variable newposition                   substituteposition (subst newposition position enty) ;defines something like a "method" that entmod will apply.        )             (entmod substituteposition) ;replaces the position             )          )(princ))
 
Hope this helps
Henrique
回复

使用道具 举报

10

主题

253

帖子

75

银币

后起之秀

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

铜币
223
发表于 2022-7-5 19:23:53 | 显示全部楼层
First of all, 'angle' is reserved word
Secondary, you forgot progn:
  1. (vl-load-com)(defun c:ter2 (/ ent ins) (if (= (type (setq ent (vl-catch-all-apply                          (function                            (lambda ()                              (ssget "_+.:S:E:L" '((0 . "MTEXT")))                              ) ;_ end of lambda                            ) ;_ end of function                          ) ;_ end of vl-catch-all-apply                    ) ;_ end of setq              ) ;_ end of type        'pickset        ) ;_ end of =   (progn     (setq ent (vlax-ename->vla-object (ssname ent 0))           ins (vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint ent)))           ) ;_ end of setq     (if (equal (vla-get-rotation ent) 0. 1e-3)       (vla-put-insertionpoint ent (vlax-3d-point (list (car ins) (- (caddr ins)) 0.25)))       ) ;_ end of if     ) ;_ end of progn   ) ;_ end of if ) ;_ end of defun
 
Ah, already answered:)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 19:29 , Processed in 0.536111 second(s), 62 queries .

© 2020-2025 乐筑天下

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