Obi-Wahn 发表于 2022-7-5 22:47:37

Move Command moves anywhere (b

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)
 

(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:

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...

Tharwat 发表于 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 .

Obi-Wahn 发表于 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

Tharwat 发表于 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 .

Tharwat 发表于 2022-7-5 23:13:36

Try this Andy and let me know .
UNTESTED .
 

(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 .

ur_naz 发表于 2022-7-5 23:18:33

while using command methods check if osmode and osnapz are set to zero

Obi-Wahn 发表于 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.

Tharwat 发表于 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 .

Tiger 发表于 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...

Tharwat 发表于 2022-7-5 23:40:43

Try again.
页: [1] 2
查看完整版本: Move Command moves anywhere (b