CADZealot Posted November 26, 2019 Posted November 26, 2019 Hello Everyone, I'm working on a GIS Application which is running with AutoCAD, in that we are placing some lines and structures, while placing that the annotation will be placced automatically middle point of that poly line. after that we need to align that as per the below image. is there any possible to align the blocks automatically. steps would be Select two Blocks--->Select the Line then the blocks should be alined automatically as per the below image. can anyone help me on this. Thanks in advance. Sample.dwg Quote
dlanorh Posted November 26, 2019 Posted November 26, 2019 I can't open your drawing as I'm using AutoCAD 2012. Quote
BIGAL Posted November 27, 2019 Posted November 27, 2019 (edited) Pretty straight forward. Pick line left end so work out angle of line left to right comparing pick point startpoint,endpoint Pick block1, get bounding box, lower left move and rotate pick block 2 use bounding box to get lower right, go -angle of line, move and rotate Just need time vl & ssget would be better *line PLEASE NOTE ADJUSTED THE INSERT POSITION OF BLOCK1 AND BLOCK2 to 0,0 by using bedit and moving text to 0,0, way to many problems to work as it was. ; move 2 blocks to line or pline ; By alanh Nov 2019 (defun c:moblk ( / pt1 py2 pt3 obj s d1 d2 temp dist) (defun *error* (errmsg) (princ "\nAn error has occurred in the programme. ") (princ "\nOr user exited incorrectly. ") (setvar 'osmode oldsnap) (princ) ) (setq oldsnap (getvar 'osmode)) (setvar 'osmode 512) (setq pt3 (getpoint "\nSelect left side inner wall near end : ")) (setq s (ssget pt3 (list (cons 0 "*line")))) (setq obj (vlax-ename->vla-object (ssname s 0))) (cond ( (= (vla-get-objectname obj) "AcDbPolyline")(setq pt2 (vlax-curve-getendpoint obj))(setq pt1 (vlax-curve-getstartpoint obj)) ) ( (= (vla-get-objectname obj) "AcDbLline")(setq pt2 (vlax-get Obj 'EndPoint))(setq pt1 (vlax-get Obj 'StartPoint)) ) ) (setq d1 (distance pt1 pt3)) (setq d2 (distance pt2 pt3)) (if (> d1 d2) (progn (setq temp pt1) (setq pt1 pt2) (setq pt2 temp) ) ) (setq ang (angle pt1 pt2)) (setvar 'osmode 0) (setq ent (car (entsel "Pick block 1"))) (setq obj (vlax-ename->vla-object ent)) (vla-GetBoundingBox obj 'minpoint 'maxpoint) (setq pointmin (vlax-safearray->list minpoint)) (setq pointmax (vlax-safearray->list maxpoint)) (Command "move" ent "" pointmin pt1) (vla-put-rotation obj ang) (setq ent (car (entsel "Pick block 2"))) (setq obj (vlax-ename->vla-object ent)) (vla-GetBoundingBox obj 'minpoint 'maxpoint) (setq pointmin (vlax-safearray->list minpoint)) (setq pointmax (vlax-safearray->list maxpoint)) (setq dist (- (car pointmax)(car pointmin))) (setq pt1 (polar pt2 (+ pi ang) dist)) (Command "move" ent "" pointmin pt1) (vla-put-rotation obj ang) (setvar 'osmode oldsnap) (princ) ) (c:moblk) Edited November 27, 2019 by BIGAL Quote
CADZealot Posted November 27, 2019 Author Posted November 27, 2019 12 minutes ago, BIGAL said: Pretty straight forward. Pick line left end so work out angle of line left to right comparing pick point startpoint,endpoint Pick block1, get bounding box, lower left move and rotate pick block 2 use bounding box to get lower right, go -angle of line, move and rotate Just need time vl & ssget would be better *line ; code done 1992 (setq tp1 (entsel "\nSelect left side near end : ")) (setq tpp1 (entget (car tp1) ) ) (setq pt1 (cdr (assoc 10 tpp1) ) ) (setq pt2 (cdr (assoc 11 tpp1) ) ) (setq pt3 (cadr tp1)) (setq d1 (distance pt1 pt3)) (setq d2 (distance pt2 pt3)) (if (> d1 d2) (progn (setq temp pt1) (setq pt1 pt2) (setq pt2 temp) ) ) (setq ang (angle pt1 pt2)) Hi BIGAL Thanks for your code I have cheked your code but i got an error like this, Select left side near end : ; error: bad argument type: 2D/3D point: nil Thanks Quote
CADZealot Posted November 27, 2019 Author Posted November 27, 2019 (edited) 9 hours ago, dlanorh said: I can't open your drawing as I'm using AutoCAD 2012. Thanks for your Reply dlanorh, I have attached older vertion file, please look at that. Thanks Sample_2007.dwg Edited November 27, 2019 by CADZealot Attachment missed Quote
BIGAL Posted November 27, 2019 Posted November 27, 2019 Updated the code while you posted. Read about blocks. Quote
CADZealot Posted November 27, 2019 Author Posted November 27, 2019 13 hours ago, BIGAL said: Updated the code while you posted. Read about blocks. Hi Bigal, I have checked the above code, it's working Partially. The first block placed over the line and the second one placed below the line, but i need to place both will be above the line with some spaces between Line and block (As below image) also it will work only with straight line, when i tried with bend line the rotation of the block will not changed.can we change the rotation as well. Note: The Second block justify is Middle, as i said its placed by default in GIS Application, i can't change that justify. Thanks Quote
marko_ribar Posted November 27, 2019 Posted November 27, 2019 You ask too much... Perhaps you could try to solve your task on your own... Quote
CADZealot Posted November 27, 2019 Author Posted November 27, 2019 1 hour ago, marko_ribar said: You ask too much... Perhaps you could try to solve your task on your own... I'm really Sorry marko, I'm not well in lisp, even i don't know to edit the program. I just run the program. and i just ask is there is possible. I really sorry for that. Quote
BIGAL Posted November 28, 2019 Posted November 28, 2019 Found a typo in the code it was to do with AcDbLLine so causes error You can change the block2 properties use BEDIT, I had to edit your block insertion point to make it work. Then run attsync pick blocks. I have not added the offset from line just needs to recalc the end points a slight offset from the line. Quote
CADZealot Posted November 28, 2019 Author Posted November 28, 2019 18 hours ago, BIGAL said: Found a typo in the code it was to do with AcDbLLine so causes error You can change the block2 properties use BEDIT, I had to edit your block insertion point to make it work. Then run attsync pick blocks. Hi Bigal, The blocks will be inserted by default settings in GIS using python scripts, i can't change or edit that blocks. instead of edit the block can we able to move as it is.? 18 hours ago, BIGAL said: I have not added the offset from line just needs to recalc the end points a slight offset from the line. As i'm not expert in a lisp, i can't find where i need to edit the lisp for recalculate the end point, can you please explain that. Thanks Quote
BIGAL Posted November 29, 2019 Posted November 29, 2019 Is every block a different name or only two ? The problem is your block example has the insertion point of the block as 0,0 that's ok but the text is at like 2000,3000. That's why I ask 1st question it is possible to move the insertion point to match the block text say a Lower left point. Are you happy for the block to be burst so make into text ? Then code works as is. Quote
CADZealot Posted November 29, 2019 Author Posted November 29, 2019 I 'm going to work only with this two blocks, and it has same name. the problem is,I can't able to edit and change the insertion point of block in GIS Application, also can't burst it. Attached the Actual Blocks which is inserted on GIS. Actual.dwg Quote
dlanorh Posted November 29, 2019 Posted November 29, 2019 Which block goes where? What happens if a line/polyline is constructed from right to left? Is the layout still the same or does it reflect the line/polyline? Quote
CADZealot Posted November 29, 2019 Author Posted November 29, 2019 1 hour ago, dlanorh said: Which block goes where? What happens if a line/polyline is constructed from right to left? Is the layout still the same or does it reflect the line/polyline? Hi dlanorh, Block1 (100mm conduit) should always appear in starting point of polyline & Block2 (40.0m) should appear in ending point of polyline,(as shown in attached image) Polylines can be constructed in any way, from left to right / Right to Left, but as mentioned above Block1 should be in starting point & simillarly Block2 should be in ending point of polyline. & it always reflects the polylines. Quote
Jack_O'neill Posted November 29, 2019 Posted November 29, 2019 On 11/27/2019 at 11:57 AM, marko_ribar said: You ask too much... Perhaps you could try to solve your task on your own... grumpy much? Quote
dlanorh Posted November 29, 2019 Posted November 29, 2019 OK. Try the attached. I minimally tested it on lines, single segment lwpolylines and multi segment polylines and it seems to work. The attribute height in the blocks was different so the lisp scales the "LENGTH_ANNO" block so that the attribute heights are the same size. The offset from the line is 0.2 x the height of the block. No Block attribute justifications or alignments are changed. The lisp uses the "Actual" names of the blocks and their layers. You are first asked to select the Alignment Line then the blocks (ssget). Both blocks can be selected together as the lisp knows which block needs to go where. Any problems let me know. AB2L.lsp Quote
CADZealot Posted November 30, 2019 Author Posted November 30, 2019 (edited) 12 hours ago, dlanorh said: OK. Try the attached. I minimally tested it on lines, single segment lwpolylines and multi segment polylines and it seems to work. The attribute height in the blocks was different so the lisp scales the "LENGTH_ANNO" block so that the attribute heights are the same size. The offset from the line is 0.2 x the height of the block. No Block attribute justifications or alignments are changed. The lisp uses the "Actual" names of the blocks and their layers. You are first asked to select the Alignment Line then the blocks (ssget). Both blocks can be selected together as the lisp knows which block needs to go where. Any problems let me know. AB2L.lsp 2.89 kB · 1 download awsome Well..Thank you so much dlanorh for your code it's working awesome. It's really working what i'm expecting but there is few changes needed on this code. actually both attributes should be different sizes as it is in Actual.dwg, is it possible to align the blocks without changing their heights. and if the attributes are in 0 degree rotation then only its aligned as per the Polyline rotation angle, or else its aligned to different rotation. can we able to align the blocks to the line rotation if the blocks already placed on any angle. Thanks again for you code Edited November 30, 2019 by CADZealot Quote
dlanorh Posted November 30, 2019 Posted November 30, 2019 3 hours ago, CADZealot said: Well..Thank you so much dlanorh for your code it's working awesome. It's really working what i'm expecting but there is few changes needed on this code. actually both attributes should be different sizes as it is in Actual.dwg, is it possible to align the blocks without changing their heights. and if the attributes are in 0 degree rotation then only its aligned as per the Polyline rotation angle, or else its aligned to different rotation. can we able to align the blocks to the line rotation if the blocks already placed on any angle. Thanks again for you code Try the attached. The blocks are now rotated to 0.0 before the bounding box is found. This solves the blocks at any rotation problem To align the blocks the same distance from the line it is neccessary for them to be the same size. The routine now rescales the "LENGTH_ANNO" block back close to its original size, using the new alignment (move) point. Due to the nature of the block and the scales involved this means using a scale factor of 1.333333333, which if you delve into the blocks scale factors with a large precision will not exactly return it to its original size (1.0) but maybe 0.9999999999998. AB2L-V2.lsp Quote
BIGAL Posted December 2, 2019 Posted December 2, 2019 (edited) Nice idea do bounding box at 0.0 rotation. Edited December 2, 2019 by BIGAL 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.