Anh Quan Posted May 8, 2023 Posted May 8, 2023 move block.dwg I really need your help, I have 2 blocks next to each other but their center is not horizontal I want them to be aligned horizontally by AutoLISP as the picture depicts can someone help me. (I don't know anything about Lisp) Quote
CyberAngel Posted May 8, 2023 Posted May 8, 2023 Have you looked into point filters? That would be much easier than writing a function. Select the green block and the insertion grip. It asks for a destination point. Type .Y and give it the insertion point of the red block. That takes the Y coordinate of your point and lets you then specify the X and Z. Drag down the green block (the block's X is assumed) and place it. If you have to do that a thousand times, yes, write a function. If you only have to do it once, try the filter. 1 Quote
Anh Quan Posted May 8, 2023 Author Posted May 8, 2023 16 minutes ago, CyberAngel said: Have you looked into point filters? That would be much easier than writing a function. Select the green block and the insertion grip. It asks for a destination point. Type .Y and give it the insertion point of the red block. That takes the Y coordinate of your point and lets you then specify the X and Z. Drag down the green block (the block's X is assumed) and place it. If you have to do that a thousand times, yes, write a function. If you only have to do it once, try the filter. Thank you, however I have to do it many times and don't know the lisp skill :( Quote
devitg Posted May 8, 2023 Posted May 8, 2023 7 hours ago, Anh Quan said: Thank you, however I have to do it many times and don't know the lisp skill @Anh Quan Find attached lisp to test align block-references+while.LSP 1 Quote
Steven P Posted May 9, 2023 Posted May 9, 2023 Try this, block2snap (defun c:block2snap ( / SnapStart Xstart Ystart Zstart snap blkset LenSet Ecount Ename Edata InsPt Xins Yins Zins Xround Yround Zround PtRound NewInsData newdata xoffset yoffset zoffset txtsize) (defun *error* ( msg ) (if doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun blksnap (val incr base / Snapdist NewNum NuymSteps Rounded NewCoord) (setq Snapdist (- val base) NewNum (/ Snapdist incr) NumSteps (atoi (rtos NewNum 2 0)) Rounded (* NumSteps incr) NewCoord (+ base rounded) ) ) (setq xoffset 0) (setq yoffset 0) (setq zoffset 0) (setq SnapStart (getvar "SNAPBASE")) (setq Xstart (car SnapStart) YStart (cadr SnapStart) ZStart (caddr SnapStart) ) (setq snap 2.5) ;;default snap distance (if (= xsnap nil)(setq xsnap snap)) (if (= ysnap nil)(setq ysnap snap)) (if (= zsnap nil)(setq zsnap 0)) (if (= MWidth nil)(setq MWidth snap)) (setq snap (getreal (strcat "\nEnter x-axis snap spacing (" (rtos xsnap) "): " ) )) (if (/= snap nil)(progn (setq xsnap snap) (setq ysnap snap) )) (setq snap (getreal (strcat "\nEnter y-axis snap spacing (" (rtos ysnap) "): " ) )) (if (/= snap nil)(setq ysnap snap)) (setq zsnap (getreal (strcat "\nEnter z-axis snap spacing (" (rtos zsnap) ")(set to 0 to set Z axis to 0): " ) )) (if (/= zsnap nil)(setq zsnap 0)) (setq blkset (ssget '((0 . "INSERT")))) (setq LenSet (sslength blkSet)) (setq Ecount 0) (repeat LenSet (setq Ename (ssname blkset Ecount) Edata (entget Ename) mycons 10) ;;Cons for entity reference 10 = block coordinates (setq InsPt (cdr (assoc mycons Edata)) Xins (car InsPt) Yins (cadr InsPt) Zins (caddr InsPt) Xround (blksnap Xins xsnap xstart) YRound (blksnap Yins ysnap ystart) ZRound (blksnap Zins ysnap ystart) PtRound (list (+ Xround xoffset) (+ YRound yoffset)) PtRound (list (+ Xround xoffset) (+ YRound yoffset) (+ ZRound zoffset)) NewInsData (cons mycons PtRound) Newdata (subst NewInsdata (assoc mycons Edata) Edata) ) (if (= "INSERT" (cdr (assoc 0 Edata))) (entmod Newdata)) (setq ECount (1+ Ecount)) ) (princ) ) 1 Quote
Anh Quan Posted May 11, 2023 Author Posted May 11, 2023 On 5/9/2023 at 5:10 AM, devitg said: @Anh Quan Find attached lisp to test align block-references+while.LSP 4.12 kB · 8 downloads Yeah, It solved my problem, thank you very much. Quote
Anh Quan Posted May 11, 2023 Author Posted May 11, 2023 On 5/9/2023 at 3:08 PM, Steven P said: Try this, block2snap (defun c:block2snap ( / SnapStart Xstart Ystart Zstart snap blkset LenSet Ecount Ename Edata InsPt Xins Yins Zins Xround Yround Zround PtRound NewInsData newdata xoffset yoffset zoffset txtsize) (defun *error* ( msg ) (if doc (_EndUndo doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun blksnap (val incr base / Snapdist NewNum NuymSteps Rounded NewCoord) (setq Snapdist (- val base) NewNum (/ Snapdist incr) NumSteps (atoi (rtos NewNum 2 0)) Rounded (* NumSteps incr) NewCoord (+ base rounded) ) ) (setq xoffset 0) (setq yoffset 0) (setq zoffset 0) (setq SnapStart (getvar "SNAPBASE")) (setq Xstart (car SnapStart) YStart (cadr SnapStart) ZStart (caddr SnapStart) ) (setq snap 2.5) ;;default snap distance (if (= xsnap nil)(setq xsnap snap)) (if (= ysnap nil)(setq ysnap snap)) (if (= zsnap nil)(setq zsnap 0)) (if (= MWidth nil)(setq MWidth snap)) (setq snap (getreal (strcat "\nEnter x-axis snap spacing (" (rtos xsnap) "): " ) )) (if (/= snap nil)(progn (setq xsnap snap) (setq ysnap snap) )) (setq snap (getreal (strcat "\nEnter y-axis snap spacing (" (rtos ysnap) "): " ) )) (if (/= snap nil)(setq ysnap snap)) (setq zsnap (getreal (strcat "\nEnter z-axis snap spacing (" (rtos zsnap) ")(set to 0 to set Z axis to 0): " ) )) (if (/= zsnap nil)(setq zsnap 0)) (setq blkset (ssget '((0 . "INSERT")))) (setq LenSet (sslength blkSet)) (setq Ecount 0) (repeat LenSet (setq Ename (ssname blkset Ecount) Edata (entget Ename) mycons 10) ;;Cons for entity reference 10 = block coordinates (setq InsPt (cdr (assoc mycons Edata)) Xins (car InsPt) Yins (cadr InsPt) Zins (caddr InsPt) Xround (blksnap Xins xsnap xstart) YRound (blksnap Yins ysnap ystart) ZRound (blksnap Zins ysnap ystart) PtRound (list (+ Xround xoffset) (+ YRound yoffset)) PtRound (list (+ Xround xoffset) (+ YRound yoffset) (+ ZRound zoffset)) NewInsData (cons mycons PtRound) Newdata (subst NewInsdata (assoc mycons Edata) Edata) ) (if (= "INSERT" (cdr (assoc 0 Edata))) (entmod Newdata)) (setq ECount (1+ Ecount)) ) (princ) ) it seems for me to be able to enter the spacing, however i don't understand the axis spacing. sir Quote
Steven P Posted May 11, 2023 Posted May 11, 2023 Yes, my one doesn't line the blocks up with each other but lines them up with a grid spacing which is where the axis comes into it. I assumed that the blocks would be nearly lined up and so lining both to grid will line them up. For example if one is a at Y axis 10.587 and the other at 9.55, set the grid spacing to say, 2.5 and they will both be moved to Y axis value of 10 1 Quote
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.