Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Attention: All Members DATA EXTRACTION TO EXCEL
#1
Hi.

If I have a polygon and select 'edit', the vertices are displayed in a table plus perimeter length and area.

Question.... Can that data ( or at least the vertices ) be exported to Excel ?

Thank you,
Graeme


Attached Files Thumbnail(s)
   
Reply
#2
Here is a DeltaCad macro I just wrote to read in the vertices of a polygon shape and 
put it in a CSV text file which can be imported into Excel.

Open your DeltaCad file with the polygon shape then copy and paste the code below into DeltaCad's Macro editor, save it and run it.

I programmed it so if you have more than 1 polygon shape it will put all of them in the same file and 
they will be separated by dashed lines and the word Polygon # then a number.

If you have more than 320 points you will need to change the line "num=320" to a larger number and 
change the line "Dim vert(640) As Double" to a larger number.

I named the text file PolyText.csv but you can rename it in the code to anything you want and 
the file will be in your DeltaCad\Macros folder when you run the macro.

I got most of the code from the dcGetShapeData sample in the DeltaCad help.
Reply
#3
I found some minor bugs in my code, so the code below should fix them.

Code:
Sub Main
'This sub finds all shape points
Dim ot As Long
Dim vert(640) As Double
Dim num As Long
Dim j As Long
Dim color As Long
Dim lt As Long
Dim lw As Long
Dim layer As String
P=1

Open "PolyText.csv" For Output As #1
ot = dcGetFirstObject("")
PT$=""

While ot <> dcNone
If ot = dcShape Then

Print #1,"Polygon # ,";P

num = 320
dcGetShapeData vert(1), num, color, lt, lw, layer
For j=1 to num
PT$=Format(vert(j*2-1))+", "+Format(vert(j*2))
Print #1,PT$
'MsgBox Format(vert(j*2-1))+", "+Format(vert(j*2))
Next j

Print #1,Chr$(34);"==================";Chr$(34);",";Chr$(34);"========================";Chr$(34)

P=P+1
End If
ot = dcGetNextObject
Wend
MsgBox "Found "+Str$(P-1)+" Polygons"
Close #1
End Sub
Reply
#4
(10-27-2020, 07:16 AM)AlwMVMO Wrote: I found some minor bugs in my code, so the code below should fix them.

Hi,
That seems to work, thank you.
I would have to remove unwanted polygons such as circles etc.
Possibly set up another .dc file with the same Cartesian grid / origin and copy the relevant polygons to the same xy point and extract from there.

Another question...........when I get the popup saying 'found 2 polygons', how do I save those vertices to a .csv file ?
Should PolyText.csv and a path have been be setup previously ?
Graeme


Attached Files Thumbnail(s)
   
Reply
#5
Quote:Should PolyText.csv and a path have been be setup previously ?


No, PolyText.csv is automatically created by the macro.
Yes, a path should have been be setup previously but a DeltaCad install should have created the\DeltaCad\macro folder already.
Check your Default Directory which is set in DeltaCad's menu Options / Options. Normally it would be C:\Program Files (x86)\DeltaCad


The line in the code that reads   >>  Open "PolyText.csv" For Output As #1  is the line of code that creates the file.
Because the macro is run from the\DeltaCad\macro folder the file PolyText.csv should have been created there.
If you want the CSV file created in a different folder then the line of code will need to be changed.
An example would be Open "C:\Program Files (x86)\DeltaCad\CSV\PolyText.csv" For Output As #1


===============================================================

I have a new macro code below that puts each polygon in its own and different CSV files (Polygon1.csv, Polygon2.csv . . . ect) and 
puts them in a different folder besides the macro folder.

The line of code that reads:
PFile$ = "C:\Program Files (x86)\DeltaCad\CSV\"
puts them in a folder called C:\Program Files (x86)\DeltaCad\CSV\ but you can create your own folder name.

Make sure the folder already exists before you run the macro.

P.S.
It is possible to code to open a "File Dialog" in the macro to pick any folder you want but it is a long and complicated process that would take time if you needed it.
Another possibility would be to put each polygon in different layers and have files created using the layers name. Maybe I will do that when I feel creative.

Code:
Sub Main
'This sub finds all shape points
Dim ot As Long
Dim vert(640) As Double
Dim num As Long
Dim j As Long
Dim color As Long
Dim lt As Long
Dim lw As Long
Dim layer As String
P=1

ot = dcGetFirstObject("")
PT$=""

While ot <> dcNone
If ot = dcShape Then
PFile$ = "C:\Program Files (x86)\DeltaCad\CSV\" : ' << Folder where CSV files are put.
Open PFile$+"Polygon"+Trim$(Str$(P))+".csv" For Output As #1

Print #1,"Polygon # ";P

num = 320
dcGetShapeData vert(1), num, color, lt, lw, layer
For j=1 to num
PT$=Format(vert(j*2-1))+", "+Format(vert(j*2))
Print #1,PT$
'MsgBox Format(vert(j*2-1))+", "+Format(vert(j*2))
Next j

P=P+1
Close #1
End If
ot = dcGetNextObject
Wend
MsgBox "Found "+Str$(P-1)+" Polygons"+chr$(13)+chr$(10)+"Files created in folder "+chr$(13)+chr$(10)+PFile$
Close #1
End Sub
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Asus Transformer Book T101HA raid data restore Sheryl 1 1,567 09-05-2018, 09:44 AM
Last Post: AlwMVMO

Forum Jump:


Users browsing this thread: 1 Guest(s)