hi,
I'm trying to deal with a pcg file, which is a 3D point cloud format in Revit.
This is what I want to do.
1. get each point in a point cloud
2. change the value of some parts in a point cloud.
In short, it seems that I acquire values of each point, but editing them doesn't seem to work.
Below is the code,
so if have any idea, please help me.
I'm struggling with it. T_T
p,s also, the bounding box of point cloud gets null !!!! why???!!
------------------------------------------
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;
////////////////////////////////////////////////////////////////////////
Transaction tr = new Transaction(doc, "FailureMessage Posting");
tr.Start();
try
{
PointCloudType type = PointCloudType.Create(doc, "pcg", @"d:\\test.pcg");
PointCloudInstance pcInstance = PointCloudInstance.Create(doc, type.Id, Transform.Identity);
if (doc != null)
{
BoundingBoxXYZ boundingBox = pcInstance.get_BoundingBox(null);
if (boundingBox != null)
{
;
}
else
{
boundingBox = new BoundingBoxXYZ();
boundingBox.Min = new XYZ(-999999999, -999999999, -999999999);
boundingBox.Max = new XYZ(999999999, 99999999, 99999999);
List<Plane> planes = new List<Plane>();
planes.Add(app.Create.NewPlane(XYZ.BasisX, boundingBox.Min));
planes.Add(app.Create.NewPlane(-XYZ.BasisX, boundingBox.Max));
planes.Add(app.Create.NewPlane(XYZ.BasisY, boundingBox.Min));
planes.Add(app.Create.NewPlane(-XYZ.BasisY, boundingBox.Max));
planes.Add(app.Create.NewPlane(XYZ.BasisZ, boundingBox.Min));
planes.Add(app.Create.NewPlane(-XYZ.BasisZ, boundingBox.Max));
PointCloudFilter filter = PointCloudFilterFactory.CreateMultiPlaneFilter(planes);
pcInstance.FilterAction = SelectionFilterAction.Highlight;
PointCollection points = pcInstance.GetPoints(filter, 100000);
System.Windows.Forms.MessageBox.Show(points.Count.ToString());
unsafe
{
CloudPoint* pointBuffer = (CloudPoint*)points.GetPointBufferPointer().ToPointer();
int totalCount = points.Count;
for (int numberOfPoints = 0; numberOfPoints < totalCount; numberOfPoints++)
{
CloudPoint point = *(pointBuffer + numberOfPoints);
System.Drawing.Color color = System.Drawing.ColorTranslator.FromWin32(point.Color);
String pointDescription = String.Format("({0}, {1}, {2}, {3}",
point.X, point.Y, point.Z, color.ToString());
(*(pointBuffer + numberOfPoints)).X = 0;
(*(pointBuffer + numberOfPoints)).Y = 0;
(*(pointBuffer + numberOfPoints)).Z = 0;
(*(pointBuffer + numberOfPoints)).Color = 0;
(*(pointBuffer + numberOfPoints)) = new CloudPoint(0, 0, 0, 0);
}
}
}
}
tr.Commit();
try
{
;// XYZ midpoint = (boundingBox.Min + boundingBox.Max) / 2.0;
}
catch (Exception ex)
{
message = ex.Message;
return Autodesk.Revit.UI.Result.Failed;
}
}
catch (Exception ex)
{
message = ex.Message;
return Autodesk.Revit.UI.Result.Failed;
}
return Result.Succeeded;
}
------------------------------------------
Hi,
About the get BoundingBox, can you quick try Regenerate the document before? Changes on geometry do not take effect until the end of command, unless with a call to this method.