Jump to content

Using external function within a routine


lpseifert

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

  • lpseifert

    10

  • Lee Mac

    7

  • jammie

    4

  • alanjt

    4

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 :P

 

also not sure if you aware of 'entlast' aka "L" just fyi

 

(command [color=Red]"tcircle"[/color] "l" "" "0.3" "r" "")

flower

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

(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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

 

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...