Oh you are creating a polyline that way...still the same problem and probably the solution. For example and what I tested only is this polyline creation part, lets say you have 6 pntucssort points, you are creating vertices and then you create polyline. The way you are creating your selection set of all created objects after profile_lastEnt, profile_ss has length of 7 (6 vertices and polyline). But you want to copy only polyline, can't copy vertices therefore the error. So you need to make selection set only with objects that are actually created and can be copied. So after creating each object (polyline, and later blocks and texts if I saw correctly) add that (entlast) to selection set. Or you could filter the selection set before ctd function to remove vertices, but I would filter them as objects are created, so after each object created put this:
(setq obj (entlast))
(ssadd obj profile_ss)