Can't load family type (about import of .rcp file)

Can't load family type (about import of .rcp file)

Anonymous
Not applicable
1,115 Views
3 Replies
Message 1 of 4

Can't load family type (about import of .rcp file)

Anonymous
Not applicable

Hi to all, i want create an add-in. In this add-in i must import a Points of Clouds. I know how to do with Revit (there is the button on "insert" menu, and after i must click on "3d View" for see my .rcp files on Revit) but i want to do with API. So..this is my code :

 

public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiApp.Application;
Document doc = uiDoc.Document;

Transaction trans = new Transaction(doc, "ExComm");
trans.Start();

// Get the Revit library path as defined via the Options dialog - File Locations tab - Places button
string libraryPath = "";

app.GetLibraryPaths().TryGetValue("Imperial Library", out libraryPath);

if (String.IsNullOrEmpty(libraryPath))
{
libraryPath = "c:\\"; // If not have, use a default path.
}


// Allow the user to select a family file.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = libraryPath;
openFileDialog1.Filter = "Family Files (*.rcp)|*.rcp";

// Load the family file using LoadFamily method and then give information.
if (DialogResult.OK == openFileDialog1.ShowDialog())
{
try
{
Autodesk.Revit.DB.Family family = null;
if (doc.LoadFamily(openFileDialog1.FileName, out family))
{
String name = family.Name;
TaskDialog.Show("Revit", "Family file has been loaded. Its name is " + name);
}
else
{
TaskDialog.Show("Revit", "Can't load the family file.");
}
}
catch (Exception ex)
{
TaskDialog.Show("Revit", ex.Message);
}
}

trans.Commit();

return Result.Succeeded;

}

 

But doc.LoadFamily always go on the else. What's i wrang? Sorry but i'm new on Revit Api World.

 

Thanks in advance

 

Nicola

0 Likes
Accepted solutions (1)
1,116 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Nicola,

 

LoadFamily loads a family definition file with the filename extension RFA.

 

A point cloud is not a family definition.

 

To create a point cloud instance, use the PointCloudInstance Create method:

 

http://www.revitapidocs.com/2018.1/d348f6b8-75b5-dc11-821f-927d575d83f8.htm

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 4

Anonymous
Not applicable
 
Thanks Jeremy, I lacked the knowledge of the correct object to use. Now my .rcp file is loaded, but it is not displayed. How can I activate the 3D View via API? I found your post on this topic: "http://thebuildingcoder.typepad.com/blog/2011/09/activate-a-3d-view.html"

but in my case it did not work. Probably I'm using a wrong object again, because the object to return in "View3D view = Get3dView(doc);" is null, do you know where I can look to activate the 3D view in my case?
 
I used exactly your method after creating the point cloud instance.
 
            if (DialogResult.OK == openFileDialog1.ShowDialog())
            {
                try
                {
                    PointCloudType type = PointCloudType.Create(doc, "rcp", openFileDialog1.FileName);
                    PointCloudInstance.Create(doc, type.Id, Transform.Identity);

                    View3D view = Get3dView(doc);

                    if (null == view)
                    {
                        TaskDialog.Show("Revit", "Sorry, no suitable 3D view found");

                        return Result.Failed;
                    }
                    else
                    {
                        // Must set view before starting the transaction,
                        // otherwise an exception is thrown saying 
                        // "Cannot change the active view of a modifiable 
                        // document (with a transaction currently open)."

                        uiDoc.ActiveView = view;

                        // Must start a transaction in order to set the 
                        // parameters on the view:

                        Transaction t = new Transaction(doc);
                        t.Start("Change to 3D view");

                        view.get_Parameter(BuiltInParameter
                          .VIEW_DETAIL_LEVEL).Set(3);

                        view.get_Parameter(BuiltInParameter
                          .MODEL_GRAPHICS_STYLE).Set(6);

                        t.Commit();

                        TaskDialog.Show("Revit", "3d view actived");

                        return Result.Succeeded;
                    }
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("Revit", ex.Message);
                }
            }

            

            return Result.Succeeded;
 
 
 
0 Likes
Message 4 of 4

Anonymous
Not applicable
0 Likes