Notifications
Clear all

[Closed] Help exporting edges to CSV file

Hello everyone I am trying to make a script that exports a list of edges to a CSV files.
Now these EDGES are special:
because they are the visible ones
because they if they are overlapping I want just one of them.

Now here is the problem:
what my script does is grab a mesh, build an array of visible edges. In that array search for duplicates and now the major problem: find the overlapping edges.
Now the overlapping edges have oposite vertex that is, if edge is made of AB vertexs the overlapping edge will be the BA vertex. Now how can I find these values in an Array of Arrays. this is a multidimensional array with both points of an edge per line.

so I need a way to find DUPLICATES values and MIRRORED values inside an array.
NOW this does not evaluate right. If you use a cube it will return 18 or so edges…

WHAT IS WRONG CAN YOU HELP!!

please see the code:


-----bernardo amorim
-----for FRANZ the god of mapping 
-----with help of bobo and me.....
-----2012

fn edgeVerts theObj theEdge = 
( 
	if not (classof theObj == Editable_mesh or classof theObj == triMesh) do 
	return undefined 
	if theEdge < 1 or theEdge > (theObj.numfaces*3) do 
	return undefined 
	local theFace = ((theEdge-1)/3)+1 
	local theVerts = getFace theObj theFace 
	case ((mod (theEdge-1) 3) as integer) of 
	(
		0: point2 theVerts.x theVerts.y 
		1: point2 theVerts.y theVerts.z 
		2: point2 theVerts.z theVerts.x 
	) 
) 

fn reverseArrayCopy arr =
(
for i = arr.count to 1 by -1 collect arr[i]
)	
	
fn compareSubArrays first second =
(
 result = true
 if first.count != second.count then 
  result = false
 else 
  for i = 1 to first.count do  if first[i] != second[i] do result = false

 result 
)
/*


*/

out_name = getSaveFileName caption:"Open A Test File:" filename:"franz.csv"
out_file = createfile out_name



for obj in selection do (
	tmesh = convertToMesh  obj
	tmesh.allEdges = true 
	
	theEdges = #()
	theArrayInv = #()
	edgeSelSet= #() -- Init. an Array
	
	for face = 1 to tmesh.numfaces do -- Go through all faces
		for edge = 1 to 3 do -- And for every of the 3 edges
		if (getedgevis tmesh face edge) do -- If the visibility is true,
		append edgeSelSet (((face-1)*3)+edge) --collect the edge
		--setedgeselection tmesh edgeSelSet -- Select all visible edges

format "%
" edgeSelSet.count
	
for i = 1 to edgeSelSet.count do (
	theEdges[i] = #()
	for u = 1 to 2 do (
		theEdges[i][u] = #()		
		v1 = getVert tmesh (edgeVerts tmesh edgeSelSet[i])[1]
		v2 = getVert tmesh (edgeVerts tmesh edgeSelSet[i])[2]
		theEdges[i][1] = v1
		theEdges[i][2] = v2
		)
)



format "%
" edgeSelSet.count

for i = 1 to theEdges.count do --go through all elements of the main array
for j = theEdges.count to i+1 by -1 do --go backwards from the last to the current+1
 if compareSubArrays theEdges[i] theEdges[j] do 
  deleteItem theEdges j --if identical, delete the one with the higher index
---format "%
" theArray --print the result to the Listener

 
 for j = 1 to theEdges.count do (
	theArrayInv[j] = #()
		for h = 1 to theEdges[j].count do (
			theArrayInv[j][h] = #()
			theArrayInv[j][1] = theEdges[j][2]
			theArrayInv[j][2] = theEdges[j][1]
		)
	)	
format "%
" theArrayInv.count
format "%
" theEdges
---format "%
" theArrayInv	

theEdgesFinal = deepCopy theEdges


	
for i = 1 to theEdgesFinal.count do --go through all elements of the main array
for j = theEdgesFinal.count to i+1 by -1 do --go backwards from the last to the current+1
 if compareSubArrays theEdgesFinal[i] theArrayInv[j] do 
  deleteItem theEdgesFinal j --if identical, delete the one with the higher index
---format "%
" theEdges --print the result to the Listener
 
 format "%
" theArrayInv
 format "%
" theArrayInv.count
 format "%
" theEdgesFinal.count
 
 for i =1 to theEdgesFinal.count do
	format "%,%,%,%,%,%
" theEdgesFinal[i][1][1] theEdgesFinal[i][1][2] theEdgesFinal[i][1][3] theEdgesFinal[i][2][1] theEdgesFinal[i][2][2] theEdgesFinal[i][2][3] to:out_file
close out_file
 
 
 /*2
 

2
 */



)
2 Replies

THIS is most urgent please
anyone?

is there a place where I can checkout some tuts on arrays…

—–bernardo amorim
—–for FRANZ the god of mapping
—–2012

out_name = getSaveFileName caption:“Open A Test File:” filename:“franz.csv”
out_file = createfile out_name

for obj in selection do (
tmesh = convertToPoly obj
theEdges = #()
num_edges = obj.GetNumEdges()
for i = 1 to num_edges do(
v1 = polyop.getVert obj (obj.GetEdgeVertex i 1)
v2 = polyop.getVert obj (obj.GetEdgeVertex i 2)
format “%” obj.name to:out_file —-dont know if you need this or not
format “%,%,%,%,%,%
” v1[1] v1[2] v1[1] v2[1] v2[2] v2[3] to:out_file
)
)
close out_file