Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel writes tower.scr which then draws a 3D tower in Acad

Excel Makes AcadScript Files

Excel writes tower.scr which then draws a 3D tower in Acad

by  tigrek  Posted    (Edited  )
'Make Excel write Acad Script Files which draw things.
'Very elegant where math outweighs graphics.
'Trick dicovered by me in year 2000, unless before that ...
'The Tower application is due to inspiration from Bindas of this forum.

'www.homescript.com

Dim dx, dy, dz, w, h, z, TopX, TopY, ThisX, ThisY, i, j, k, P1, P2, Width, slope1
'Dim hBars(), dBars() As Double

Sub Acad3Dtower()
'Open a new excel Workbook, Alt+F11 for VBA Editor, Insert new module, paste this code there
'save the file - this path defines where the script file will go.
'Run command from Tools/Extras ->Macros->runMacro
'Coordinates of 12 horizontal bars at each level will be written into script file Tower1.scr
'From AcadMenu->Tools->RunScript pick this file and watch the tower draw
'use acad commands _3dcorbit etc to see the 3Dtower (only horizontal bars - for demo)
'with command _id pick a point to see the coordinates on command line.
'Next weekend I may add the contour and diagonal bars of the tower too - no time now, sorry folks!

'Data in meters
dx = Array(1.75, 1.75, 8.23)
dy = Array(1.75, 1.75, 8.23)
dz = Array(0#, -6#, -60#)
'horizontalBars
hBars = _
Array(0#, -2#, -4#, -6#, -9#, -12#, -16#, -20#, -25#, -30#, -35#, -40#, -45#, -50#, -55#, -60#)
'diagonalBars
dBars = _
Array(0#, -1#, -3#, -5#, -7.5, -10.5, -14#, -18#, -22.5, -27.5, -32.5, -37.5, -42.5, -47.5, -52.5, -57.5)
'Top Frame Coordinates - assuming top center of tower be (0,0,0)
'4 Corners and 4 midpoints, from upperRight, Clockwise
w = dx(0): h = dy(0): z = dz(0)
TopX = Array(w / 2, w / 2, w / 2, 0, -w / 2, -w / 2, -w / 2, 0)
TopY = Array(h / 2, 0, -h / 2, -h / 2, -h / 2, 0, h / 2, h / 2)
For i = 0 To 7: Debug.Print "Level "; z; "Point "; i; TopX(i); ","; TopY(i); ","; z: Next i
'Open a scriptFile
MyScriptFile = ActiveWorkbook.Path & "\" & "Tower1.scr"
Open MyScriptFile For Output As #1
Close #1
Open MyScriptFile For Append As #1

'HorizontalBars
For i = 1 To UBound(hBars)
z = hBars(i)
slope1 = slope(z)
w = w + slope1 * 2 * (z - (hBars(i - 1)))
h = h + slope1 * 2 * (z - (hBars(i - 1)))
'4 Corners and 4 midpoints at this level

ThisX = Array(w / 2, w / 2, w / 2, 0, -w / 2, -w / 2, -w / 2, 0)
ThisY = Array(h / 2, 0, -h / 2, -h / 2, -h / 2, 0, h / 2, h / 2)
Debug.Print hBars(i); " m. slope at level "; i; slope(hBars(i)); "width "; w

fromTo 0, 2
fromTo 0, 4
fromTo 0, 6
fromTo 1, 3

fromTo 1, 7
fromTo 2, 4
fromTo 2, 6
fromTo 3, 1
fromTo 3, 5

fromTo 3, 6
fromTo 4, 6
fromTo 5, 7

Next i
Close #1
End Sub
Sub fromTo(P1, P2)
Debug.Print "... Horiz Bar "; (ThisX(P1) & "," & ThisY(P1) & "," & z); " To " _
; (ThisX(P2) & "," & ThisY(P2) & "," & z)
'Append to script file
MyString = "_Line " & (ThisX(P1) & "," & ThisY(P1) & "," & z) & " " & (ThisX(P2) & "," & ThisY(P2) & "," & z) & " "
Print #1, MyString
End Sub

Function slope(elev)
j = 0
Do While dz(j) > elev
j = j + 1
Loop
If j = 0 Or (dy(j) - dy(j - 1)) = 0 Then
slope = 0
Else
slope = ((dy(j) - dy(j - 1)) / 2) / (dz(j) - dz(j - 1))

End If

End Function

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search