acad1985 Posted August 1, 2018 Share Posted August 1, 2018 Hello Everyone, In my drawing file, there is lot of attributes to Align as per standard. (Attribute are in Block Reference). It will take lots of time to do with Manual. All the attribute are in middle of the polyline. I want to align automatically through lisp. So that when run the command, ATT1 should move and aligned to Starting point of Poly line, and ATT2 should move and aligned to End point of Poly line (Please see the attached .dwg file) Sample.dwg Please help me anyone to do with lisp. Thanks in Advance. Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted August 1, 2018 Share Posted August 1, 2018 (edited) Maybe you have posted the wrong dwg? There are no block references with attributes, instead there are attribute definitions and none of these is aligned with the end point of a polyline. Furthermore Case 1 and Case 3 seem to be exactly the same and yet the desired result is different? EDIT: You may also want to look at the case where the Case 1 polyline runs from top right to bottom left. Edited August 1, 2018 by Roy_043 Quote Link to comment Share on other sites More sharing options...
acad1985 Posted August 1, 2018 Author Share Posted August 1, 2018 (edited) Hi Roy, Maybe you have posted the wrong dwg? Yes, I have uploaded Wrong DWG. Please look at this updated one. Sample.dwg Furthermore Case 1 and Case 3 seem to be exactly the same and yet the desired result is different? Actually i need to align three different cases as per space available in Drawing. Thanks Edited August 1, 2018 by acad1985 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 2, 2018 Share Posted August 2, 2018 Can be done pick pline line arc spline etc near what you want as start pt so att1 goes to this end. Then window the atts. Result is drawn. The reason for picking is if you just use startpoint, endpoint it may draw the atts on wrong ends. Line drawn to right v's to left. Needs a few simple defuns, I am sure someone will post, I need to find the group of defuns and have to do real work now. A start http://www.cadtutor.net/forum/showthread.php?104805-Measure-with-Flip-Option Quote Link to comment Share on other sites More sharing options...
acad1985 Posted August 3, 2018 Author Share Posted August 3, 2018 HI Bigal, Sorry for the Delay. Actually I didn't understand what you said, and also i'm not a expert in Lisp. Could you please Help me on this. Thanks Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 6, 2018 Share Posted August 6, 2018 (edited) Sorry been busy lately no spare time, will see if I can find time tonight, some else can jump in. Part 2 now having a play a couple of problems like the block attribute is at an odd angle does not help automating. Please where are the att1 & att2 values are coming from I have ignored picking ex blocks rather insert them at correct location when creating. testing lines plines and arcs. Edited August 6, 2018 by BIGAL Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 7, 2018 Share Posted August 7, 2018 Here is something to look at, it needs a fair bit of work, still I corrected the blocks angle so it worked properly and removed the need for extra coding, it needs the text position to be played with and a check for readability. I still dont see the need to insert the blocks 1st rather than adding at ends. (defun stend ( / d1 d2 temp) (setq stpt (vlax-curve-getstartPoint Obj) endpt (vlax-curve-getEndPoint Obj) d1 (distance stpt pt) d2 (distance endpt pt) ) (if (> d1 d2) (progn (setq temp stpt) (setq stpt endpt) (setq endpt temp) ) ) ) (defun ispline ( / co-ordsxy I xy co-ords numb len ang1 ang2) (stend) (setq co-ords (vlax-safearray->list (vlax-variant-value (vlax-get-property obj "Coordinates" ) ) ) ) (setq len (length co-ords)) (setq numb (/ len 2)) (setq I 0) (repeat numb (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) )) (setq co-ordsxy (cons xy co-ordsxy)) (setq I (+ I 2)) ) (alert"check direction here") (setq ang1 (angle (nth 1 co-ordsxy)(nth 0 co-ordsxy))) (if (= numb 2) (setq ang2 ang1) (setq ang2 (angle (nth (- numb 1) co-ordsxy)(nth (- numb 2) co-ordsxy))) ) (command "-insert" "att1" endpt 1 "" ang1 (rtos (car stpt) 2 2 )) (command "-insert" "att2" stpt 1 "" ang2 (rtos (cadr stpt) 2 2 )) ) (defun isline ( / ang) (stend) (setq ang (angle stpt endpt)) (command "-insert" "att1" stpt 1 "" ang (rtos (car stpt) 2 2 )) (command "-insert" "att2" endpt 1 "" ang (rtos (car stpt) 2 2 )) ) (defun isarc ( / ) (alert "Non supported item at this time")(exit) ) (defun iscirc ( / ) (alert "Non supported item at this time")(exit) ) ;;;; starts here (defun endptlabel1 ( / ent) (setq ent (entsel "pick object near end for start")) (SETQ ANGBASEE (GETVAR "ANGBASE")) (SETQ ANGDIRR (GETVAR "ANGDIR")) (SETQ AUNITSS (GETVAR "AUNITS")) (SETVAR "ANGBASE" 0.0) (SETVAR "ANGDIR" 0) (SETVAR "AUNITS" 3) (setq pt (cadr ent)) (setq obj (vlax-ename->vla-object (car ent))) (setq objname (vla-get-objectname obj)) (setvar 'attdia 0) (cond ((= objname "AcDbPolyline")(ispline)) ((= objname "AcDbLine")(isline)) ((= objname "acDbArc")(isarc)) ((= objname "AcDbCircle" )(iscircle)) ) (SETVAR "ANGBASE" angbasee) (SETVAR "ANGDIR" angdirr) (SETVAR "AUNITS" aunitss) (princ) ) (defun c:aaa () (endptlabel1) ) (defun c:bbb () (endptlabel2) ) Quote Link to comment Share on other sites More sharing options...
acad1985 Posted August 7, 2018 Author Share Posted August 7, 2018 Hello Bigal, Thank you so much for your Code. I have tried the code above posted by you. well it's working but, it's update the length on both end. but i have to move the Attributes to both end from selected place. (Block Attributes already placed in my DWG), so first i have to select the Attributes, and the select the line. after that that selected attributes moved to both end of the line with same rotation angle as line. Thanks again. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 8, 2018 Share Posted August 8, 2018 I know the text needs some alignment work. But my big question is why are you inserting the blocks then attaching them to the line plines etc I would just add blocks to the objects directly and thats what I have tried to show in the code. This seems to be a 3 step process rather than 1. You can add the pick two blocks at the start and read their attribute value and create new adding to the code Quote Link to comment Share on other sites More sharing options...
acad1985 Posted August 8, 2018 Author Share Posted August 8, 2018 . But my big question is why are you inserting the blocks then attaching them to the line plines etc I would just add blocks to the objects directly and thats what I have tried to show in the code. This seems to be a 3 step process rather than 1. You can add the pick two blocks at the start and read their attribute value and create new adding to the code Actually, I'm working on one of the GIS Application,in that the block attributes will be placed automatically center top of the polyline. After that we need to move that block attributes to both end. This will take some time to align manually. That's why I'm asking here, if it's can be done through lisp. That's very helpful to me. Thanks Quote Link to comment Share on other sites More sharing options...
acad1985 Posted August 10, 2018 Author Share Posted August 10, 2018 Hello Bigal, Please share if any suggestions/updates. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 10, 2018 Share Posted August 10, 2018 Is this part working on one of the GIS Application in Autocad or Arcgis etc. Quote Link to comment Share on other sites More sharing options...
acad1985 Posted August 10, 2018 Author Share Posted August 10, 2018 Yes, it is working with AutoCAD Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 11, 2018 Share Posted August 11, 2018 Not sure why you insert them at centre then want to move them rather than center or end in 1st place. If you make a mistake then yes an extra option, likewise move ends to middle. Quote Link to comment Share on other sites More sharing options...
acad1985 Posted August 11, 2018 Author Share Posted August 11, 2018 Not sure why you insert them at centre then want to move them rather than center or end in 1st place It's automatically placed on center of the line. we didn't that, in that GIS that blocks always placed on middle of the line.(as per that Program of GIS) After that we have to align to both end. 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.