ACAD command line: Draw line and then select line by id/name or db-nr

In Autocad i want to select individual lines preferably with Lisp.
I'll generate lines with lisp and then later on want to delete/manipulate
these lines one by one.

What is the best way to achieve this? My guess is that i have to give the
lines/objects unique identifiers somehow, so they are adressable for
selection later on?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saqib Husain, SyedEngineerCommented:
You can use the entity handle for this purpose. You can record the handles as and when the entity is created and later use this handle to delete them.

The function to do this is the "handent"

kiggsondromeAuthor Commented:

Handent works great, where i still see a problem is that
the records for the handles would have to be written
to an excel sheet because i'm using excel to generate
the lisp that does the drawing and then with a new lisp
later on the modifications.

This could work through vba, i'm just not sure if it will be
reasonably fast for thousands of lines.

If i could define or change the handle id it would be faster
i think. Or is there a better way adressing the lines/objects
with xdata?
Saqib Husain, SyedEngineerCommented:
Can you write the generated handles to a text file and, once completed, import the text file to excel?
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

kiggsondromeAuthor Commented:

That could be fast enough i think. The problem here is that i use one row
per acad line in excel, so the handles would have to get placed on the
row that created it in the first place. Unfortunately i don't see a reliable
way to get that right without complications.

Saqib Husain, SyedEngineerCommented:
If that can be fast enough then you can considering writing your preferred key together with the generated handle and then import the two columns into excel. Thereafter you can use vlookup to correlate the two.

Xdata is also a good option. I have tried it at some point in time but had been facing problems and then abandoned the idea. You might like to give it a go. Do you need help with it or can you handle it on your own?
kiggsondromeAuthor Commented:

If you remember how to attach a key or xdata to an acad
line it would help me a lot. It seems i can't find that info right now.

I'll give the vlookup in excel a try as soon as i really need it.  
Saqib Husain, SyedEngineerCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Would storing them as a GROUP in AutoCAD work for you? Group info is stored in AutoCAD and then it can be accessed later.
What do you mean by later access them and delete/manipulate them?

Are you going to delete/manipulate them during the same program execution? Or will this be done later during another program execution, perhaps even another day in another autocad session?

There's several ways to do any of this. Storing the handles is one way if you need access later. If the same program that creates them will later delete/manipulate them, you could just keep adding them to a selection set as they are created for later deletion/manipulation.

You could put them on seperate layers, you could attached Xdata to them to give them unique identifiers and/or other data that lets your program later know what they are and their purpose.

What determines what/when they get deleted/manipulated? Perhaps you just erase them all and redraw in their manipulated state (could be slow if there's thousands of lines) but could also be insignificant...especially if you are using something like Entmake as opposed to calling the line command.

You could also not draw lines but instead make them as blocks...but as Borgunit said, Groups mighht work better as you can easily select by group and manipulating the lines within the group is a lot easer than from within a block definition.

What version of AutoCAD? Newer versions have paremetric and geometric constraints that might allow you to manipulate them by manipulating the constraints as opposed to the lines themselves.

If you can elaborate more on exectly the nature of your program, we might be better able to help.
kiggsondromeAuthor Commented:

Thanks for all the comments, i'm still thinking about all the
necessities to get this right. I'll possibly have to test/implement
several ways. If someone wants to give me or point me to
existing examples on how to interactively draw dwgs with excel
(including edits the next day) it definitely would help a lot.
I didn't really got to try much yet.

I'll give the points to ssaqibh or maybe i'll split them if i can get
sample files. We're using Acad2005.

Attaching xdata works well:
(setq lastent (entget (entlast)))
(regapp "NEWDATA")
(setq exdata '((-3 ("NEWDATA" (1000 . "This is a new thing!")))))
(setq newent (append lastent exdata))
(entmod newent)

Check for xdata:
(entget (car (entsel)) '("NEWDATA"))

Can you post a sample drawing and/or sample Excel file that you think you might end up with?  Depending on what you're trying to do, some apporaches may work better than others.

If the Excel file is the template to create the entire drawing, I'd consider not editing the drawing at all, just erasing and redrawing in it's modified state if selection of items is cumbersome or difficult.
kiggsondromeAuthor Commented:

I'll definitely get back here in the next weeks and maybe
also post samples, all my drawings will need manual and
automated edits.

I have lots of other questions too then, thanks again for
all your comments.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CAD/Architecture Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.