Basic autolisp question

Basic autolisp question

Anonymous
Not applicable
1,245 Views
9 Replies
Message 1 of 10

Basic autolisp question

Anonymous
Not applicable

I have a list of pairs in autolisp ((x1 x2)(x3 x4)(x6 y5)...) This list contains variable number of argument and I wonder on how can feed all the arguments to the command funct. 

(command "xxxx"  pair1 pair2 ... pairfinal)

0 Likes
Accepted solutions (2)
1,246 Views
9 Replies
Replies (9)
Message 2 of 10

cadffm
Consultant
Consultant
The answer is depent of the whole command expression, but for normal:
(Command "point")
(Foreach pair ofmylist (command pair))
(Command "")

Which command you try to use in (command expression?

Sebastian

0 Likes
Message 3 of 10

Anonymous
Not applicable

I attached the detail in a notepad

0 Likes
Message 4 of 10

cadffm
Consultant
Consultant
Accepted solution
Oh select is very special (simular to the alltime autocad object selection)

Three answeres

(foreach coord ofmylist (command coord))

If your setting is the standard setup (pickauto) it should working.

BUT the autocad object selection is depend of your current view(target and zoomlevel of view),
So it isn't really sure what "select" will find.
You should use ZOOM to make sure the objects are near enough (and if SELECTIONOFFSCREEN is off, you can use zoom too for make sure the area is visible. Or set SELECTIONOFFSCREEN on)

Without command, selectionset can create by using ssget and ssadd.



Sebastian

Message 5 of 10

john.uhden
Mentor
Mentor
Accepted solution

It depends on what types the pairs are made of so that suitable responses are fed to the command invoked.

 

But, for example, if the pairs are all reals, as in ((X1 Y1)(X2 Y2)... (Xn Yn)), then.

(command "_.line")
(mapcar 'command pairs)
(command "")
OR,
(command "_.line")
(mapcar 'command (append pairs '("")))

Of course one must beware of running object snaps that might make any supplied point end up at the end or middle of other thingies.  Adding "_non" before each point is one way but slightly difficult to program, so it might be best to turn off osnaps before the command and turn them back on after.

Here's one way...

Before:
(setvar "osmode" (logior (getvar "osmode") 16384))
After:
(setvar "osmode" (boole 2 (getvar "osmode") 16384))

I hope I don't have them backwards.

 

John F. Uhden

Message 6 of 10

Anonymous
Not applicable

I normally use 

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
.....
...
(setvar 'osmode oldsnap)
0 Likes
Message 7 of 10

cadffm
Consultant
Consultant
That deselect all osnap settings, if you don't use a error function for reset osnaps, the user will lost his osmode setting.

Osnaps turning off like john shows it is much better in this case.

(Or the real well method for that, command input without osnaps, set osnapcoord to 1)

Sebastian

0 Likes
Message 8 of 10

john.uhden
Mentor
Mentor

Sheesh.  I never even knew that [osnapcoord] existed.  But there it is, even in 2002.  But the help speaks only of keyboard entry.  What about points computed in AutoLisp or read from a file?  I don't think I ever type in coordinates.  What about if you point to the direction and enter a distance?

John F. Uhden

0 Likes
Message 9 of 10

cadffm
Consultant
Consultant
Look at options/user preferences upper right corner.

Every time when you give input for coordinates..
No matter how.
Mouse direction and length
,30
Mouseclick
Every click or input for a pickpoint will be as result a coordinate information for acad.
In some situation acad is asking for a object, you can click them or select it by 200,400 - in first line both are coordinate information for acad,
At the same time acad calculate the coordinate point by the current osnap one or more are active.

Coordinates 1 is default.
Whenever you using the keyboard for input, acad ignore the running osnap(osmode).
Thats good, because you never want a osnap point when you working with the keyboard, or you will use the temporary snap explicit.
Ps: osnapcoord set to 0 can be a really bad thing(users who playing in options and change this setting to 0)
Unexpected results welcome.

But osnapcoord(1) is only for ignoring running osnaps by keyboard input from users,
it is not for automation inputs like macro script (commands or sendcommand from other APIs)
When you needed osnaps without input by user? Not so often..
Osnapcoords 2 includes coordinate inputs from automations (control commands with lisp,scr,macros and so on)

Value 2 should be the default, but it isn't from adesk.
1 or 2, for normal user work it is the same.
But you knowing about millions of lisp snippeds and dirty macro/scripts/lisps and blind using users.
Value 2 should be default and protects users for some gray hairs, but it isn't by adesk.

Sebastian

0 Likes
Message 10 of 10

cadffm
Consultant
Consultant
Last answer yesterday it looks like i was very tired.
Of course it should read
Default 2 (only keyboard)
My opinion is it should be 1 (keyboard and automation)
i am sorry for confusion.

Sebastian

0 Likes