Jump to content

Move blocks with certain attribute to position of Text having same content as attribute


enthralled

Recommended Posts

Hi,

I have 4 block names:

AHS-1T, AHS-1TR, AHS-2T, AHS-2TR

They all have a text attribute called "TEE", with different values (e.g. N2096)

I have many of these 4 block types scattered, each having a distinct TEE attribute value,

on the other hand, I have a table where there are text objects having the same contents as the TEE attribute.

What I need is for the blocks to move to the position of the text which have the same content as the TEE value (eg block with Tee attribute "N2096" will move to the position of the text object which also reads "N2096".

Attached CAD Source and result for reference.

 

EDIT: just a tiny clarification, the block insertion point will match the X position of the text, but the Y position will be 148 units below the text. (although I can offset the Y position manually, so it's not a big deal). Thanks

 

Source.dwg Result.dwg

Edited by enthralled
Link to comment
Share on other sites

Don't know if you have multiple graphs so this will ask you to pick the "Row" to get the Y cords. x cords are pulled form the text. then its just a simple move command.

will display an error message if either multiple text are found or no text are found.

 

;;----------------------------------------------------------------------------;;
;; Move Blocks to graph location
(defun C:BlkMove (/ x y ss txt blk atts oTag)
  (setq y (cadr (getpoint "\nPick \"SPECIAL PIECES\" Row")))
  (prompt "\nSelect Blocks")
  (setvar 'cmdecho 0)
  (if (setq ss (ssget '((0 . "INSERT") (2 . "AHS-1T,AHS-1TR,AHS-2T,AHS-2TR") (66 . 1) (410 . "Model"))))
    (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (setq PT (cdr (assoc 10 (entget blk))))
      (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes (vlax-ename->vla-object blk)))))
      (foreach tag atts
        (if (eq (vla-get-tagstring tag) "TEE")
          (progn
            (setq oTag (vla-get-textstring tag))
            (if (setq txt (ssget "_X" (list '(0 . "*TEXT") (cons 1 oTag) '(410 . "Model"))))
              (if (eq (sslength txt) 1)
                (progn
                  (setq x (car (cdr (assoc 10 (entget (ssname txt 0))))))
                  (vl-cmdf "_.Move" blk "" "_non" PT "_non" (list x y))
                )
                (prompt (strcat "\nMultiple Text Found [" oTag "]"))
              )
              (prompt (strcat "\nText not Found [" oTag "]"))
            )
          )
        )
      )
    )
  )
  (setvar 'cmdecho 1)
  (princ)
)

 

  • Like 1
Link to comment
Share on other sites

Just saw this :

 

Quote

EDIT: just a tiny clarification, the block insertion point will match the X position of the text, but the Y position will be 148 units below the text. (although I can offset the Y position manually, so it's not a big deal). Thanks

 

Sorry for my bad insight and reaction...

  • Like 1
Link to comment
Share on other sites

On 2/25/2022 at 6:50 PM, mhupp said:

Don't know if you have multiple graphs so this will ask you to pick the "Row" to get the Y cords. x cords are pulled form the text. then its just a simple move command.

will display an error message if either multiple text are found or no text are found.

 

;;----------------------------------------------------------------------------;;
;; Move Blocks to graph location
(defun C:BlkMove (/ x y ss txt blk atts oTag)
  (setq y (cadr (getpoint "\nPick \"SPECIAL PIECES\" Row")))
  (prompt "\nSelect Blocks")
  (setvar 'cmdecho 0)
  (if (setq ss (ssget '((0 . "INSERT") (2 . "AHS-1T,AHS-1TR,AHS-2T,AHS-2TR") (66 . 1) (410 . "Model"))))
    (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (setq PT (cdr (assoc 10 (entget blk))))
      (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes (vlax-ename->vla-object blk)))))
      (foreach tag atts
        (if (eq (vla-get-tagstring tag) "TEE")
          (progn
            (setq oTag (vla-get-textstring tag))
            (if (setq txt (ssget "_X" (list '(0 . "*TEXT") (cons 1 oTag) '(410 . "Model"))))
              (if (eq (sslength txt) 1)
                (progn
                  (setq x (car (cdr (assoc 10 (entget (ssname txt 0))))))
                  (vl-cmdf "_.Move" blk "" "_non" PT "_non" (list x y))
                )
                (prompt (strcat "\nMultiple Text Found [" oTag "]"))
              )
              (prompt (strcat "\nText not Found [" oTag "]"))
            )
          )
        )
      )
    )
  )
  (setvar 'cmdecho 1)
  (princ)
)

 

Thanks for the help!

Also special thanks for allowing me to pick the row for the special pieces. This is so neat :)

Edited by enthralled
  • 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...