×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Excel Makes AcadScript Files

Excel writes tower.scr which then draws a 3D tower in Acad by tigrek
Posted: 26 Aug 01

'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


Back to Autodesk: AutoCAD FAQ Index
Back to Autodesk: AutoCAD Forum

My Archive


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close