I don't have this object enabler, so the piles do not show properly for me, but there are a few things that you may be able to do to improve your code, for example:
By wrapping all your prompts for user input in an And expression (as the test expression for an If statement) you require all input to be valid (non-Nil) in order to evaluate the rest of your code. As written, if the user hits escape for one of the prompts, the next prompt is still evaluated, let alone the code that is dependent on the prompt results.
While it is necessary to define the space Object parameter for the vla-AddMText Method, this only need be done once (prior to the While loop), instead of each time a pile selection is made (inside the While loop).
You currently prompt the user for both a rotation angle, and offset for the text label you're adding following pile selection, but you're not doing anything with them yet (I get you needed help with that part; more on that below)... But I wanted to point out that currently you're extracting the pile Object's InsertionPoint Property (a variant), converting it to a list or reals, then using vlax-3D-Point to convert it back to a variant, when instead you could simply supply the original variant returned by the InsertionPoint Property.
You can us Polar to calculate the offset/rotated InsertionPoint to be used for your newly added MText, but in order to do this you need to supply a coordinate list, and not a variant... 'But you just made a point about converting from variant, etc.!?' - and I did, just stay with me... There often a few different means to get or set a particular Object's Property (i.e., vlax-get-property <obj> '<prop> etc.), and more so with the getting of Properties, these different means not only have a slightly different syntax, but more importantly each syntax yields a different result, or returned value.
Here's a quick example... I'm going to extract the InsertionPoint of a given block Object (VLA), and convert to a coordinate list (a list of real numbers):
Code:
(vlax-safearray->list (vlax-variant-value (vla-get-insertionpoint oBlock)))
... Or, I could simply extract the property as a coordinate list with:
Code:
(vlax-get oBlock 'insertionpoint)
... Which is both faster, and less code. Win-win.
In any event, I hope you find those comments helpful... Here's an untested LISP routine to demonstrate:
Code:
(vl-load-com)
(defun c:POSTAG (/ *error* _suffix prefix i ang d acDoc space clayer
eName oPile oText
)
(defun *error* (msg)
(and clayer (setvar 'clayer clayer))
(if acDoc
(vla-endundomark acDoc)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it
)
(princ)
)
(defun _suffix (i n)
(if (< (strlen i) n)
(_suffix (strcat "0" i) n)
i
)
)
(if
(and (setq prefix (getstring "\nEnter pile prefix: "))
(setq i (getint "\nEnter pile start number: "))
(setq ang (getreal "\nEnter text angle: "))
(setq d (getreal "\nEnter text offset from center of pile: "))
)
(progn
(vla-startundomark
(setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
)
(setq space
(vlax-get acDoc
(if (= 1 (getvar 'tilemode))
'modelspace
(if (= 1 (getvar 'cvport))
'paperspace
'modelspace
)
)
)
)
(setq clayer (getvar 'clayer))
(setvar 'clayer "TXT-GEN")
(while (and (setq eName (car (entsel)))
(setq oPile (vlax-ename->vla-object eName))
(vlax-property-available-p oPile 'posnumber)
)
(vlax-put oPile
'posnumber
(setq n (strcat prefix "-" (_suffix (itoa i) 3)))
)
(vla-rotate
(setq oText
(vla-addmtext
space
(vlax-3d-point
(polar (vlax-get oPile 'insertionpoint) ang d)
)
100.0
n
)
)
(vla-get-insertionpoint oText)
ang
)
(setq i (1+ i))
)
)
(cond (ang (prompt "\n** Must enter text offset ** "))
(i (prompt "\n** Must enter text angle ** "))
(prefix (prompt "\n** must enter pile start number ** "))
)
)
(*error* nil)
)
Separately, as a matter of drawing maintenance... To keep your files clean, and running quickly, you should make a habit of purging registry applications (scroll down):
Code:
Loading AEC Base...
Loading AEC Base Extended...
Loading AEC Base UI...
Loading AEC Project Base...
Loading AEC Base GUI...
Loading AEC Schedule Data...
Loading AEC Project UI...
Loading AEC Utilities...
Customization file loaded successfully. Customization Group: BLACKBOX
Initializing....
There are no valid MS Jet providers installed......Done.
Loading AECC Base...
Loading AECC Land...
Loading AECC Subentity Selection...
Loading Modeler DLLs.
Loading AECC Pipe Part...
Loading AECC QTO......
Loading AECC Pipe Network...
Loading AECC Roadway...
Loading AECC Survey...
Loading AEC Schedule...
Loading AECC Plan Production...
Loading AEC Architectural Base...
Loading AEC Structural Base...
Loading AEC Area Base...
Loading AEC Dimensions Base...
Loading AecCivilBase...
Loading AECC Building Site...
Loading AECC Point Cloud...
Regenerating model.
*Cancel*
Blacklist 1.0.0.0
Creative innovation by BlackBox, 2012
Loading blacklisted AutoCAD file definition(s):
acad.fas
acad.vlx
acaddoc.fas
acaddoc.vlx
bakdwg.fas
bakdwg.vlx
Blacklist: No blacklisted AutoCAD file(s) detected.
Purged 1153 registry applications from the current database.
AutoCAD menu utilities loaded.
Loading AECC Hydrology...
Loading AECC Base UI...
Loading AECC Event Viewer...
Loading AECC Land UI...
Loading AECC QTO UI...
Loading AECC Pipe Network UI...
Loading AECC Roadway UI...
Loading AECC Survey UI...
Loading AECC Plan Production UI...
Loading AECC Publish UI...
Loading AECC AeccUiHydrology...
Loading AECC Mapcheck...
Loading AECC Mapcheck UI...
Loading AECC Building Site UI...
Loading AECC Point Cloud UI...
Loading AECC Management UI...
Loading AECC 2011 SAP UI...
Loading AECC Model UI...
Loading MgdDbg...
XColor 1.0.0.0
Creative innovation by BlackBox, 2011
AutoCAD menu utilities loaded.Regenerating model.
>> Reactors Loaded
AutoCAD menu utilities loaded.
Autodesk DWG. This file is a TrustedDWG last saved by an Autodesk application
or Autodesk licensed application.