Start a new topic

Re Number Verticies

Is it possible to re number vertices with a script?

If I select a vertex, and then select a polygon, can I iterate through verticies of the polygon and re number them so that the vertex I selected is the first vertex?

If someone can point me towards a command, or a general approach I think I can code it.



The order of the vertices is determined by their order in the hierarchy. To reorder them, you can detach and then attach them in the correct order. Key functions to use are:

mgDetach   - you cannot attach something that is already attached. you need to first detach or the other functions will fail

mgAttach    - attaches the child as the first child (prepend)

mgAppend  - attaches the child as the last child

mgInsert     - attaches the child relative to another child

Here is a completed script that shows how to do the reorder. It assumes that the target vertex you want to be moved to the front is selected. 


db = mgGetCurrentDb ()
selectList = mgGetSelectList (db)
targetvert, m = mgGetNextRecInList (selectList)
if (targetvert is None or mgGetCode(targetvert) != fltVertex):
	mgSendMessage (MMSG_ERROR, "Select a vertex to make first")
	polygon = mgGetParent(targetvert)
	# find the last vertex in the polygon
	endvert = targetvert;
	nextVert = mgGetNext(endvert)
	while nextVert:
		endvert = nextVert;
		nextVert = mgGetNext(endvert)

	# starting from end of verticies, attach to front until
	# we get to the selected vertex
	while endvert != targetvert:
		prevVert = mgGetPrevious(endvert)
		mgAttach(polygon, endvert)
		endvert = prevVert;
	# finish by moveing the selected vertex to the front
	mgAttach(polygon, targetvert)


Key things to note about this procedure is that mgGetParent, mgGetNext and mgGetPrevious… all rely on the node being attached already. You need to be careful about when you use mgDetach. As long as you are mindful of that and make sure you detach before trying to re-attach, it is pretty easy to re-arrange your hierarchy to your own designs.

This is very similar to the Reorder tool in Creator. The code for this tool is incuded in the samples\scripts\creatortools folder of the OpenFlight API installation ( The Reorder tool reorders children based on the order you select ALL the verts of a polygon so you'll have to adapt it a bit but it should help get you started. Even though Chris already made the apaptation I encourage you to check out the code in this folder to see how other Creator tools use the OpenFlight API to do their thing.

Login to post a comment