amb2301 Posted August 27, 2017 Posted August 27, 2017 Hi Lisp Legends, Actually i am new to autolisp, just now reviewed cadtutor.net, excellent works done by members here. Thanks in advance to those peoples:) I need a urgent help from you friends.... actually I need to align text(as shown in attachment) to three different positions of a block(red coloured). Is there any lisp to get the text aligned to those positions. further explained in attached image Please revert for clarification if any required. Awaiting for your response. Thanks amb sample.dwg Quote
BIGAL Posted August 28, 2017 Posted August 28, 2017 Try this ; pick 3 texts and align to a block (vl-load-com) (defun c:tritxt ( / oldang oldunit oldsnap obj ang ins Tp xscale bname ins) (setq oldang (getvar 'angdir)) (setq oldunit (getvar 'aunits)) (setq oldsnap (getvar 'osmode)) (setvar 'angdir 0) (setvar 'aunits 3) (setvar 'osmode 0) (setq obj (vlax-ename->vla-object (car (entsel "\nPick Block object")))) (setq Objname (vla-get-Objectname obj)) (if (/= Objname "AcDbBlockReference") ; check is it a block (alert "You have not Picked a block\n\nPress ok ") (progn (setq ang (vla-get-rotation obj)) (setq ins (vlax-safearray->list (vlax-variant-value(vla-get-insertionpoint obj)))) (setq xscale (vla-get-XScaleFactor obj)) (setq bname (vla-get-name obj)) (cond ((if (= bname "TERM_AER_E")(setq len 6))) ; as per sample ((if (= bname "xxxx")(setq len 10))) ; other blocks change len value ) (setq off 2.0) (setq Tp (vlax-ename->vla-object (car (entsel "\nPick text1")))) (setq pt1 (vlax-3d-point (polar ins (+ ang (/ pi 2.0)) off))) (vla-put-insertionpoint Tp pt1) (vla-put-rotation Tp ang ) (setq Tp (vlax-ename->vla-object (car (entsel "\nPick text2")))) (setq pt1 (vlax-3d-point (polar ins (- ang (/ pi 2.0)) off))) (vla-put-insertionpoint Tp pt1) (vla-put-rotation Tp ang ) (setq Tp (vlax-ename->vla-object (car (entsel "\nPick text3")))) (setq pt1 (vlax-3d-point (polar ins ang (* len 2.0)))) (vla-put-insertionpoint Tp pt1) (vla-put-rotation Tp ang ) (setvar 'angdir oldang) (setvar 'aunits oldunit) (setvar 'osmode oldsnap) ) ) ) Quote
amb2301 Posted August 28, 2017 Author Posted August 28, 2017 hi Bigal, Thank you so much for your help:), but its showing some error, could you please check the below mentioned error & revert Command: TRITXT Pick Block object; error: no function definition: VLAX-ENAME->VLA-OBJECT Thanks, Amb Quote
amb2301 Posted August 29, 2017 Author Posted August 29, 2017 Hi Devitg, Thanks for your reply, but the code (vl-load-com)is already available in lisp provided by Bigal. Thanks, amb Quote
BIGAL Posted August 29, 2017 Posted August 29, 2017 I copy and pasted it to my autocad and tested on your sample supplied dwg and worked fine so no idea, did you try it on another dwg or how did you copy the code. Quote
pBe Posted August 29, 2017 Posted August 29, 2017 (edited) (defun c:demo (/ block Annotaions i data ang scale ipt iptoff objname npt layer) (if (and (princ "\nSelect reference block object") (setq block (ssget "_+.:S:E" '((0 . "INSERT")(2 . "TERM_AER_E")))) (not (redraw (setq block (ssname block 0)) 3)) (princ "\nSelect Annotations to align") (setq Annotaions (ssget "_:L" '((-4 . "<OR") (-4 . "<AND") (0 . "INSERT")(2 . "SITE_ANNO") (-4 . "AND>") (-4 . "<AND")(0 . "MTEXT")(8 . "SITE_ANNO,COUNT_ANNO") (-4 . "AND>") (-4 . "OR>")) )) (= (setq i (sslength Annotaions)) 3) ) (progn (redraw block 4) (setq data (mapcar '(lambda (d) (cdr (assoc d (entget block)))) '(10 41 50 41))) (setq ang (caddr data) ipt (car data) scale (cadr data)) (setq iptoff (polar ipt ang (* scale 0.25)) ang (if (minusp (last data)) (+ ang pi) ang)) (repeat i (setq item (vlax-ename->vla-object (ssname Annotaions (setq i (1- i)))) objname (vla-get-Objectname item) layer (vla-get-layer item)) (if (setq npt (cond ( (eq objname "AcDbBlockReference") (polar ipt ang (distance ipt (vlax-get item 'Insertionpoint))) ) ( (and (eq objname "AcDbMText") (eq (strcase layer) "COUNT_ANNO")) (polar iptoff (+ ang (* pi 1.5)) (* scale 1.5)) ) ( (and (eq objname "AcDbMText") (eq (strcase layer) "SITE_ANNO")) (polar iptoff (+ ang (/ pi 2.0)) (* scale 1.5)) ) ) ) (progn (vlax-put item 'Insertionpoint npt) (vlax-put item 'Rotation (+ ang (if (and (>= (* 1.5 pi) ang) (> ang (* 0.5 pi))) pi 0)) )) ) ) ) ) ) (vl-load-com) Select reference block object Select objects: Select Annotations to align Select objects: 3 found HTH I copy and pasted it to my AutoCAD and tested on your sample supplied dwg and worked fine so no idea, did you try it on another dwg or how did you copy the code. Works here on my end. The picture on the OP shows what appears to be 3 TEXT objects while the sample drawing shows mtext and a block. Similar to Bigals, the code I posted considers mtext and a block for it to work. Wondering if the annotations vary from one drawing to another. Edited August 30, 2017 by pBe Quote
amb2301 Posted August 29, 2017 Author Posted August 29, 2017 Hi pBe, Thanks for looking on this work, i tried with the lisp given by you, it shows the error as "; error: no function definition: VLAX-ENAME->VLA-OBJECT" after selecting 3 text & hitting enter key it shows that error.please suggest me what do on this issue. Awaiting for your reply. Quote
amb2301 Posted August 29, 2017 Author Posted August 29, 2017 Hi Bigal, Thanks again for looking on this work. actually i just copied the program given by you & saved it in my desktop as test.lsp file, then apploaded & when entering the TRITEXT command, after that selecting the "TERM_AER_E" block, it shows the following error. Command: TRITXT Pick Block object; error: no function definition: VLAX-ENAME->VLA-OBJECT thanks, amb Quote
pBe Posted August 29, 2017 Posted August 29, 2017 Strange, paste this on the command prompt (findfile "vlcom.dll") and tell us what you see Hi pBe, ..... after selecting 3 text & hitting enter key it shows that error.please suggest me what do on this issue. The code I posted requires the user to select the reference block and 2 mtext and a block. Quote
pBe Posted August 29, 2017 Posted August 29, 2017 It's there alright, this is me grasping for straws, put (vl-load-com) on your acaddoc.lsp or any startup routines. [ it is a known bug ]. Worst you may need to repair your Autocad Installation. EDIT: what is all that image you posted on the -previous post? Quote
amb2301 Posted August 29, 2017 Author Posted August 29, 2017 Hi pBe, Thank you so much for your suggestion, as you suggested i repaired Autocad & your lisp working perfectly now:) But one small problem, please check the attached image (circled in blue) marked location. text getting overlapped. please check it if possible Thanks again for your help:D Quote
pBe Posted August 29, 2017 Posted August 29, 2017 The conditions for the code is this: 1. First selection is the "TERM_AER_E" block 2. Objects selected on the second prompt should comprise of the "SITE_ANNO" block, MTEXT under "SITE_ANNO" layer and another MTEXT under "COUNT_ANNO" You have an overlap because both MTEXT is on "SITE_ANNO" layer. We can modify the code to "check" if the selection meets the criteria if we have to. Quote
amb2301 Posted August 29, 2017 Author Posted August 29, 2017 The conditions for the code is this:1. First selection is the "TERM_AER_E" block 2. Objects selected on the second prompt should comprise of the "SITE_ANNO" block, MTEXT under "SITE_ANNO" layer and another MTEXT under "COUNT_ANNO" You have an overlap because both MTEXT is on "SITE_ANNO" layer. We can modify the code to "check" if the selection meets the criteria if we have to. Thank you so much for your help pBe..... I will check with some other drawings & get back to u. Quote
pBe Posted August 29, 2017 Posted August 29, 2017 Anytime amb2301, I would suggest you try Bigals' code at post#3, it does not have the same restrictions as the demo code I posted which makes it a better choice. Quote
amb2301 Posted August 30, 2017 Author Posted August 30, 2017 Anytime amb2301, I would suggest you try Bigals' code at post#3, it does not have the same restrictions as the demo code I posted which makes it a better choice. Hi Bigal & pBe, both of your lisp is working properly, problem is with my Autocad & it has been fixed up now, one more help required, if u refer the attached image, the yellow circled region shows the manually aligned for showing it in readable angle, but i tried the same lisp, its getting rotated as shown in attached image(grey circled), Please look on its & kindly try to solve it Quote
BIGAL Posted August 30, 2017 Posted August 30, 2017 Both codes will need a check angle of block and rotate text 180 and probaly a redo on the text poisitions as I fudged a couple of values to make it very simplistic in its approach. To read right handed angle is 1.5*pi 0.5*pi 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.