@Tony_Gibbs wrote:
....
(setq BarLength (getreal "\nEnter New Bar Length or Use <500>"))
....
(initget 33) (setvar "osmode" 513)
....
(command ".fillet" ThirdLine FourthLine
".lengthen" "T" 500 ThirdLine FourthLine ""
....
A few comments on the above....
The BarLength variable is never used. It can be asked for with any previous setting offered as default, or 500 if there is no previous setting [@smaher12 included a way of doing that; my suggestion below is another way].
If 500 is a typical bar length value, I assume you never need decimals, so it may as well be (getint) rather than (getreal).
Setting OSMODE to 513 is pointless, because the NEArest part of that will always "win out" over the ENDpoint part -- just use 512 for Nearest only.
Since the lines drawn are Polylines, if you adjust the code to successfully Fillet them, the result will be one Polyline [the same entity name as the latest one drawn], so Lengthen will not be able to find one of those that it's asked to work on, because it will no longer exist. And if it gets to seeing the one that still exists, that will be shortened to an overall length of 500 [both legs combined], approximately removing one leg, except for the fact that Lengthen also requires not just an entity name but a point, so it knows which end to change.
And some other issues....
You have several unnecessary (progn) functions that "wrap" groups of things that don't need to be wrapped -- they can all stand on their own within the (while) function.
The (initget 33) ought to be repeated for the SecondBar prompt as for the FirstBar prompt.
Since you turn off ORTHO, I assume the legs of these bent bars will not always be perpendicular. When they're not, @smaher12's suggestion will not result in correct leg lengths -- the adding of 25 to the initial lengths before Offsetting will work right only with a right-angle bend.
You can just get the angles of the legs directly as angles, rather than get points and work with the angles from the corner to them.
The whether-to-continue thing can be based directly on whether the User picks a corner point, without the 'a' variable and the checking for it.
Here's a [minimally tested] way of doing it that accounts for all of those things:
(vl-load-com)
(defun C:qqq (/ InsPt Ang1 Ang2 start pl1 pl2)
(savevartoold) (reobarlayer) (setvar 'osmode 1) (setvar 'orthomode 0)
(setq BarLength ; non-localized variable to remember for later use
(cond ; [assuming always integer values used]
( (getint ; [returns nil on Enter]
(strcat
"\nEnter New Bar Length <"
(if BarLength (itoa BarLength) "500"); prior value as default if present
">: "
); strcat
); getint
); User-input condition
(BarLength); User pressed Enter with prior value
(500); Enter with no prior value [first use]
); cond
); setq
(while (setq InsPt (getpoint "\nSelect Insertion Corner <exit>: "))
(setvar 'osmode 512)
(initget 33)
(setq Ang1 (getangle InsPt "\nFirst corner bar direction:"))
(initget 33)
(setq Ang2 (getangle InsPt "\nSecond corner bar direction:"))
(command "_.pline"
"_none" (setq start (polar InsPt Ang1 BarLength))
"_none" InsPt
"_none" (polar InsPt Ang2 BarLength)
""
"_.offset" 25 (list (setq pl1 (entlast )) InsPt)
(mapcar '/ (mapcar '+ start (vlax-curve-getEndPoint pl1)) '(2 2 2)) ""
"_scale" (setq pl2 (entlast)) ""
(setq InsPt (vlax-curve-getPointAtParam pl2 1)); replace former value
"_reference" (distance InsPt (vlax-curve-getStartPoint pl2)) BarLength
); command
(entdel pl1)
(setvar 'osmode 1); for next one
); while
(resetoldvar)
(princ)
); defun
It could replace the Offsetting and length adjustment and deletion of the initial Polyline, with just MOVE-ing the Polyline instead. That would eliminate some steps and at least one variable, but would also require some trigonometric calculations to determine how far and in what direction to Move it.
Kent Cooper, AIA