Author Topic: ssget prompt with variables  (Read 1468 times)

0 Members and 1 Guest are viewing this topic.

NameWaster

  • Mosquito
  • Posts: 10
ssget prompt with variables
« on: March 11, 2022, 05:44:24 AM »
Hello,

I would like to create a selection set of a specific Hatch object at a specific location in my drawing.
I have the coordinates saved with setq in the variables "x" and "y".
My value of x is "87911.9" and my value of y is "70247.6".

Now I'm trying to use x and y with ssget somehow but I am still a beginner with AutoLISP.
This is my code:

(setq hatchss (ssget "_+.:S" '((0 . "HATCH")(8 . "my layer"))))

At first I tried to incorporate the x and y into this line but I couldn't and then I tried without it (code as seen above) and I am prompted to select objects.
If I manually enter "87911.9,70247.6" in the prompt then it works and I get the selection set that I want but I need to be able to automate it by using "x" and "y" as their values will change.

So my question is, can I implement what I enter into the prompt into my code? Without the prompt coming up? If so, how?
OR can I edit this
(setq hatchss (ssget "_+.:S" '((0 . "HATCH")(8 . "my layer"))))
so that it incorporates the coordinates already and doesn't need a prompt.

Any help is greatly appreciates, thank you in advance!

mhupp

  • Bull Frog
  • Posts: 250
Re: ssget prompt with variables
« Reply #1 on: March 11, 2022, 07:11:52 AM »
Lee Mac's Website gives a good reference for ssget.
http://www.lee-mac.com/ssget.html
That said I don't think you can use ssget with just one point. You would at least have to use two points for the "_W" window option.

The only function I know that uses a single point to select something is
Code - Auto/Visual Lisp: [Select]
  1. (setq hatch (car (nentselp pt))

NameWaster

  • Mosquito
  • Posts: 10
Re: ssget prompt with variables
« Reply #2 on: March 11, 2022, 08:35:58 AM »
Thankyou! The nentselp function technically works for me too but is there a way I can filter it to select only HATCH objects?
Because I will have different kinds of objects at the same point.
Best regards!

mhupp

  • Bull Frog
  • Posts: 250
Re: ssget prompt with variables
« Reply #3 on: March 11, 2022, 08:55:07 AM »
Try, Don't know if it will work tho.
Code - Auto/Visual Lisp: [Select]
  1. (setq hatchss (ssget "_+.:E:S" PT '((0 . "HATCH")(8 . "my layer"))))

NameWaster

  • Mosquito
  • Posts: 10
Re: ssget prompt with variables
« Reply #4 on: March 11, 2022, 09:18:43 AM »
It says "too many arguments" when I tried that.
But it's okay, I was able incorporate freezing the layers with the objects I don't need before using nentselp and afterwards thawing them again and this way I was able to reach my goal.
Thank you for introducing nentselp to me :-D

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: ssget prompt with variables
« Reply #5 on: March 12, 2022, 09:56:42 PM »
You could expand the ssget search method either Fence or CP crossing polygon

(setq hatchss (ssget "F" (list pt1 pt2)  '((0 . "HATCH")(8 . "my layer"))))

The reason for a Fence approach is that if you use say ansi31 a line pattern if a point does not touch a line in the hatch it will miss. Often I use a little square with CP to find stuff like this the square just need to be big enough to touch the hatch.
 
A man who never made a mistake never made anything

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ssget prompt with variables
« Reply #6 on: March 29, 2022, 04:30:52 PM »
Lee Mac's Website gives a good reference for ssget.
http://www.lee-mac.com/ssget.html

Thank you for the recommendation  :-)

That said I don't think you can use ssget with just one point. You would at least have to use two points for the "_W" window option.

You can indeed supply a single point to the ssget function to select geometry which passes through that point, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (setq pt (list x y))
  2. (ssget pt '((0 . "HATCH") (8 . "My Layer")))

However, using a single point selection in this way can prove to be unreliable in general, as the target geometry must pass exactly through the point, which can consequently lead to a false empty selection as a result of rounding issues or dependency on the current zoom level (since the target objects must be visible within the drawing area in order to be selected using the graphical selection methods).

Instead, I would suggest using a crossing window with a small tolerance around the point, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (setq pt (list x y))
  2. (ssget "_C"
  3.     (mapcar '+ pt '(1e-3 1e-3))
  4.     (mapcar '- pt '(1e-3 1e-3))
  5.    '((0 . "HATCH") (8 . "My Layer"))
  6. )

Changing the tolerance depending on the use case.