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

Icons (resources) in Sharp Develop

I’ve finally figured out how to get icons into my SharpDevelop grasshopper components. I had been struggling to understand this tutorial http://wiki.sharpdevelop.net/UsingResources.ashx, but I think I’ve got a good understanding of how to make it work (dont yet know exactly why). So far I got it to work with a bitmap. Not sure if there will be any changes to be made with other image file types.

1. First add a reference to System.Drawing (this is what allows you to add images)

2. Add a resource fill by clicking Projects > Add > New Item and select Misc > Empty Resource File

3. Go to your new empty resource file and right click in on one of the blank cells and select “Add Files” and then add your files in the browser

4. Go to the properties of your resource file in the project tree select “ResXFileCodeGenerator” for Custom Tool

5. Right click on your resource file and select “Execute Custom Tool” (this generates a designer.vb file which does all the hard work for you)

6. For the Propery Internal_Icon, Return a reference to the image with the Name of the resource file and the name of the image uploaded to the resource file. Intellisense should pop up on this one for both the name of the resource file and the name of the image.

Protected Overrides ReadOnly Property Internal_Icon_24x24 As system.drawing.bitmap
Get
Return ResourceFileName.BitmapFileName
End Get
End Property

 

Have fun with those icons.

Ben S

 

Open Dialog Box

The tool Sap_2_Rs asks the User (to the Revit Structure environment) to open the Sap2000 file that he wishes to import the geometry.

This happens by calling the OpenFileDialog box:

‘ Configure open file dialog box

Dim dlg As New Microsoft.Win32.OpenFileDialog()

dlg.FileName = “Select Sap model to import”   ‘ Default file name

dlg.DefaultExt = “.sdb”    ‘ Default file extension

dlg.Filter = “SAP MODEL Files (.sdb)|*.sdb”   ‘ Filter files by extension

‘ Show open file dialog box

Dim result? As Boolean = dlg.ShowDialog()

Dim filename As String = dlg.FileName

If result =  True  Then

‘start the Sap2000 application

SapObject.ApplicationStart()

ret = SapModel.InitializeNewModel             ‘initialize model

ret = SapModel.File.OpenFile(filename)     ‘open specific file

End If

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

Don’t forget to add the “PresentationFramework” reference (type.NET)

Sharp Develop vs. GH

Has anyone found a trick to getting Sharp Develop to show intellisence all the time when you are working on the GH components? I’ve been getting really odd behavior where it will show up for one line, but not the next one. Really perplexing… I’d really prefer to not switch to Visual Studio but if that’s the only way to get consistent performance…

Revit API and SDK files

The Revit SDK file has really useful files in order to get started, scripting with Revit API… This is a video found from autodesk that quickly presents the SDK file  http://download.autodesk.com/us/firstplugin/revit/exploring_the_revit_sdk_1044x828.html

You can download the Revit SDK file from Autodesk website

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

as long as you have an activated Autodesk account…

So between these files the Revit API is included and also a pdf called “Revit 20xx API Developer Guide”  which has many useful details for a new programmer in Revit

creating elements in REVIT VSTA (beams, columns, braces and so forth…) – variables needed

here is a list of variables needed in order to create members in Revit VSTA. I this this might be useful to whoever is new to VSTA…I’d see it as a kind of guide, just to make sure you are not skipping any fundamental variable…

you’ll find how to put togheter all these variables and how to draw a member in VSTA in these following 2 posts:

creating elements in REVIT VSTA (beams, columns, braces and so forth…) – loading path

creating elements in REVIT VSTA (beams, columns, braces and so forth…) – define start and end point and draw member

 

           ‘VARIABLES
                Dim beam_sym As Autodesk.Revit.DB.FamilySymbol = Nothing
                Dim instance As Autodesk.Revit.DB.FamilyInstance = Nothing
                Dim myBeam As Autodesk.Revit.DB.Line = Nothing
                Dim start_point As Autodesk.Revit.DB.XYZ = Nothing
                Dim end_point As Autodesk.Revit.DB.XYZ = Nothing
                Dim my_level As Autodesk.Revit.DB.Level

creating elements in REVIT VSTA (beams, columns, braces and so forth…) – loading path

critical in the process of creating beams or columns or whatever element in Revit VSTA is the load path that stores all the family…it was tricky for me to find it so I’m uploading here the general path that is more or less the same for everyone!

In this example I’m loading metric but you can use Imperial as well…just MAKE SURE that the name of the element you are considering (beam in this case) is the exact same name of the one in the family (“300 x 600mm” in this example)…you can double check this easly by opening Revit and read the names in the family tab!

HAVE FUN CREATING MEMBERS!

 

 ’Loading the family symbol for beams from family located on the C drive
                Dim loaded As Boolean
                loaded = myModel.LoadFamilySymbol(“C:\ProgramData\Autodesk\RST 2011\Metric Library\Structural\Framing\Concrete\M_Concrete-Rectangular Beam.rfa”, “300 x 600mm”, beam_sym)

Hydrostatics in Grasshopper

I have been working on a Hydrostatics calculator in Grasshopper, written entirely in VB.net. This node will serve to replace the hydrostatics calculations done using Maxsurf or Orca (two naval architecture software programs that are exceedingly expensive). The idea is to input a hull surface with the Rhino WorldXY plane as the waterplane. The node then intersects the hull surface with the waterplane and generates the hydrostatics values required for basic stability estimates of the input hull. It is almost done and the values found with my calculator are within 1% of those found by Maxsurf’s calculator.

The next steps I plan on taking is locking down the VB.net node so that it is not editable, and publishing this component to the Grasshopper page for public use. Writing this node has been a great way to learn how to interact with Rhino and GH and use both programs’ commands and functions to accomplish my goals. Perhaps to make it interoperable I could write in a function to make the results output to an organized Excel sheet?

Get Catia Coordinates

I am currently working on relaying geometric coordinates from a wireframe in Catia to VB.NET to a text file. In order to do this my first step is to get the XYZ coordinates of each point of my wireframe geometry in Catia and store it in a variable in VB.NET. Utilizing some code I found in a forum discussion I was able to select a point in Catia and get its coordinates into a VB.NET variable. However, reading the XYZ’s of multiple points in a polyline has proven to be a much more difficult challenge for me. After scouring through the deep rooted trees of classes, objects, properties, and methods in the Catia Automation Help I have come up with a very roundabout yet workable VB.NET solution.

Using the GetElements sub method of HybridShapePolyline I am able to return an arrray of the elements (points) of the polyline. The difficult part was figure out how to store each element into a point instance so that I could use the Point sub method GetCoordinates to return the XYZ’s of each point.

The GetCoordinates constructor asks for “oCoordinates as Array”.  The first road bump was figuring out that that the “o” before “Coordinates” stands for output (as opposed to when there is an “i” for input), thus the constructor should be passed an array to store the values that are returned by GetCoordinates. It seems pretty simple now, but this was the first Method I had used that asked for an output object in the constructor and it took me an hour or so to come to the above realization.

The GetElements sub method of HybridShapePolyline resulted in another deep exploration through the Catia Automation Help. At first I attempted to plug the elements returned by GetElements directly into GetCoordinates to no avail. After some debugging I found that GetElements does not return a point, but rather it returns a reference to a point, thus I could not run a Point sub method such as GetCoordinates.

So here’s where my code got a little clunky. In order to turn the references to points into actual points, I searched for a Point object that could somehow reference the reference to the point to create a point with identical coordinates. Using the HybridShapeFactory sub method AddNewPointCoordWithReference I was able to reference the reference to the point and offset it by 0,0,0. VB.NET is then able to run GetCoordinates on my new Point that references the reference to the point on the polyline for which I am attempting to get coordinates. A bit roundabout, but it was a satisfying feat at the time. I am sure Jonatan and Ben will be able to cut the fat on this code and leave it at 2 or 3 lines.

 

The code:

‘cycle through each element (point) of the HybridShapePolyline
For i As Integer = 1 To myWireFrame.NumberOfElements

‘create ptXYZ array to hold xyz coordinates of point
Dim ptXYZ(2) As Object

‘set items of ptXYZ to equal XYZ coordinates of myPoint
Dim myWireFrameElement As Reference ’= Nothing

‘get reference to points of selected wireframe
myWireFrame.GetElement(i, myWireFrameElement, Nothing)

‘create point object offset 0,0,0 from reference to point on polyline
wireFramePoint = myHSFactory.AddNewPointCoordWithReference(0,0,0,myWireFrameElement)

‘create physical point in Catia for debugging purposes
myCoordHybridBody.AppendHybridShape(wireFramePoint)

myPart.Update

‘assign point coordinates to ptXYZ array
wireFramePoint.GetCoordinates(ptXYZ)

‘convert units from mm to feet
Dim xft As Double = ptXYZ(0)*0.0032808399
Math.Round(xft,2)
Dim yft As Double = ptXYZ(1)*0.0032808399
Math.Round(yft,2)
Dim zft As Double = ptXYZ(2)*0.0032808399
Math.Round(zft,2)

‘debug
Console.Writeline(“X= “ & xft & ” Y= “ & yft & ” Z= “ & zft)

Next i