Jump to content

Move Command moves anywhere (but not where I want it to)


Obi-Wahn

Recommended Posts

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 :oops: )

 

(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.1
5.26409e+006
1362.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...

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 .

Edited by Tharwat
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

I don't understand where the Blocks should be moved...

 

 

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 .

Link to comment
Share on other sites

Not saying it is a solution, but if you have access to AutoCAD Civil 3D, there are native commands to do just this...

Link to comment
Share on other sites

@Tharwat: Thank you very much! :thumbsup: That works like a charm.

May I ask where the Z-position gets changed? I don't see a single move command. :?

 

@Tiger: Yeah, I've seen that in my google research whilst I was searching for code. Unfortunately, he doesn't has access to Civil 3D. Thanks for the input though :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...