Place Family Instance from .csv files points

Place Family Instance from .csv files points

Anonymous
Not applicable
1,259 Views
5 Replies
Message 1 of 6

Place Family Instance from .csv files points

Anonymous
Not applicable

Hi,

   I want to place Family Instance which I select from active document on points which get from csv file. I use this code which is from following link but it showing the error.

 

http://thebuildingcoder.typepad.com/blog/2012/02/add-reference-points-from-csv-file.html

 

 

This is the code:-

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
using (Transaction t = new Transaction(doc, "csv"))
{
t.Start();

string filepath = "E:\\Points.csv";

if (File.Exists(filepath))
{
StreamReader s = new StreamReader(
filepath);
TaskDialog.Show("Revit","Read csv File");

//
Reference pickrdRef = null;

//pick a group

Selection sel = uiapp.ActiveUIDocument.Selection;
pickrdRef = sel.PickObject(ObjectType.Element, "Please select a group");
TaskDialog.Show("Revit", "Select Your Marker");

while (-1 != s.Peek())
{
string line = s.ReadLine();

string[] data = line.Split(
new char[] { ',' });

XYZ p = app.Create.NewXYZ(
double.Parse(data[0]),
double.Parse(data[1]),
double.Parse(data[2]));

ReferencePoint rp = doc.FamilyCreate.NewReferencePoint(p);
}
}
else
{
TaskDialog.Show("Revit","Files Does not Exists");
}

t.Commit();
}

return Result.Succeeded;
}

0 Likes
Accepted solutions (1)
1,260 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Accepted solution

Use NewFamilyInstance() for placing family instance on points.

0 Likes
Message 3 of 6

jeremytammik
Autodesk
Autodesk

For a complete and tested example add-in implementing this, please refer to The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/2013/10/text-file-driven-automatic-placement-of-family-inst...



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

0 Likes
Message 4 of 6

Anonymous
Not applicable

I have downloaded the add-in, but we are unable to place the family automatically at the given coordinates.

I have given coordinates in text file in following format.

x

y

z

Can you please give solution for this.

If possible can you share one example text file.

 

Thanks

Libna

0 Likes
Message 5 of 6

jeremytammik
Autodesk
Autodesk

As far as I can tell from the code, it expects two or three real numbers per text line for XY or XYZ coordinates.

 

Try feeding it the data in the following format:

 

 

  X1 Y1 Z1
  X2 Y2 Z2
  ...

 

Why don't you just debug it and see what is going on?

 

Cheers,

 

Jeremy

 



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

0 Likes
Message 6 of 6

Anonymous
Not applicable

Now I am working in visual studio 2017 express, so that I am not able to debug external programs. I have raised request in my organisation for installing professional version in my system. Once installed I will debug the code.

 

Thanks for your replay.

0 Likes