Convert Qleaders to Same-Style Mleaders (AutoLISP Solutions AutoCAD Tutorial)31 Aug, 2008 By: Tony Hotchkiss
Q2M routine automatically converts a leader while maintaining the style and text of the original.
Scott Loadman of San Antonio, Texas, requested a routine for changing a Qleader to an Mleader in an AutoCAD drawing by simply entering "Q2M" as a command. Scott uses the same style for both Qleaders and Mleaders, and he usually uses Qleaders, but sometimes finds that it would have been more appropriate to have the Mleader. Instead of deleting the existing leader and creating an Mleader, it would be easier to convert to the Mleader by simply typing a quick command and selecting the Qleader to be converted.
The AutoLISP Solution is Q2M.LSP, which allows the user to enter Q2M on the AutoCAD Command line, then select the Qleader which is automatically converted to an Mleader that maintains the same style and text as the original.
Get the Code!
Download the Q2M.LSP file from Cadalyst's CAD Tips site. Save the file in AutoCAD's Support directory. Use the Appload facility by selecting Tools / Load Application, and then use the browser to select the Q2M.LSP file.
How to Use the Q2M.LSP Code
To start the program, enter Q2M, and you will be prompted to "Select the Qleader."
The Qleader selection prompt.
After the Qleader is selected, it is automatically converted to the Mleader using the same coordinates, layer, and text as the original.
Both the leader and the text are now highlighted.
Note that the first figure shows that only the leader and not the text is highlighted, as is the case for Qleaders. The second figure shows that both the leader and the text are highlighted when the cursor is moved over the leader. This denotes that that the object is now an Mleader.
The program starts with my usual error handler and system variable manager. These functions are followed by the function Q-TO-M that sets some environment variables and uses the Visual LISP method VLA-GETENTITY to allow the user to select the Qleader object to be converted. The Qleader object is then supplied as an argument to the function DO-Q2M, which completes the job of converting the Qleader to the Mleader. Some ActiveX methods place values into variables that have the appearance of quoted arguments, and VLA-GETENTITY is one of those. The code here shows that both the Qleader and the point that is selected by the user are returned in this way:
(vla-GetEntity *utility* 'Qleaderobject 'PickedPoint "\nSelect the Qleader")
The quoted variable names are described as output only, and the GETENTITY method actually returns nil, so there is no need to use the SETQ function to capture the variables. This approach to returning values as quoted arguments is common when more than one returned value is required, such as in the bounding box points of the BOUNDINGBOX method that I have used elsewhere in these AutoLISP solutions.
The function DO-Q2M uses the ADDMLEADER method to create a new Mleader object before deleting the original Qleader object. This should be simple enough to work properly, but on testing, the text attached to the new Mleader was placed on the left side of the leader hook on the drawing that Scott Loadman provided, even though the text was on the right side in the Qleader. I then added some code in an effort to control the text placement by controlling the coordinates of the leader and text justification, but this still did not produce the correct result. The length of the hook on a leader defaults to the arrowhead length, and I tried creating three coordinates in an attempt to get the text to follow the hook, but again to no avail. I left the function DO-NEWARRAY in the program out of interest, but it should not be necessary because any third coordinate is optional in the creation of leaders.
Paradoxically, when I created my own Qleader in Scott's drawing, the AutoLISP routine worked correctly on the conversion to the Mleader, and I have not been able to determine why this happens. It is easy enough to move the text manually from one side to the other once the conversion to the Mleader is complete, and Scott tells me that using the new routine is still much easier than deleting the Qleader and starting from scratch on the Mleader. I hope that on new drawings the routine will give the correct result as it did for me as shown in the figures.
As always, I look forward to receiving your comments and requests for AutoLISP Solutions. Please contact me using the links below.