reckon this will help
https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-8543549B-F0D7-43CD-87A3-F6B827FF0B88
Probably: vl-string-subst
Worth noting that the backslash often denotes the next character is a special character (a tab \t, new line, \n and so on) so to make it useable you might need a double \\ (tell the LISP you want to use the special character \)
Can you post a sample drawing, I am not quite sure what you are wanting.
A second thing you could do - and that might almost write the LISP for you.. is write down all the steps you do manually. Get it working for one viewport and the change to select all of them is usually quite easy
The first step to becoming a proficient programmer is learning how to debug code. Open up the VLIDE and set break on error.
Then load the selection:
There are a couple of issues with line 3: (setq vertices (vlax-invoke pline 'vertices))
vlax-invoke requires a VLA-OBJECT (vlax-ename->vla-object pline) and a polyline does not have a vertices property, it's coordinates.
Here is a common way to get LWPOLYLINE coordinates
(mapcar 'cdr (vl-remove-if '(lambda (x) (/= 10 (car x))) (entget pline)))
This returns ((X Y) (X Y) (X Y) (X Y))
Another way is like this which works on "heavy" polylines as well:
(vlax-get (vlax-ename->vla-object pline) 'coordinates)
This returns (X Y X Y X Y X Y)
It does not look like you're using the vertices variable for anything except setting the num-vertices variable ? An easier way to get that number is through the 90 DXF code.
(cdr (assoc 90 (entget pline)))
are you making a new polyline, so you have 2, or are you trimming the existing to the points, P1 and P2, to leave 1 polyline?
If you make a copy the process will be the same after that to trim it to the points.
I have something that might work, but for now a sample drawing to see what you are wanting might help
My opinion is that it's a great tool for a knowledgeable person but could be problematic for a novice like me.
Because of my limited knowledge I would run the risk of having bad code, or worse, harmful code.
BUT... in the right hands it's a great advancement.