乐筑天下

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

[编程交流] Move Command moves anywhere (b

[复制链接]

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 22:47:37 | 显示全部楼层 |阅读模式
Hi!
 
A buddy of mine asked me yesterday if I could help him with a little problem.
He got a DWG with blocks that contain a attribute called "Z" which contains the actual height of the point in the drawing.
But the block isn't located at this height, it is at Z=0
 
The only way to solve this problem fairly fast was in my opinion a lisp command.
 
So I searched the web a bit and found some commands and after fiddling around a bit it worked to read the attribute.
I made a coord-set and tried to move it there but without success.
 
Now I've tinkered with autolisp before, but only beginners stuff and it was years ago.
 
So maybe you could help me what I've done wrong.
 
Currently the command contains only for one block, but my goal would be to move all blocks at once. (I could use some help there too  )
 
  1. (defun c:test ( / entity newZ block tag posX posY newPos )   ; select block   (setq entity (entsel "\nChoose block:"))   ; convert entity to vla-object   (setq block (vlax-ename->vla-object (car entity)))   ; set tag to uppercase (currently hardcoded)   (setq tag (strcase "Z"))   ; retrieve X and Y position from the block   (setq posX (nth 0 (cadr entity)))   (setq posY (nth 1 (cadr entity)))   ; query Z position from the block attribute   (setq newZ (vl-some '(lambda ( attr ) (if (= tag (strcase (vla-get-tagstring attr))) (atof (vla-get-textstring attr))))       (vlax-invoke block 'getattributes)   ))   ; set newPos to the new coords   (setq newPos (list posX posY newZ))   ; move the block accordingly to the new coordinates   (command "_.move" (car entity) "" (cadr entity) "" newPos )   ; some debugging   (print posX)   (print posY)   (print newZ)   (print newPos))
Thank you for your advice
Andy
 
PS.: The current "debugging" Output is:
  1. 97894.15.26409e+0061362.75(97894.1 5.26409e+006 1362.75) (97894.1 5.26409e+006 1362.75)
I don't know how exactly these coordinates are since the Y-Coordinate has that "weired" scientific writing style. I've never had this happen before...
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 22:57:13 | 显示全部楼层
Welcome to CADTutor
 
What do you mean by the height of the point ? does it mean the Z coordinate ?
Then what do you want to do with the Z attribute in that block ?
 
More info is needed in my opinion or a sample drawing with before and after process would help a lot .
回复

使用道具 举报

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 22:58:41 | 显示全部楼层
Hi!
 
Thanks for your reply.
 
Unfortunately I can't supply a example drawing but I'll explain as much as I can.
 
Basically the drawing represents a map with blocks which represent GPS markers.
Each block (=marker) has a X and Y position but the Z position is at zero.
However, each block has three attributes which one of them is the attribute called "Z" containing the elevation (position z) of that marker.
Now my buddy has the unfortunate task to move every marker to position Z according to the value from the attribute "Z".
 
His work would be selecting a marker copying the value from the attribute "Z" and pasting them to position Z. He asked me for my help since it's ok for say 50 markers, but occasionally he has maps to work with that has as many as 200-500 markers and he thought that there would be an faster way to do that.
 
I hope this makes things more clear.
Thanks in advance
Andy
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 23:05:44 | 显示全部楼层
Okay ‚ I will write a routine for you when I get back to my laptop in an hour or so .
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 23:13:36 | 显示全部楼层
Try this Andy and let me know .
UNTESTED .
 
  1. (defun c:Test (/ ss) ;;    Tharwat 09.July.2014        ;; (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "C1-PNT5") (66 . 1))))   ((lambda (i / sn o z p e)      (while (setq sn (ssname ss (setq i (1+ i))))        (foreach x (vlax-invoke (setq o (vlax-ename->vla-object sn)) 'GetAttributes)          (if (and (eq (strcase (vla-get-tagstring x)) "Z")                   (numberp (read (setq z (vla-get-textstring x))))                   (vlax-write-enabled-p o)              )            (entmod              (subst (cons 10 (list (car (setq p (cdr (assoc 10 (setq e (entget sn)))))) (cadr p) (atof z)))                     (assoc 10 e)                     e              )            )          )        )      )    )     -1   ) ) (princ))(vl-load-com)
Note: I assumed that the name of the block is marker , so if it is not correct , just change the name that is at the top of the routine .
回复

使用道具 举报

1

主题

20

帖子

12

银币

初来乍到

Rank: 1

铜币
14
发表于 2022-7-5 23:18:33 | 显示全部楼层
while using command methods check if osmode and osnapz are set to zero
回复

使用道具 举报

1

主题

4

帖子

3

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 23:22:10 | 显示全部楼层
Hi!
 
Thank you for your code.
It sure does something but doesn't move the block(s).
I've changed the markername in the lisp (it is "C1-PNT5")
 
I don't understand where the Blocks should be moved...
 
Maybe it is because the markerblocks are on different layers?!?
 
 
 
@ur_naz:
Thanks, I'll check and try implementing.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 23:30:43 | 显示全部楼层
 
Selected blocks should be moved to Z coordinates , to see the changes just select any of these blocks and press Ctrl+1 to invoke the property palette on .
回复

使用道具 举报

14

主题

719

帖子

706

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
70
发表于 2022-7-5 23:32:08 | 显示全部楼层
Not saying it is a solution, but if you have access to AutoCAD Civil 3D, there are native commands to do just this...
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 23:40:43 | 显示全部楼层
[codeS UPDATED] Try again.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 03:17 , Processed in 0.780653 second(s), 72 queries .

© 2020-2025 乐筑天下

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