Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Swapping Block Location

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
jleford
756 Views, 7 Replies

Swapping Block Location

Is there a command that allows you to swap block locations.

 

In an ideal world I would love to be able to enter this command, select block 'A'  then select block 'B' and have them swap locations.

7 REPLIES 7
Message 2 of 8
Patchy
in reply to: jleford

Message 3 of 8
3wood
in reply to: jleford

Another method without additional routine is this:

Use command BLOCKREPLACE in Express Tools to replace

1. Create a temporary Block C

2. Replace all Block A with Block C

3. Replace all Block B with Block A

4. Replace all Block C with Block B

5. Delete and purge Block C

Message 4 of 8
jleford
in reply to: 3wood

I don't want to do a mass block replacement. It more of an isolated scenario. I literally want to swap block locations with out purging any blocks out of the drawing.
Message 5 of 8
hwalker
in reply to: jleford

A dirty workaround would be to draw a line between the insertion points of both blocks.

 

Then move both blocks at the same time to one end of the line. Then move the block which is left hanging to the other end of the line.

 

Or go into properties for each block one at a time, and note their x,y,z positions.

 

Then go into properties again and swap the x,y,z positon of the block you've chosen for the other block.

Howard Walker
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Left Handed and Proud

Message 6 of 8
Kent1Cooper
in reply to: Patchy


@Patchy wrote:

Follow this link:

....


Here's a more sophisticated version than what I posted there.  This one is tailored specifically to INSERT objects, has some selection controls, and uses a different method to move them, so there's no command echoing to deal with.

 

If you don't want it to accept other kinds of INSERT objects than Blocks [Xrefs, Minserts, Windows Metafiles, old-style Hatch patterns], additional controls could be added.

Kent Cooper, AIA
Message 7 of 8
p_mcknight
in reply to: jleford

The below code makes a command 'swap' to swap two block locations.  The blocks will inherit any mirroring, rotation, scaling, etc of the block they are being swapped with.  You may select the two blocks before executing the command or after.

 

(defun c:swap ( / objs vlobj1 vlobj2 block1Name block2Name)
  (setq objs (ssget))
  (if (= 2 (sslength objs))
    (progn
      (setq vlobj1 (vlax-ename->vla-object (ssname objs 0)))
      (setq vlobj2 (vlax-ename->vla-object (ssname objs 1)))
      (if (and (= "AcDbBlockReference" (vla-get-ObjectName vlobj1)) (= "AcDbBlockReference" (vla-get-ObjectName vlobj2)))
 (progn
   (setq block1Name (vla-get-Name vlobj1))
   (setq block2Name (vla-get-Name vlobj2))
   (vla-put-name vlobj1 block2Name)
   (vla-put-name vlobj2 block1Name)
   )
 (alert "One or more selected item is not a block. ")
 )
      )
    (alert "More or less than two objects are selected. ")
    )
  (princ)
  )

Message 8 of 8
jleford
in reply to: p_mcknight

Works great. Thanks

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost