@Rovinator Your code works, except you would have to either:
1) Parse the "tag" property to add in the return code before inserting the tag.
2) Add the return into the tag itself.
Here is some code for option 1. I added in the function (pjk-StrParse), and added in some basic error handling. Tested minimally. NOTE: this only works properly if your tags always have the SAME format, i.e. the same number of "-" dashes, such as X-X-X-X (the X"s can be any length)
(defun c:VTL ( / cnsap myEnt pt1 sc strlst valvetag vlaobj)
(vl-load-com)
; get the Valve number from piping obj
(setq CSNAP (getvar "osmode"))
(setvar "osmode" 512)
(if
(and
(setq SC (getreal "\Text Height: "))
(setq myEnt (car (entsel "\nSelect Valve: ")))
(setq PT1 (getpoint "\Pick Label Location: "))
)
(progn
(setq vlaobj (vlax-ename->vla-object myEnt))
(if (vlax-property-available-p vlaobj 'Tag)
(progn
(setq ValveTag (vlax-get-property vlaobj 'Tag)
strlst (pjk-Strparse valvetag "-")
valvetag (strcat (nth 0 strlst) "-" (nth 1 strlst) "-\\P" (nth 2 strlst) "-" (nth 3 strlst))
)
(setvar "ATTDIA" 0)
(Command "-insert" "ValveNumberTag1" PT1 SC "" pause ValveTag "")
)
(princ "\nTag Property not found for select object.")
)
)
)
(setvar "osmode" CSNAP)
(princ)
)
;|==============================================================================
Function Name: (pjk-StrParse)
Arguments:
str = String; String to process
del = String; Delimiter to separate the string
Usage: (pjk-StrParse <string> <delimter>)
Returns: List; A list of strings
Description:
Separates a string into a list of strings using a
specified delimiter string; uses recursion.
================================================================================|;
(defun pjk-StrParse (str del / pos)
(if (and str del)
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos) (pjk-StrParse (substr str (+ pos 1 (strlen del))) del))
(list str)
)
)
) ;; End Function (pjk-StrParse)
Option 2 - NO CODE: