Hello,
I am trying to create a one-click entity selection and block insertion solution with AutoLISP.
The tool is supposed to detect the layer of a line and change the active layer to a different (already existing) layer based on this selection. Then it should insert a block on that newly actived layer on a sepcific point on the line.
I want to combine these two steps into one, i.e. I want to be able to 'hover' over the line with an active OSNAP in such a way that the line gets detected (highlighted) and the selected OSNAP detects the desired block insertion point. Once the cursor is in a spot where these two selection methods are activated, the click should invoke the layer change and the block insertion at the OSNAP point.
I have the following problems:
1) I can detect the current line layer with ENTSEL and switch layers, but ENTSEL ignores OSNAP settings and records the actual click location. Hence I have to explicitely activate an OSNAP (e.g. endpoint) before the selection, ENTSEL will then return the correct point. However, I would like to avoid having to manually activate an OSNAP in the process.
2) Let's say I have multiple lines sharing one endpoint (like a 'Mercedes' star) - based on my use case, this is the most likely scenario. When I click them individually (without the OSNAP), ENtSEL will return the correct entity list entry for each line. However, I noticed that when I combine the selection with an OSNAP for that common endpoint, I get the correct point locations, but every line selection also returns the same entity list entry, regardless of which line I select.
In other words, if three lines (entities "A", "B", and "C") share the coordinate 0,0,0 with one endpoint:
- ENTSEL without OSNAP returns "A", "B", and "C", but (obviously) different coordinates (cursor locations).
- ENTSEL with OSNAP returns the coordinate 0,0,0 for all three lines, but also the same entity name (e.g. "A", "A", and "A")
I haven't really investigated how it is determined which entity name is returned in the second case. When I use the BREAK command (similar functionality) that way to break one of two intersecting lines (with an intersection OSNAP activated), AutoCAD always ends up breaking the one in front (in draw order), regardless of which line I hover over. I'm not sure if it would actually help me to know anyway, because it still doesn't tell me which entity was originally selected...
I wouldn't mind having to use a little workaround in my code (let's say to change the draw order of the selected item or to add and later delete a 'helper' entity, or something like that), but at this point I can't think of any.
Has anybody here done something like that and can point me into the right direction?
Thank you very much in advance!