Changing Element Properties in Revit Structure

When you define Beams in Revit Structure the software automatically draws a driving line on top of the Beam. That line will meet a same line from a Column and their meeting point will actually become a node. So the “z-Direction Justification” is a property of Beams that describes the vertical position of the beam related with the imaginary line that connects the start and end point of the Beam. This parameter can get 3 different values TOP / CENTER / BOTTOM and we imagine the difference.

So using the SAP_2_ RS tool, we needed to set the z-Direction Justification to CENTER in order to be precise and the code is the following.(the default value is on TOP)

‘drawing beam

myBeam = myModel.Create.NewFamilyInstance(myBeamLine, beam_sym, my_level, Autodesk.Revit.DB.Structure.StructuralType.Beam)

‘giving the right z Direction Justification

Dim V_justification As Autodesk.Revit.DB.BuiltInParameter = Autodesk.Revit.DB.BuiltInParameter.BEAM_V_JUSTIFICATION

Dim myParameter As Autodesk.Revit.DB.Parameter = myBeam.Parameter(V_justification)

myParameter.[Set](1)      ’ here: 0 is Top  /  1 is Center  /  2 is Bottom

These lines need to be used after “drawing” the beam and this is the way to approach and change other parameters of elements if needed.. (got a lot of intelligense there)

enjoy

 

Dialog Boxes and VBYesNo

So I was experimenting with the VBYesNo function in order to get some interactivity as I’m building up the Gerilla Materials & Assembly routine. If you haven’t found it yet this is a super useful function that allows you to avoid firing off data to another program accidentally:

‘Save to Gerilla Library
Dim GerillaLibraryPath As String = ”C:\geRILLA\Libraries\Materials\”

Dim GerillaDatabaseMessageBox As Integer

If myGerillaDatabase = ”True” Then

If System.IO.File.Exists(GerillaLibraryPath & myName & ”.txt”) = True Then

Select Case (GerillaDatabaseMessageBox = MsgBox(“This material already exists in the Gerilla Library. Do you want to overwrite?”,vbYesNo,”Save Material”))
Case vbYes
Dim ObjectWriter As New System.IO.StreamWriter(GerillaLibraryPath & myName & ”.txt”)
For j As Integer = 0 To myMaterialOutput.Count – 1
ObjectWriter.WriteLine(myMaterialOutput(j))
Next
ObjectWriter.Close()
MsgBox(“Material Updated”)
Case vbNo
MsgBox(“Material NOT Saved”)
End Select

Else
Dim ObjectWriter As New System.IO.StreamWriter(GerillaLibraryPath & myName & ”.txt”)
For j As Integer = 0 To myMaterialOutput.Count – 1
ObjectWriter.WriteLine(myMaterialOutput(j))
Next
ObjectWriter.Close()
MsgBox(“Material Updated”)
End If

End If

Package that with a Case statement and you’ve got yourself a little bit of windows-style flair.

Mike

Revit Code Resources

Interoper’s,

The following are some of the best site’s I’ve found that deal with the Revit API, as well as other issues revolving around automation and interoperability through other programs.

The Proving Ground , Nathan Miller

Excellent blog that deals with many instances of Interoperability. Specific code examples for Revit API .CSV XYZ import and Mathematical surface generation available.

http://theprovingground.wikidot.com/

The Building Coder, Jeremy Tammik

A very thorough blog that deals specifically with using the Revit API to automate tasks in Revit. Many example scripts available. Whilst not dealing directly with Interoperability issues, this is the best place on the web for Revit API assistance.

http://thebuildingcoder.typepad.com/

BIMBOOMBAM, Michelle Van Kolck

BIM focused blog, somewhat Revit-centric that explores the possibility of BIM data being shared across different CAD platforms.

http://bimboombam.wordpress.com

GeometryGym, Jon Mirtschin

Geometry Gym is a blog almost solely dedicated to solving interoperability problems. For a link between Grasshopper and Revit Jon is  utilizing the IFC (Industry Foundation Classes, an object-based file format with a data model developed specifically for use in the building industry for interoperability purposes) as the means of translation. The IFC Wiki also has some great links to example interoperability projects (see below).

http://www.geometrygym.blogspot.com/

http://www.ifcwiki.org/index.php/Examples

Buildz, Zach Kron / Joe Kendsersky

“Practical notes on making impractical things”. Whilst not delving into the scripted side of interoperability Joe offers many useful techniques for transferring 3D models between various software.

http://buildz.blogspot.com

RevitAppBlog, Various

Revit VB code examples and a good discussion thread of the possibilities/ techniques available when using the Revit API.

http://blog.revitapp.com/category/coding/

DesignReform, CASE Inc.

Design reforms provides many resources to the building technology minded. Excellent video tutorials in addition to a strong user community

http://designreform.net/

AutoCADRevit Documentation

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=14996975

VB Code examples and in depth documentation on the Revit Platform.

http://images.autodesk.com/adsk/files/3968933_Revit_Interoperability_w_CAD.pdf

White paper dealing with Interoperability issues relating specifically to a link between AutoCAD and Revit. Methodology revolves around exporting 2D Revit drawings onto empty AutoCAD sheets and then linking the files via the “Import/Link” command.

N


Using Excel To Read Points Script

‘Creates instance of the Excel com interop object which knows how to talk to the Excel components

Public Sub OpenExcel()
Dim objExcel
Dim objWorksheet1
Dim objWorksLastRow

Dim strFilePath = “C:\your path\Book1.xlsx”

objExcel = CreateObject(“Excel.Application”)
objExcel.Workbooks.open(strFilePath, False, True)
‘objExcel.Sheet1.Select()
objExcel.Visible = True
objWorksheet1 = objExcel.Worksheets(“TestSheet1″)
objWorksLastRow = objWorksheet1.UsedRange.Rows.Count
Dim objRangeName = objExcel.Range(“A1:A” & objWorksLastRow)

Dim strX, strY, strZ As String
Dim rangeCellX As Object
Dim rangeCellY As Object
Dim rangeCellZ As Object
For Each rangeCellX In objRangeName
If Trim(rangeCellX.Value) <> “” Then

‘Make cell the active cell

rangeCellX.Activate()
strX = rangeCellX.Value()
rangeCellY = rangeCellX.Offset(0, 1)
strY = rangeCellY.Value()
rangeCellZ = rangeCellX.Offset(0, 2)
strZ = rangeCellZ.Value()
‘Create Revit Point and Append to CurveArray’
XYZp = NewAutodesk.Revit.DB.XYZ(Convert.ToDouble(strX),Convert.ToDouble(strY), Convert.ToDouble(strZ))
‘CA.Append(XYZp)
End If
Next rangeCellX
objExcel.Quit()

End Sub

Rhino/SketchUp/Revit  Team

Veronica, Melvin

Excel points to Catia

‘make sure to load required libraries in Tools/ References:
”MecModInterfaces
”InfInterfaces
”PartInterfaces
”SpaceAnalysisInterfaces
”GEMKnowledgeInterfaces
”GSMInterfaces

”Have CATIA Part File open and active

Declare Public Variables

Dim my_catia As INFITF.Application
Dim my_doc As MECMOD.PartDocument
Dim my_part As MECMOD.Part
Dim my_fac As HybridShapeTypeLib.HybridShapeFactory
Dim my_SolFac As ShapeFactory
Dim my_Shapes As HybridShapes
Dim TheSPAWorkbench As Workbench
Dim TheMeasurable ‘As Measurable
Dim my_bodies As HybridBodies
Dim Body1 As HybridBody

Sub main()
OpenUp
Initialize
ReadWritePts

End Sub

Public Sub OpenUp()

Worksheets(“Sheet1″).Activate

End Sub

Initialize Catia:

Public Sub Initialize()
Set my_catia = GetObject(, “Catia.Application”)
Set my_doc = my_catia.ActiveDocument
Set my_part = my_doc.Part
Set my_fac = my_part.HybridShapeFactory
Set my_SolFac = my_part.ShapeFactory
Set TheSPAWorkbench = my_doc.GetWorkbench(“SPAWorkbench”)
Set my_bodies = my_part.HybridBodies

”create a geometrical set:
Set Body1 = my_bodies.Add
Body1.Name = “Set1″
my_part.Update
End Sub

Read Point coordinates from Excel:

Public Sub ReadWritePts()
Dim x, y, z As Double

Dim Rows As Integer
Rows = 20

Dim StartRow, i As Integer
StartRow = 12

Dim StartCol, j As Integer
StartCol = 1

i = StartRow
j = StartCol

Do While Cells(i, j) <> “”
Do While Cells(i, j) <> “”

x = Cells(i, j).Value
y = Cells(i + Rows + 1, j).Value
z = Cells(i + 2 * Rows + 2, j).Value * 100
i = i + 1

Create Point in CATIA document
Dim newPT As HybridShapePointCoord
Set newPT = my_fac.AddNewPointCoord(x, y, z)
newPT.Name = “ExcelPT_” & i – StartRow & “_” & j – StartCol + 1

Body1.AppendHybridShape newPT
Loop

i = StartRow
j = j + 1
Loop
my_part.Update
End Sub

Launching an .exe from VBA

I worked out another way to launch an .exe from a VBA script as opposed to the code Jonatan has posted here.

This method does not have any real error checking built in, but it is clean and to the point.

—————————————————————

Sub CATMain()

openMyApplication

End Sub

—————————————————————-

Sub openMyApplication()

Dim x As Variant
Dim Path As String

Path = “C:\Program Files (x86)\someFolder\Application.EXE”

‘ ‘///this is the path to your .exe

x = Shell(Path, vbNormalFocus)
End Sub

—————————————————————-

Just be sure to input the correct path to your application.  And again this does not have any error checking, but it works if you can be sure of the location/naming of the application you want to run.

-Matt

Catia>>Ecotect>>Radiance

We’ve made progress in sending analysis back from Radiance to Ecotect and back to Excel.   We are able to update the analysis grid that we initially established in Ecotect with the Lux values from the Radiance analysis and from there we can send the grid point data to and Excel spreadsheet in the same dimensions as the analysis grid (# of rows x # of columns).  From here we will create a rule in VBA that highlights any cells that exceed the Lux value criteria we are designing for.

Moving forward we will work on making the path from Ecotect to Excel more automated since much the current process is manual.

Useful links:

  • http://naturalfrequency.com/articles/radiancedf
  • http://radsite.lbl.gov/radiance/framer.html
  • http://www.bozzograo.net/radiancewiki/doku.php
  • http://radsite.lbl.gov/radiance/refer/ray.html#Scene

–Mike & Nick

launching Ecotect as an external application through VBA

''This will launch Ecotect (specify correct install directory)
Dim RetVal
RetVal = Shell("C:\Program Files (x86)\Autodesk\Ecotect 2009\ECOTECT.EXE", 1)

''___________________________________________________
''and this will only launch Ecotect, if it is not already running:
Set Service = GetObject("winmgmts:")

For Each Process In Service.InstancesOf("Win32_Process")
    If Process.Name = "Ecotect.exe" Then
        wscript.echo "Ecotect running"
        Stop
        wscript.Quit

    End If
Next
'wscript.echo "Ecotect not running"
Dim RetVal
RetVal = Shell("C:\Program Files (x86)\Autodesk\Ecotect 2009\ECOTECT.EXE", 1)
''___________________________________________________

I can’t remember where I found this, but I tested it for Ecotect, and it works fine. It will also work with other applications.

How to add posts with highlighted syntax

This site uses the syntax highlighter plugin from Alex Gorbatchev

Here is a list of supported syntax brushes. I also added a brush for Lua. Please let me know if you want me to add further brushes.

The advantage of using a highlighter is clear: Code that has been posted in this blog will look like this:

If a > b Then
    MsgBox "a > b"
ElseIf c > a
    MsgBox "c > a"
ElseIf b > c Then
    MsgBox "b > a"
Else
    MsgBox "Else"
End If

Rather than:

If a > b Then
MsgBox “a > b”
ElseIf c > a
MsgBox “c > a”
ElseIf b > c Then
MsgBox “b > a”
Else
MsgBox “Else”
End If