Jump to content

Move block based on a attribute in the block


Dormant

Recommended Posts

(defun c:MoveXY (/ ss i e xnew ynew r e)
 (vl-load-com)
 (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
  (repeat (setq i (sslength ss))
   (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
   (cond
    (and
	  (setq	xnew (assoc "X"
			   (mapcar
			    '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j))))
			    (vlax-invoke e 'Getattributes)
			   )
		     )
	  )
	  (setq	ynew (assoc "Y"
			   (mapcar
			    '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j))))
			    (vlax-invoke e 'Getattributes)
			   )
		     )
	  )
	  (vla-put-insertionpoint e (vlax-3d-point (list (cadr xnew) (cadr ynew))))
    )
   )
  )
 )
 (princ)
)

 

That should do it. You should just replace the two tagstrings "X" and "Y", since I don't know what your tags are for these two attributes.

 

  • Like 1
Link to comment
Share on other sites

After more testing, the result is sometimes nil in situations where I select blocks that have one or both XY attributes empty.

To be clear. Some of the blocks relatively often have empty attributes and in that case if I select both blocks that have correctly filled XY attributes and those blocks that have empty XY attributes then the program does not execute correctly or nil.

Is it possible to fine tune that too ?! thank you

Link to comment
Share on other sites

(defun c:MoveXY (/ ss i e xnew ynew)
 (vl-load-com)
 (if (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1))))
  (repeat (setq i (sslength ss))
   (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
   (cond
    (and
	  (setq	xnew (assoc "X"
			   (mapcar
			    '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j))))
			    (vlax-invoke e 'Getattributes)
			   )
		     )
	  )
	  (setq	ynew (assoc "Y"
			   (mapcar
			    '(lambda (j) (list (vla-get-tagstring j) (distof (vla-get-textstring j))))
			    (vlax-invoke e 'Getattributes)
			   )
		     )
	  )
          (if (and (cadr xnew) (cadr ynew))
	   (vla-put-insertionpoint e (vlax-3d-point  (list (cadr xnew) (cadr ynew))))
	  ) 
    )
   )
  )
 )
 (princ)
)

 

I have inserted the condition that the block only moves if the x and y coordinates exist.

 

(if (and (cadr xnew) (cadr ynew))
 (vla-put-insertionpoint e (vlax-3d-point  (list (cadr xnew) (cadr ynew))))
)

  • Like 1
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...