@Anonymous_dude wrote:
This is what I've come up with, and it seems to work great. Can you tell me if its coded efficent?
....
It could be reduced somewhat.
(defun c:pb (/ olayer pt1 pt2 dist ang pt3); added the rest of the local variables
(setq ; combined more variable settings into the one (setq) function
olayer (getvar 'clayer); most people use this simpler approach [at both ends], without all the (vlax-...) stuff
pt1 (getpoint "\n Select First Point: ")
pt2 (getpoint "\n Select Second Point: ")
dist (distance pt1 pt2)
ang (angle pt1 pt2)
pt3 (polar pt1 ang (/ dist 2.0))
); end setq
(command "-layer" "m" "c_gen_symbol" "c" "80" "" "")
; no need to check for it; the Make option will set it current for you; and no need to
; specify continuous linetype [even if you spell it right], because it's always the default,
; unless you think maybe the Layer may already exist with a different linetype, and
; you want to correct that
(setvar 'plinewid 0.0)
(command ".pline" pt2 "arc" "angle" "60" pt3 pt1 "angle" "-60" pt3 "")
(setvar 'clayer olayer)
(princ)
)
One thing I did that is completely optional [but saves an entire code character in each instance!] is to use the apostrophe before system variable names ['clayer, 'plinewid] in place of the double-quotes both before and after. Both (setvar) and (getvar) functions will work with either approach.
EDIT: Also, you don't need the hyphen before the Layer command name. You would need it in a command macro or a Script, to suppress the dialog box, but not inside a (command) function, where the default is to not use the dialog box [if you want one, you need to force it to come up by preceding the (command) function with (initdia) to INITiate the DIAlog box]. If you're using any overlay program such as the specialty Architectural or Civil or other ones, it's possible that it will have a specially-defined Layer command, and will have undefined the native Layer command, so that (command "layer" ...) will not work. So I always use the preceding decimal to force it to use the native AutoCAD command, and I use the preceding underscore so it will work in other-than-English-language versions AutoCAD, since these Boards are used by people all over the world: (command "_.layer" ...).
Further EDIT: To be really safe, as described in my first Reply, you might add Thawing that Layer first:
(command "_.layer" "t" "c_gen_symbol" "m" "c_gen_symbol" "c" "80" "" "")
but don't bother if there's no likelihood that it would ever be Frozen.
AND another thing: You can combine more than one command into a single (command) function:
(setvar 'plinewid 0.0)
(command
"_.layer" "t" "c_gen_symbol" "m" "c_gen_symbol" "c" "80" "" ""
".pline" pt2 "arc" "angle" "60" pt3 pt1 "angle" "-60" pt3 ""
); command
Consider also whether you should have the routine turn running Object Snap off, because you may get unexpected results if you don't.
Kent Cooper, AIA