rock1 Posted June 2, 2017 Share Posted June 2, 2017 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. Quote Link to comment Share on other sites More sharing options...
maratovich Posted June 2, 2017 Share Posted June 2, 2017 If you can use the VBA ? In archive macro - AlingSquare.dvb AlingSquare.zip Quote Link to comment Share on other sites More sharing options...
SLW210 Posted June 2, 2017 Share Posted June 2, 2017 I moved your thread to the AutoLISP, Visual LISP & DCL Forum. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 2, 2017 Share Posted June 2, 2017 (edited) 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 June 3, 2017 by Tharwat Added a Circle object name to codes Quote Link to comment Share on other sites More sharing options...
rock1 Posted June 2, 2017 Author Share Posted June 2, 2017 If you can use the VBA ?In archive macro - AlingSquare.dvb How do I use this? Please give a step by step method Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 2, 2017 Share Posted June 2, 2017 @ rock1, Did not you try my codes in post number 4 yet? Quote Link to comment Share on other sites More sharing options...
rock1 Posted June 2, 2017 Author Share Posted June 2, 2017 @ rock1, Did not you try my codes in post number 4 yet? I don't know how to use this code. Quote Link to comment Share on other sites More sharing options...
rock1 Posted June 2, 2017 Author Share Posted June 2, 2017 I moved your thread to the AutoLISP, Visual LISP & DCL Forum. 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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 2, 2017 Share Posted June 2, 2017 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. Quote Link to comment Share on other sites More sharing options...
rock1 Posted June 3, 2017 Author Share Posted June 3, 2017 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. Quote Link to comment Share on other sites More sharing options...
Dadgad Posted June 3, 2017 Share Posted June 3, 2017 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. Quote Link to comment Share on other sites More sharing options...
rock1 Posted June 3, 2017 Author Share Posted June 3, 2017 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. Quote Link to comment Share on other sites More sharing options...
rock1 Posted June 3, 2017 Author Share Posted June 3, 2017 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 3, 2017 Share Posted June 3, 2017 (edited) Try changing the code to this See correct post by Tharwat below Edited June 3, 2017 by BIGAL Quote Link to comment Share on other sites More sharing options...
maratovich Posted June 3, 2017 Share Posted June 3, 2017 I am getting the following error when I try to load your dvb file. Do you have a vba installed? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 3, 2017 Share Posted June 3, 2017 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]")))) Quote Link to comment Share on other sites More sharing options...
maratovich Posted June 3, 2017 Share Posted June 3, 2017 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? An example of this AlingSquare2.zip Quote Link to comment Share on other sites More sharing options...
rock1 Posted June 5, 2017 Author Share Posted June 5, 2017 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 Quote Link to comment Share on other sites More sharing options...
maratovich Posted June 5, 2017 Share Posted June 5, 2017 Try installing for your version of autocad: https://knowledge.autodesk.com/search-result/caas/downloads/content/download-the-microsoft-visual-basic-for-applications-module-vba.html Quote Link to comment Share on other sites More sharing options...
SLW210 Posted June 5, 2017 Share Posted June 5, 2017 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. Try installing for your version of autocad:https://knowledge.autodesk.com/search-result/caas/downloads/content/download-the-microsoft-visual-basic-for-applications-module-vba.html 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.