Hello.
I have a list function that asks for the user to pick points when it is run. It looks something like this...
(foo arg1 arg2)
When invoked it asks the user to pick points and press enter when done It.
Instead of getting the points from the user i want to pass it a list of pre-defined points. The code cannot be changed so I must use it as is.
Is this possible, if so how can it be done? I will be very grateful for any suggestions.
Thank you in advance.
Solved! Go to Solution.
Solved by doni49. Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Thanks for your question.
the actual function accepts some optional keywords and then asks the user to pick points as input for a polyline. When the is finished inputting points it creates a polyline and adds some proprietary data to it.
It is a third party function that I can't change only use.
I'm still learning AutoLISP, but i'll give it a try )
My idea:
to make a new function that you will run while running the initial "foo-function"...
the new function would take every member of the pre-defind list, and send it to foo-function...
maybe smth. like this ?
(defun foo2 (<pre-defined list> / vvv lis) (setq lis <pre-defined list>) (foreach vvv lis (princ vvv) ) )
I wonder if it will work fine like this:
(foo (foo2 (<pre-defined list>)))
?
Thank you for your suggestion.
I tried it exaclty as you describe but it will not take the point list and just keeps asking the user to specify points.
The first argument is a point coordinates and what about the second argument ? what does it stand for ?
It would me better if you attached the routine that you have at the moment, and an exemple of a pre-defined list of points.
In that case, me, or more probably somebody else from this forum could make an exact solution of your issue )
Actually the first argument is not a point coordinate. The arguments are for setting some properties, then the function starts asking for the user to define points. It continues to ask for points until the user cancels.
Unfortunately I can't give you the functions code because I don't have it. This function is part of a propretary ARX plug-in that has a lisp interface for some commands. You need a hardware lock to use the plugin.
A list of points would be like this. Perhaps this is the wrong way to pass them to the function?
'('(344.8238 628.2810)
'(344.8238 699.7638)
'(233.7504 699.7638)
'(233.7504 440.6118)
'(198.3629 440.6118)
'(198.3629 432.1601))
They are 2D points so the Z value is not needed.
Thanks for thinking about this for me. I think your suggestion is the way this should be done but this function does not respond to it.
@Kycau wrote:
In such case give me an example of a pre-defined list of points, so I can figure out how to acces them.
I suspect that's not going to be viable. You can do something like this to feed such input into a (command) function:
(command "_.pline"); leaves you in a running Pline command
(foreach pt ptlist (command pt)); feed points to Pline
(command ""); complete Pline
[The last line could be omitted if the point list isn't only points, but ends with an Enter ("") or perhaps "_close".]
But I don't think a (defun)'d function [whether or not enclosed within an ARX or FAS or whatever] can do that, i.e. can "leave you in" the function to supply input to it from outside. I think it's going to want to do what it does, including any User input it asks for internally, before going on to whatever may follow [such as a (foreach) function as supplied to the command above].
I may be wrong about that, but if that's true, there may not be a way to do it other than to go to the supplier of the function, and ask whether they would either 1) write you a version that takes a pre-defined list as an additional argument, or 2) send you the un-compiled code so you can modify it to work that way yourself [or with help from here or elsewhere]. Given that it involves proprietary information and is hardware-locked, I expect the former is much more likely than the latter.
Thank you Kent,
I think you are probably right about this. I get the feeling it is just not written in a way that it will do what I want it to do. i shame really but can't be helped.
I will do as you suggest and contact the vendor to see what they say.
My thanks to everyone for your assistance. Very much appreciated.
Kent1Cooper , I read this lesson:
http://ronleigh.com/autolisp/ales11.htm
Sample program 1, ol
This program is not run at the command prompt. Rather, it is run in the middle of any drawing or editing command when you are prompted for a point. To run the command you must call it as a function by including the parentheses. In other words, when prompted for a point you would enter (ol). Note that the program is defined as a function rather than a command (there is no "c:" in front of the function name).
I will try later this evening to get it to work the next way:
1. kennethmjones runs his function (foo (arg1) (arg2))
2. when promted for points, he types (plist) ... yes, with parantheses.
3. while this new function asks for input from kennethmjones , he inserts by pressing ctrl+v this string:
'('(344.8238 628.2810)
'(344.8238 699.7638)
'(233.7504 699.7638)
'(233.7504 440.6118)
'(198.3629 440.6118)
'(198.3629 432.1601))
4. while (plist) is executed, the input string is reformed, and at the output is given a proper list of points
5. (foo) function receives the point-list from (plist) and does whatever it hasw to do with that list.
kennethmjones , does it sound like what you need ?)
Thank You Kycau,
That sounds good to me but I think Kent Cooper is probably right about this function not responding. It probably is not designed that way. I guess I should give up on this one.
Thanks anyway.
@Anonymous wrote:A script... I see. How would that work then?
A script file basically sends keystrokes as though you sat there and typed them in yourself. So figure out exactly what key strokes you'd have to enter to be able to get the results you wanted manually. Having done that, you can make your script file. If the points never change then you can just use the script file you just created. If the points DO change, then you can have a lisp routine generate the script file "on the fly".
For the latter, you'll need to have a look at the "OPEN", "WRITE-LINE" & "CLOSE" functions.
It's been a while since I used a script file so I don't remember the exact syntax to actually run it, but just as an example what one looks like, here's one to start the PLINE command and then draw three points.
Note: A script file should have an extension of scr. The website won't let me post a file with that extension. So rename it when you download it.
Don Ireland
Engineering Design Technician
Just to clarify that a little....
Using my example, if I wanted the user to enter 3 points but for whatever reason, I had to pass the points to the pline command using a script file, following is a lisp routine that I'd create which would ask the user for the points, create the script file and then run the script file (although I still don't remember the exact syntax for running the script file.
EDIT: I just realized that before you can write the points to the file, you'll need to convert them to text strings.
(defun c:pts2script()
(setq pt1(getpoint "Select start point: "))
(setq pt2(getpoint pt1 "Select next point: "))
(setq pt3(getpoint "pt2 "Select last point: "))
(setq fn(open "MyScript.scr" "w"))
(write-line "PLINE" fn)
(write-line pt1 "w")
(write-line pt2 "w")
(write-line pt3 "w")
(close fn)
;;; <--Insert the code to run the script here once you find the syntax
)
Note: I haven't tested the code, but it should work or at least get you really close.
Don Ireland
Engineering Design Technician
Thank you doni49,
I tried the script method and it works with the defun function pefectly. Thinking of a script for this cas was a stroke of genius. I have used them before but I must admit I am more of an ARX guy and don't have much experience with lisp but it comes up in my work from time to time.
Thanks again to all of you who have responded. These a have all been great suggestions.
Kudos to all