Jump to content

Aligning centres quickly


rock1

Recommended Posts

I have five rectangles as closed polylines. Is there a quick way to align their centres vertically quickly as shown in the screenshot? I am currently making a vertical line passing through one of the centres of rectangle and then moving individual rectangles one by one.

rectangle.jpg

Link to comment
Share on other sites

Hi,

 

Written in haste.

 

(defun c:Test (/ sel int ent pts lst l r x)
 ;;------------------------------------;;
 ;; Tharwat - Date: 02.June.2017	;;
 ;;------------------------------------;;
 (if (setq sel (ssget "_:L" '((0 . "LWPOLYLINE[color="magenta"],CIRCLE[/color]"))))
   (progn
     (repeat (setq int (sslength sel))
       (setq ent (vlax-ename->vla-object (ssname sel (setq int (1- int))))
       )
       (vla-getboundingbox ent 'l 'r)
       (setq pts (mapcar 'vlax-safearray->list (list l r))
             lst (cons (list (mapcar '(lambda (q p) (/ (+ q p) 2.0)) (car pts) (cadr pts) ) ent ) lst ) )
       )
     (setq l (vl-sort lst '(lambda (a b) (> (cadar a) (cadar b))))
           x (caaar l)
          )
     (foreach obj (cdr l)
       (vla-move (cadr obj) (vlax-3d-point (car obj)) (vlax-3d-point (list x (cadr (car obj)) 0.)))
     )
   )
 )
 (princ)
) (vl-load-com)

Edited by Tharwat
Added a Circle object name to codes
Link to comment
Share on other sites

If you can use the VBA ?

In archive macro - AlingSquare.dvb

 

How do I use this? Please give a step by step method

Link to comment
Share on other sites

I don't know how to use this code.

 

Copy the codes into a txt file and save it with .lsp format. eg: Test.lsp then go back to AutoCAD and call the command APPLOAD or just AP then select the newly created lisp file.

 

Now type Test in AutoCAD and select the fore-said polylines as shown into your first post.

 

Waiting for your kind reply.

Link to comment
Share on other sites

Copy the codes into a txt file and save it with .lsp format. eg: Test.lsp then go back to AutoCAD and call the command APPLOAD or just AP then select the newly created lisp file.

 

Now type Test in AutoCAD and select the fore-said polylines as shown into your first post.

 

Waiting for your kind reply.

 

Thanks. :) It works only for rectangles, polygons and any irregularly shaped closed polyline. However, I tried your lsp with circles and it did not work.

Link to comment
Share on other sites

Thanks. :) It works only for rectangles, polygons and any irregularly shaped closed polyline. However, I tried your lsp with circles and it did not work.

 

Nicely done Tharwat! :)

 

Are you disappointed that it only does EXACTLY what you asked for,

and fails to do everything else that you didn't?

As the saying goes, "Be careful what you ask for, you might get it." :|

 

Circles are a piece of cake, no lisp required, see screenshot.

Just Select all the circles you want to align, enter the value you want them to all have in their Center X field in Properties, or Quick Properties.

The column of circles on the right has had a single value entered into that field.

align circles with quick properties.JPG

Link to comment
Share on other sites

If you can use the VBA ?

In archive macro - AlingSquare.dvb

 

I am getting the following error when I try to load your dvb file.

 

ERROR.png

Link to comment
Share on other sites

Are you disappointed that it only does EXACTLY what you asked for,

and fails to do everything else that you didn't?

As the saying goes, "Be careful what you ask for, you might get it." :|

 

Circles are a piece of cake, no lisp required, see screenshot.

Just Select all the circles you want to align, enter the value you want them to all have in their Center X field in Properties, or Quick Properties.

The column of circles on the right has had a single value entered into that field.

 

Oh! Thanks! :) Is there a way I can align all the circles by just specifying one circle and aligning all the rest of others with its centre without manually entering it? I'm asking for this because I have used alignments of centres, lefts, bottoms and tops in Adobe PHotoshop and Illustrator and they have a very fast method of aligning objects with respect to one object, page or selection. I'm looking for such commands here.

Link to comment
Share on other sites

Thanks. :) It works only for rectangles, polygons and any irregularly shaped closed polyline. However, I tried your lsp with circles and it did not work.

You are welcome. :)

Nicely done Tharwat! :)

 

Thank you Dadgad. :)

 

@rock1,

 

Just add Circle object name in the selection set with comma in prior as follows :

 

(setq sel (ssget "_:L" '((0 . "LWPOLYLINE[color="magenta"][b],CIRCLE[/b][/color]"))))

Link to comment
Share on other sites

Do you have a vba installed?

 

I don't know. Maybe it got installed with autocad or any microsoft product automatically. I dont see it listed in my installed programs list in the control panel

Link to comment
Share on other sites

Because of this, people are thinking that I know codes, techie language stuff of autocad. I'm an architect with zero knowledge of computer language, scripts, codes, etc.

 

What you want to do requires programming, you don't have to know anything about coding, just learn to save and execute them. Your thread belongs here.

 

 

If the OP has AutoCAD 2012 and doesn't already have the VBA module they will need to upgrade, it is no longer available for AutoCAD 2013 and older.

 

https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/Unable-to-download-VBA-Enabler-for-previous-versions-of-AutoCAD.html

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