@carlos_m_gil_p wrote:
....
I think they should be separate.
....
That's actually a little easier than making one all-the-way-around 3DPolyline, I think. Try this out:
;; TraceCentroidsAroundMeshEdges.lsp [command name: TCAME]
;; To Trace along the Centroids [averaged corner locations] of a polygon
;; Mesh's Edge faces, with a 3DPolyline along each edge, colored separately.
;; Kent Cooper, 12 October 2015
(defun C:TCAME ; = Trace Centroids Around Mesh Edges
(/ asso centroid edge mesh edata m n faces)
(defun asso (code)
(cdr (assoc code edata))
); defun -- asso
(defun centroid (face / edata c c1 c2 c3 c4)
(setq
edata (entget face)
c 4 ; initial assumption number of corners
c1 (asso 10) c2 (asso 11) c3 (asso 12) c4 (asso 13); corners
); setq
(if (equal c3 c4 1e-4) (setq c4 '(0 0 0) c 3)); 3-sided
(mapcar '/ (mapcar '+ c1 c2 c3 c4) (list c c c)); return average of corners
); defun -- centroid
(defun edge (index dir inc color / index clist)
(repeat dir
(setq clist (cons (centroid (ssname faces (setq index (+ index inc)))) clist))
); repeat
(command "_.3dpoly")
(foreach c clist (command "_none" c))
(command
"" ; end 3dPoly
"_.chprop" "_last" "" "_color" color ""
); command
); defun -- edge
(if
(and
(setq mesh (car (entsel "\nSelect Polygon Mesh: ")))
(setq edata (entget mesh))
(= (logand (asso 70) 16) 16); it's a polygon mesh
); and
(progn ; then
(setq
m (1- (asso 71)); # of resulting 3dFaces in M direction
n (1- (asso 72)); in N direction
); setq
(command
"_.copy" mesh "" '(0 0 0) "@"
"_.explode" "_last" ; turns into 3dFaces
); command
(setq faces (ssget "_P")); results from Exploding copy of Mesh
(edge -1 n 1 1); trace centroids on first edge [red]
(edge -1 m n 2); second edge [yellow]
(edge (1- (* (1- m) n)) n 1 3); 3rd edge [green]
(edge (- n) m n 5); fourth edge [blue]
(command "_.erase" faces ""); [optional]
); progn
(prompt "\nNothing selected, or not a Polygon Mesh."); else
); if
(princ)
); defun
Some things to note:
I thought the average of the four corner locations of a 3dFace was the same as its centroid, but they seem to come out in a slightly different location than yours, when used in your first example drawing. Converting a 3dFace to a Region will give a real centroid, but Regions need to be planar, so the warped faces can't be done that way. Since Post 4 sounds like it's not critical, I didn't do anything about it, and maybe I should have avoided the word "centroid" in the routine, but I left it in.
It does only a single Polygon Mesh object, not the perimeter of the larger multi-mesh collective "objects" in your second sample drawing. I'm not sure it would be possible [or at least it would be very much more complicated] to draw along the overall-collective edges on those.
It could use the usual enhancements -- error handling, command-echo suppression, undo begin/end wrapping, etc., but those can be added easily enough, if it works for you otherwise.
If you are Zoomed in far enough that any of the 3DPolylines it draws will not be visible on-screen, the color assignments will not come out right, and one or more of those colors could be imposed on something other than the new 3DPolylines. It could be made to Zoom out to prevent that problem, if you like.
Kent Cooper, AIA