There are plenty of examples of how to set and reset system variables. We usually don't test whether the sysvar value is or isn't value we want. It's a more complicated code for no meaningful reason. But what you should do for sure is to ensure that the value is returned to its value even in case of error (incl. ESC ending). That means to add the *error* function - localized, has to be localized!
Splines are removed by default - unless you mess with the DELOBJ variable.
Fit option - it makes the code significantly slower. But your first expression is correct.
Also, might be practical to wrap the code to a single undo group.
(defun c:HatchRecreatePolylineBoudary (/ *error* pea dlo doc s i e l f)
(defun *error* (errmsg)
(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
(princ (strcat "\nError: " errmsg)))
(if pea (setvar 'peditaccept pea))
(if dlo (setvar 'delobj dlo))
(vla-endundomark doc)
(princ)
)
; ----------------------------------------------------------------------------------
(vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
(if (and (setq s (ssget "_:L" '((0 . "HATCH"))))
(setq pea (getvar 'peditaccept)
dlo (getvar 'delobj))
(setvar 'peditaccept 1)
(setvar 'delobj 3)
)
(repeat (setq i (sslength s))
(setq e (ssname s (setq i (1- i))))
(setq l (entlast))
(command "_.HATCHEDIT" e "_B" "_P" "_N")
(if (and (setq f (entnext l))
(= "SPLINE" (cdr (assoc 0 (entget f)))))
(command "_.PEDIT" f 1 "_F" ""))
(setq f (entlast))
(command "_.BHATCH" "_P" "_S" "_S" f "" "")
(setpropertyvalue (entlast) "LayerId" (getpropertyvalue e "LayerId"))
(setpropertyvalue (entlast) "Color" (getpropertyvalue e "Color"))
(entdel e)
(entdel f)))
(*error* "end")
)
BTW the code is not explosive. Learn by trials, use the HELP system, use the search in these forums. Your question should be about the principles, good practices, not about what this does, or doesn't. That is the HELP for, there you can find the explanation within the seconds. Eg. HERE is the page about the IF function - there is even an example of using = comparison.