PDA

View Full Version : Load Family Symbol



jdshanks
2006-03-14, 07:54 PM
Using VB.net 2.0 and Revit 9 demo.



Public Function Execute(ByVal commandData As Autodesk.Revit.ExternalCommandData, ByRef message As String, ByVal elements As Autodesk.Revit.ElementSet) As Autodesk.Revit.IExternalCommand.Result Implements Autodesk.Revit.IExternalCommand.Execute

Try

' hard coded family file

Dim fileName As String = "C:\Documents and Settings\All Users\Application Data\Autodesk\Revit Building 9\Imperial Library\Furniture\Bed-Bunk.rfa"

Dim symName As String = "82x36"

Dim str As String = "Loading Family Symbol: " & fileName & vbCr & symName

MsgBox(str)

If (LoadFamilySymbol(fileName, symName) = True) Then

MsgBox("Finaly loaded a stupid family!")

Return Revit.IExternalCommand.Result.Succeeded

End If

Catch ex As Exception

message = ex.Message

Return IExternalCommand.Result.Failed

End Try

End Function



The error I get on "LoadFamilySymol" is "Reference to a non-shared member requires an object reference." Yet the Revit API shows LoadFamilySymbol(String, String) As Boolean as a legit function. What am I doing wrong? Or is there a better way to do this? Thanks for any help.

I admit that I'm a code hack. I just find what works for someone else and change a few variables until it works for me (if it's a language I don't konw very well.)

jdshanks
2006-03-16, 07:58 PM
Follow up:

To use this function in 2.0, it now looks like this
note: I've only gotten load family to work; Still working on family symbol





If (commandData.Application.ActiveDocument.LoadFamily(fileName)) Then

jdshanks
2006-03-21, 06:19 PM
Yeah, so I've tried everything I can think of and can't get a family symbol to load in 2.0. Any ideas or code examples?

GuyR
2006-03-21, 11:55 PM
Just did a quick test. Same result, no go, seems to always fail? Would suggest posting this on the beta forum to see if you get a response.


public class command1 : IExternalCommand
{
public IExternalCommand.Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
{
Autodesk.Revit.Application application = cmdData.Application;
const string fName = "F:\\RevitContent\\V9\\Metric Library\\Furniture\\Chair 2.rfa";
const string sName = "430 mm dia";
if ((application.ActiveDocument.LoadFamilySymbol(fName, sName)))
{
MessageBox.Show("Yes the family loaded ");
return IExternalCommand.Result.Succeeded;
}
MessageBox.Show("Sorry can't load the family ");
return IExternalCommand.Result.Failed;
}
}