As always Lee - You code structure is impeccable. You have given me some ideas to think about. I also realize on further testing of my code that I need to prevent an automation error when the alignment point is Left, Aligned, or Fit. The reason I use a separate function for setting the alignment property is because I use it with single line Text objects as well.
Thank you for your compliments PKENEWELL -
My example was just a refinement of your code, as I noticed that some expressions could be written more clearly & concisely - I'm glad that you can take some ideas/techniques from the code.
I have always been confused on the practice of releasing objects, so I tend to set them to a variable - then release them when finished. By your practices, I assume that if you do not set ActiveX objects to variables, then there is no need to release them? I have always been confused by this, since it has been debated that you need to release the objects rather than just set the variables to nil.
Your assumption is not true that if objects are not assigned to variables that they do not need to be released - the object still resides in the allocated memory, only, there is no pointer to the memory address in which it resides. When assigning data to variables, the variables are simply pointers to the location of the data in the system memory - data which is not assigned to a variable still exists in the system memory, only we don't know where (those who know more on this subject, please feel free to correct me).
However, having also queried the practices of releasing objects myself in the past, I hold the understanding that the general consensus is that it is not necessary to release objects which fall within the AutoCAD Object Model (i.e. anything derived from
vlax-get-acad-object), as AutoCAD will release these objects automatically when a garbage collection is performed periodically during the drawing session (which you can also force manually using
gc). However, I believe it
is necessary to release objects which are outside of the AutoCAD Object Model, such as when interfacing with the Excel Application object, FSO or WSH.
Anyway - thanks much for your examples! Your code is brilliant! I have learned much about streamlining Autolisp code from you. I have been coding Autolisp for almost 20 years, and thought I was pretty decent at it until I encountered you and the other Swampers. I used to use loops like foreach, repeat, and while in much of my old code to handle lists. I have converted much code recently to using mapcar and lambda thanks you your tutoring on this forum. Also using things like (cond) for defaulting is new to me.
Thank you for your kind words PKENEWELL, I too have learnt a great deal from the knowledgeable community here at the Swamp. As I've discussed in another recent thread, many programs could be written using only
foreach /
repeat /
while loops, and using nested
if statements in place of a single
cond expression; there are often many ways to perform the same task in AutoLISP, but becoming familiar with all the tools in your AutoLISP toolbox ensures that a program can be built with more than just a sledgehammer
I would suggest something along the following lines:
< .. >
Perhaps adding an additional parameter to indicate the owner of the attribute would make the function more generic.
ie: either a block object or nil.
if nil use your current owner code, otherwise add the attribute to the block object nominated.
Just a thought.
Agreed, something like:
( own )
'paperspace
'modelspace
)
)
)
)