Help exporting edges to CSV file

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  08 August 2012
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 "%\n" 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 "%\n" 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 "%\n" 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 "%\n" theArrayInv.count
format "%\n" theEdges
---format "%\n" 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 "%\n" theEdges --print the result to the Listener
 
 format "%\n" theArrayInv
 format "%\n" theArrayInv.count
 format "%\n" theEdgesFinal.count
 
 for i =1 to theEdgesFinal.count do
	format "%,%,%,%,%,%\n" 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
 */



)
 
  08 August 2012
Bobo - Help

THIS is most urgent please
anyone?


is there a place where I can checkout some tuts on arrays...
 
  08 August 2012
Solved

-----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 "%,%,%,%,%,%\n" v1[1] v1[2] v1[1] v2[1] v2[2] v2[3] to:out_file
)
)
close out_file
 
  08 August 2012
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:44 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.