Jump to content

Modify First Vertex of multi areas (polygons) to vertex more to north


Recommended Posts

Oh, I see now.


There's a function that replaces the list of coordinates

(vlax-put (vlax-ename->vla-object ent) 'coordinates coords)


So I read the coordinates, set the most North one to 0, then replace the coordinates.


Like this:

Command MFV for Modify First Vertex



;; LW Vertices  -  Lee Mac
;; Returns a list of lists in which each sublist describes
;; the position, starting width, ending width and bulge of the
;; vertex of a supplied LWPolyline
(defun LM:LWVertices ( e )
    (if (setq e (member (assoc 10 e) e))
                (assoc 10 e)
                (assoc 40 e)
                (assoc 41 e)
                (assoc 42 e)
            (LM:LWVertices (cdr e))
(defun getVertices ( pline / verts vert res)
	(setq verts (LM:LWVertices (entget pline) ))
	(setq res (list))
	(foreach vert verts
		(setq p (cdr (assoc 10 vert)))
		(setq res (append res (list p)))

;; returns the index of the vertex with the max Y value
(defun getMaxYVert ( verts / maxY i ind)
	(setq maxY nil)
	(setq ind 0)
	(setq i 0)
	(foreach a verts
		(if (= nil maxY)
			(setq maxY (nth 1 a))
			(if (> (nth 1 a) maxY)
					(setq ind i)
					(setq maxY (nth 1 a))
		(setq i (+ i 1))

;; MFV for Modify First Vertex
(defun c:MFV ( / ss i j ent verts maxYindex verts2 coords)
	(setq ss (ssget (list (cons 0 "*POLYLINE") (cons 70 1))))
	(setq i 0)
	(repeat (sslength ss)
		;;(princ "\n")
		(setq ent (ssname ss i))
		(setq verts (getVertices ent))
		(setq maxYindex (getMaxYVert verts))
		(setq coords (list))		;; new list of coordinates. (list x0 y0 x1 y1 x2 y2...), rearraned to have the most North one first
		(setq j 0)
		(princ maxYindex)
		(repeat (length verts)
			(setq coords (append coords (list
				(nth 0 (nth (rem (+ j maxYindex) (length verts)) verts))
				(nth 1 (nth (rem (+ j maxYindex) (length verts)) verts))
			(setq j (+ j 1))
		;; now replace the verices verts by coords
		(vlax-put (vlax-ename->vla-object ent) 'coordinates coords)
		;;(princ coords)
		(setq i (+ i 1))


Edited by Emmanuel Delay
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...