lpseifert Posted February 14, 2009 Posted February 14, 2009 I'm trying to use the Express Tools' Tcircle command within an app I'm trying to write. What I want to do is put a rectangle around the last entity created (text). But it hangs at "Select TEXT, MTEXT or ATTDEF objects..." and I can't seem to pass the required info programmatically. Anyone know how? This is what I've tried (command (c:tcircle) "l" "" "0.3" "r" "") Thanks- Larry Quote
flowerrobot Posted February 14, 2009 Posted February 14, 2009 i dont have have autocad @ home so i carnt test and see wat the command requires but You were almost correct. when you want a command to run, place the name in "" and the rest should follow also not sure if you aware of 'entlast' aka "L" just fyi (command [color=Red]"tcircle"[/color] "l" "" "0.3" "r" "") flower Quote
Lee Mac Posted February 14, 2009 Posted February 14, 2009 I must admit, I have always had trouble with using the Express tools within other LISPs, as they seem to take control and mess up my LISP after completion, so I'd be interested if Flower's solution works. Quote
flowerrobot Posted February 14, 2009 Posted February 14, 2009 Do you know where the express tools lsp are located and are they incripted. since i some how broke one of them, and that way you can borrow their code and place in in yours Quote
lpseifert Posted February 14, 2009 Author Posted February 14, 2009 (command [color=Red]"tcircle"[/color] "l" "" "0.3" "r" "") Thanks, I tried that but it gives me the error 'unknown command "tcircle"' Yes, I'm aware of entlast, but I can't get passed "Select TEXT... The Tcircle command works fine by itself, and it works inside the app I'm writing if I supply the necessary options, I was hoping to pass them programmatically without the need to enter them manually. Quote
Lee Mac Posted February 14, 2009 Posted February 14, 2009 As Flower says, - the reckon the best thing to do is hack into the express tool LISPs Quote
flowerrobot Posted February 14, 2009 Posted February 14, 2009 ***cough****location??*****cough*** Quote
lpseifert Posted February 14, 2009 Author Posted February 14, 2009 I can't seem to find tcircle.lsp or a .lsp that has tcircle. It must be a .fas file. Quote
JohnM Posted February 14, 2009 Posted February 14, 2009 You cant call external functions like tcircle and pass them values unless they have been set up to accept values. The tcircle file is located at “c:/program files\\express” the file name is acettxt.lsp Quote
lpseifert Posted February 15, 2009 Author Posted February 15, 2009 OK Thanks. I took a look and the code is beyond me. I guess I'll go to Plan B. Quote
JohnM Posted February 15, 2009 Posted February 15, 2009 Here a little help for your plan B: In your program make a call to this code and pass it 2 variables the first must be the entity name of the text the second is an offset distance of the rectangle from the text. In your code after you have it makes the text write (setq txent (entlast)) this will get the entity name of the last thing made in the drawing, which should be the text. Now make the call to the code I supplied:(mk_rect txent 0.0313) this calls the mk_rect routine and passes the 2 variables: txext which is the entity name and a real number that can be anything for the offset. [font=Times New Roman][font=Times New Roman](vl-load-com);_make sure vl commands are loded[/font] [font=Times New Roman];;;pass 2 variables to the mk_rect function aug1 = entity aug2 = offset distance[/font] [font=Times New Roman](defun mk_rect (aug1 aug2 / rect llc urc ang1 dist lent)[/font] [font=Times New Roman](vla-GetBoundingBox (vlax-ename->vla-object aug1) 'minpt 'maxpt);_check for heigth /width[/font] [font=Times New Roman](setq[/font] [font=Times New Roman]llc (vlax-safearray->list minpt)[/font] [font=Times New Roman]urc (vlax-safearray->list maxpt)[/font] [font=Times New Roman]);_setq[/font] [font=Times New Roman](setq rtlst(textbox (list(assoc 1 (entget aug1)))));_get true outline on text returns a lower left and upper right[/font] [font=Times New Roman](setq ang1 (angle (nth 0 rtlst) (nth 1 rtlst)));_ angle from lower left ro upper right[/font] [font=Times New Roman](setq dst (distance (nth 0 rtlst) (nth 1 rtlst)));_ distance from lower left ro upper right[/font] [font=Times New Roman] (command "rectangle" llc (polar llc ang1 dst));_make rectangle to exact sixe[/font] [font=Times New Roman](setq lent (entlast));_get rectanglwe entity name for deletion[/font] [font=Times New Roman](vla-offset (vlax-ename->vla-object (entlast)) aug2);_offset rectangle [/font] [font=Times New Roman](entdel lent);_delete first rectangle[/font] [font=Times New Roman](princ) [/font] [font=Times New Roman] );_defun [/font] [/font] Quote
David Bethel Posted February 15, 2009 Posted February 15, 2009 Once you have turned control over to an external program, you cannot interface with it via an Autolisp app. The external app must either complete it's task or terminate via a cancel. Unless it has changed over the years, (command (c:myfoo) ... should not work As to whether you have to use (c:myfoo) or (myfoo), it would either very difficult or impossible to test for, just trial and error. Command: (type acad_strlsort) EXRXSUBR Command: (type c:wipeout) SUBR Command: (type c:a2) SUBR -David Quote
jammie Posted February 15, 2009 Posted February 15, 2009 A slight work about could be to create a temporary script file that you can call and run during your own routine. The script can be evaluated but allows your routine to still run when your script is finished (setq fname (vl-filename-mktemp "test.scr") file (open fname "w")) (foreach n (list "tcircle" "l" "" "0.3" "r" "") (write-line n file) ) (close file) (command "script" fname) (vl-file-delete fname) Quote
Lee Mac Posted February 15, 2009 Posted February 15, 2009 Hmmm, never though about using a script within an AutoLISP routine - would this be feasible? Quote
jammie Posted February 15, 2009 Posted February 15, 2009 For less complex functions I believe it is feasible. The following example prompts the user to create a text string an calls on the tcircle command to enclose it (defun c:revtxt () (vl-load-com) (setq os (getvar "osmode")) (setq pt (getpoint "\nSpecify start point of text :") str (getstring t "\nType text :") ) (vl-cmdf "text" pt 1 "" str) (setvar "osmode" 0) (setq fname (vl-filename-mktemp "test.scr") file (open fname "w") ) (foreach n (list "tcircle" "l" "" (rtos (getreal "\nOffset factor : ") 2 13) "r" "" "" ) (write-line n file) ) (close file) (vl-cmdf "script" fname) (vl-file-delete fname) (setvar "osmode" os) ) Quote
JohnM Posted February 15, 2009 Posted February 15, 2009 everything is cool but the line: (vl-cmdf "text" pt 1 "" str) it should be: (vl-cmdf "text" pt "" str) and then it works Quote
lpseifert Posted February 15, 2009 Author Posted February 15, 2009 Here a little help for your plan B:In your program make a call to this code and pass it 2 variables the first must be the entity name of the text the second is an offset distance of the rectangle from the text. In your code after you have it makes the text write (setq txent (entlast)) this will get the entity name of the last thing made in the drawing, which should be the text. Now make the call to the code I supplied:(mk_rect txent 0.0313) this calls the mk_rect routine and passes the 2 variables: txext which is the entity name and a real number that can be anything for the offset. [font=Times New Roman][font=Times New Roman](vl-load-com);_make sure vl commands are loded[/font] [font=Times New Roman];;;pass 2 variables to the mk_rect function aug1 = entity aug2 = offset distance[/font] [font=Times New Roman](defun mk_rect (aug1 aug2 / rect llc urc ang1 dist lent)[/font] [font=Times New Roman](vla-GetBoundingBox (vlax-ename->vla-object aug1) 'minpt 'maxpt);_check for heigth /width[/font] [font=Times New Roman](setq[/font] [font=Times New Roman]llc (vlax-safearray->list minpt)[/font] [font=Times New Roman]urc (vlax-safearray->list maxpt)[/font] [font=Times New Roman]);_setq[/font] [font=Times New Roman](setq rtlst(textbox (list(assoc 1 (entget aug1)))));_get true outline on text returns a lower left and upper right[/font] [font=Times New Roman](setq ang1 (angle (nth 0 rtlst) (nth 1 rtlst)));_ angle from lower left ro upper right[/font] [font=Times New Roman](setq dst (distance (nth 0 rtlst) (nth 1 rtlst)));_ distance from lower left ro upper right[/font] [font=Times New Roman] (command "rectangle" llc (polar llc ang1 dst));_make rectangle to exact sixe[/font] [font=Times New Roman](setq lent (entlast));_get rectanglwe entity name for deletion[/font] [font=Times New Roman](vla-offset (vlax-ename->vla-object (entlast)) aug2);_offset rectangle [/font] [font=Times New Roman](entdel lent);_delete first rectangle[/font] [font=Times New Roman](princ) [/font] [font=Times New Roman] );_defun [/font] [/font] Thanks John, your code works great. Unfortunately the code I'm writing is for labeling storm sewer pipes, and they are rarely horizontal. Our standard is to align the text with the pipe and enclose it with a rectangle. The code you graciously provided creates a rectangle that is horizontal. I've tried mucking around using polar and setting the 4 corners, etc. but it doesn't want to cooperate. Quote
lpseifert Posted February 15, 2009 Author Posted February 15, 2009 A slight work about could be to create a temporary script file that you can call and run during your own routine. The script can be evaluated but allows your routine to still run when your script is finished (setq fname (vl-filename-mktemp "test.scr") file (open fname "w")) (foreach n (list "tcircle" "l" "" "0.3" "r" "") (write-line n file) ) (close file) (command "script" fname) (vl-file-delete fname) jammie, that's pretty clever how you made a script file on the fly, I would have never thought of that. Works well but I notice it seems to run the script at the end of the function. I saved the current layer so it could be restored, changed the clayer to what I want the text and rectangle to be on, but when I run the code the rectangle always ends on the original layer. I tried chprop > entlast... and reordering the lines of code but neither seems to help. Probably along the same lines, after completing the c: function and you hit enter to repeat the function, you get the the prompts for the Tcircle command. Little things I can live with... Thanks for your help Quote
jammie Posted February 16, 2009 Posted February 16, 2009 Glad to be of help. I encountered a similar stumbling block myslef where I wanted to manipulate an external routine without rewriting the code. I wrote a routine that effectively mimiced all the inputs, skipping the ones that I did not require and wrote the sequence to a script file. I then simply ran the script file I notice it seems to run the script at the end of the function. That is a good observation, I hadn't noticed that myself. I not sure exactly why AutoCAD does it... when I run the code the rectangle always ends on the original layer. Maybe this could work instead (setq fname (vl-filename-mktemp "test.scr") file (open fname "w")) (foreach n (list "tcircle" "l" "" "0.3" "r" "" "chprop" "l" "" "la" "<layname>" "") (write-line n file) ) (close file) (command "script" fname) (vl-file-delete fname) Regards, Jammie Quote
lpseifert Posted February 16, 2009 Author Posted February 16, 2009 Maybe this could work instead (foreach n (list "tcircle" "l" "" "0.3" "r" "" "chprop" "l" "" "la" "<layname>" "") That works great... more than one way to skin a cat Thanks Jammie 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.