PDA

View Full Version : Save entity for later use



Coolmo
2005-01-26, 06:34 PM
Here's a quick one but I'm stumped over here. What's the quickest way to either grab an entity on screen or draw and entity within a private sub and then somehow save that entity to be later used by another private sub. I want to create a polyline with a command button but I then want to edit that polyline within VBA with other controls or buttons but I can't seem to figure out how to make the second button (control) access the polyline just drawn. Any quick answers to this? I suspect it would be a selection set but I've never used those and the HELP that I'm seeing only confuses me.:-?

jim.vipond
2005-01-27, 09:14 AM
Depends on how you want to do it.
If you want the user to pick the object for editing you could use .Utility.GetEntity
If you want to edit the polyline immediately then call a sub routine passing the entity details.
If you want to keep that entity for later use use a global variable.
The vba help files should give you an idea of each of these.
Sorry not sure of your expertise but don't forget you will have to watch for errors on each of the above.

Hope this helps

Coolmo
2005-01-27, 03:35 PM
I'll ask the user to pick a certain polyline on screen first and then I'll have him/her edit that polyline through a series of different controls. What will ultimately happen would be the original polyline data will be saved and when a change is made through the other controls the new data will be appended or added to the original polyline data, the original polyline will be erased, a new polyline with the new data will be drawn in the originals place, and then that will become the current polyline for editing. If anyone works in AutoLisp, it's kinda like setting an entity to a variable (X) and then any time during that AutoCAD session I can call up that entity by just refering to X. A situation like that in VBA would be ideal. Any thoughts?

Ed Jobe
2005-01-27, 04:10 PM
Lisp would store the ename in X. You can do the same in vba. Get the handle or ObjectId and use SaveSetting to store it in the registry. Then when you need it, use GetSetting to retrieve the id and then use the id to get the object.

Coolmo
2005-01-27, 06:07 PM
what kind of code would you use to get the object? Would you use the ..Utility.GetEntity method with some sort of pointer to the pline handle? Could you post some quick code that I could use?

Ed Jobe
2005-01-27, 06:33 PM
Dim oLWP As AcadLWPolyline
Set oLWP = ThisDrawing.HandleToObject(GetSetting())

Assuming GetSetting is supplied with the right arguments.

Coolmo
2005-01-27, 06:46 PM
Thanks! I've never used "HandleToObject" before. Works great now. Instead of saving the handle to the registry, I simply made an invisible label caption = the handle and then retrieved that for grabbing the entity. Thanks again!!

Ed Jobe
2005-01-27, 07:34 PM
Whoah. Hold the horses. Your original description made it sound like you needed it much later, like after the program finished running. It now sounds like you have a form running ("caption") and only need to store the data during the life of the form? If so, just create a global variable in the form's declaration section. If you need it to last after the form closes, create a global var in the module that loads the form and have the form set it before it closes.