Select last 'x' line lines created

Select last 'x' line lines created

bobbyrubyii
Contributor Contributor
1,828 Views
12 Replies
Message 1 of 13

Select last 'x' line lines created

bobbyrubyii
Contributor
Contributor

I need to select the last "x" lines created. 

 

Background....

  I have a command that draws 'x' # of lines on the same color and layer to a dynamic # of insertion points .  The command then selects all lines of that color in the drawing and puts their length at the midpoint in an MTEXT, which works fantastic for new drawings.  Just not ones that are in process.

 

 It would be better if I could just access the last lines created so it does not duplicate footage's elsewhere.

 

Thank You!

0 Likes
1,829 Views
12 Replies
Replies (12)
Message 2 of 13

Moshe-A
Mentor
Mentor

@bobbyrubyii hi,

 

Selected objects can quickly be selected again in the following modify command with 'previous' option.

 

 

moshe

 

0 Likes
Message 3 of 13

pendean
Community Legend
Community Legend
AutoCAd's built-in features will only select your last drawn (single) item with LAST option, or your previous selection(s) with PREVIOUS.

There is no built in ability to ask AutoCAD to guess at what constitutes "last few Xlines" otherwise.

What better narrows down what you want to select exactly?


0 Likes
Message 4 of 13

bobbyrubyii
Contributor
Contributor

The objects are never selected to begin with, just created.  I need to somehow access the lines just created. 

0 Likes
Message 5 of 13

bobbyrubyii
Contributor
Contributor

It really doesn't have any native way to access the objects within with some sort of id#?  Well... is there a way I can record what is being created at the time of creation into a variable I can then access?

0 Likes
Message 6 of 13

pendean
Community Legend
Community Legend
Nope, nothing built-in to do that: try asking in the LISP or other customzation forums to see if a customization may be able to assist with your task https://forums.autodesk.com/t5/autocad-customization/ct-p/AutoCADTopic1


0 Likes
Message 7 of 13

Kent1Cooper
Consultant
Consultant

@bobbyrubyii wrote:

I need to select the last "x" lines created. 

....


 

I use my LastNo.lsp routine, with its (ln) function, available >here<.  See the Usage instruction in the third line.

Kent Cooper, AIA
0 Likes
Message 8 of 13

Kent1Cooper
Consultant
Consultant

@bobbyrubyii wrote:

I need to select the last "x" lines created. 

....

  I have a command that draws 'x' # of lines on the same color and layer to a dynamic # of insertion points .  The command then selects all lines of that color in the drawing and puts their length at the midpoint in an MTEXT, which works fantastic for new drawings.  Just not ones that are in process.

....


 

Another way you could do this, which doesn't  require you to know your number 'x' to find them [as the (ln) function in my previous reply requires], is to put a line like this in your command definition before  the drawing of any of those Lines:

 

(setq ss (ssadd))

 

for an initially-empty selection set.  Then build into the command, after  the drawing of each Line, the adding of it to that selection set:

 

(ssadd (entlast) ss)

 

After it has drawn all of them, no matter how many there were, you can call for the 'ss' selection set to use in whatever way you need.

Kent Cooper, AIA
0 Likes
Message 9 of 13

Kent1Cooper
Consultant
Consultant

[Unfortunate double posting -- if you get a good solution in either this thread or the other one, at least refer to it in the one that it's not in, so people who find the "wrong" thread in a Search will be able to find the solution.]

Kent Cooper, AIA
0 Likes
Message 10 of 13

dbhunia
Advisor
Advisor

Hi,

 

As your requirements...

 


@bobbyrubyii wrote:

I need to select the last "x" lines created. 

 

Background....

  I have a command that draws 'x' # of lines on the same color and layer to a dynamic # of insertion points .  The command then selects all lines of that color in the drawing and puts their length at the midpoint in an MTEXT, which works fantastic for new drawings.  Just not ones that are in process.

 

 It would be better if I could just access the last lines created so it does not duplicate footage's elsewhere.

 

Thank You!


 

You can try this...(For those drawings are in under process not for new drawings)

 

(defun C:CXLINE (/ lastent ss)
(setq lastent (entlast))
(setq ss (ssadd))
(command "_.XLINE"); Create XLINE.
  (while (> (getvar "cmdactive") 0)
    (command pause)
  )
  (while (setq lastent (entnext lastent))
    (ssadd lastent ss); Creating Selection Set of Created XLINE.
  )
(command "chprop" ss "" "C" 4 ""); Changing the color of last Selection Set(An Example)
)

Now if you "Select" command with "Previous" option, then it will select the last set of "XLINE" created by "CXLINE" lastly.....


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 11 of 13

bobbyrubyii
Contributor
Contributor

Not looking to use xline commnad.  would this work with line command?

0 Likes
Message 12 of 13

dbhunia
Advisor
Advisor

Yes it will work.....for continuous line......

 

change this .......

(command "_.XLINE")

To this .......

(command "_.LINE")

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 13 of 13

john.uhden
Mentor
Mentor

I was thinking of something more tedious, but guaranteed to find the last xline created, or for that matter anything, but, hmmm, it would probably be way too slow especially if your drawing contained lots of heavy or 3D polylines or blocks with attributes.

The conundrum results from the probability that the handle of the most recently created xline might not be "newer" than a previously created one (unless one of the wizards here can promise me differently).  I have just never tested the theory.

John F. Uhden

0 Likes