ContainsPoint Problem!

ContainsPoint Problem!

nam_vt
Enthusiast Enthusiast
848 Views
1 Reply
Message 1 of 2

ContainsPoint Problem!

nam_vt
Enthusiast
Enthusiast

Hi there!

- I have to use containsPoint(point) to check a point that constaint by a CurveLoop. I had debug and see that true but containsPoint method always return false. Can somebody help me.? this is my source and family I use to check.

 

 

 [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class ExportGeometryInfoToCSV : Autodesk.Revit.UI.IExternalCommand
    {
        public object SiteEditingUtils { get; private set; }

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

            Selection choices = uiDoc.Selection;

            // Pick one object from Revit.
            Reference hasPickOne = choices.PickObject(ObjectType.Element);

            if (hasPickOne == null)
            {
                return Result.Succeeded;
            }

            Element element = uiDoc.Document.GetElement(hasPickOne);
            if (element is FamilyInstance)
            {
                double width = 0.0;
                double height = 0.0;
                ElementType type = doc.GetElement(element.GetTypeId()) as ElementType;
                Parameter paramWidth = type.LookupParameter("Width");
                if (paramWidth != null)
                {
                    width = paramWidth.AsDouble();
                }
                Parameter paramHeight = type.LookupParameter("Height");
                if (paramHeight != null)
                {
                    height = paramHeight.AsDouble();
                }

                FamilyInstance familyInstance = element as FamilyInstance;
                Family family = familyInstance.Symbol.Family;
                Document familyDoc = doc.EditFamily(family);
                if (null != familyDoc && familyDoc.IsFamilyDocument == true)
                {
                    using (Transaction trans = new Transaction(familyDoc, "Add Type to Family"))
                    {
                        trans.Start();

                        FamilyManager familyManager = familyDoc.FamilyManager;

                        string text = string.Empty;
                        foreach (FamilyParameter familyParam in familyManager.Parameters)
                        {
                            text += familyParam.Definition.Name + "\n";

                            if (string.Compare(familyParam.Definition.Name, "Width") == 0)
                            {
                                familyManager.Set(familyParam, width);
                            }
                            if (string.Compare(familyParam.Definition.Name, "Height") == 0)
                            {
                                familyManager.Set(familyParam, height);
                            }
                        }
                        trans.Commit();
                    }
                    FilteredElementCollector collector = new FilteredElementCollector(familyDoc);
                    ICollection<Element> collection = collector.OfClass(typeof(GenericForm)).ToElements();

                    StringBuilder csv = new StringBuilder();
                   
                    foreach (Element elem in collection)
                    {
                        if (elem is Extrusion)
                        {
                            Extrusion extrusion = elem as Extrusion;
                            if (extrusion.Name == "Void Extrusion")
                            {
                                continue;
                            }
                            Plane plan = extrusion.Sketch.SketchPlane.GetPlane();                           
                            CurveArrArray curveArrArray = extrusion.Sketch.Profile;
                             
                            try
                            {                             
                                FindBoun(curveArrArray, doc);  
                            } 
                            catch (System.Exception ex)
                            {
                                System.Windows.Forms.MessageBox.Show(ex.Message + "\n" + ex.StackTrace.ToString());
                                 return Result.Succeeded;
                            }                            
                        }
                    }        
                }
            }            
            return Result.Succeeded;
        }
   
        bool FindBoun(CurveArrArray curveArrArray, Autodesk.Revit.DB.Document doc)
        {            
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            collector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_Columns);                               
            List<XYZ> points = new List<XYZ>();

            foreach (CurveArray curveArr in curveArrArray)
            {
                foreach (Curve curve in curveArr)
                {
                    XYZ startpoint = curve.GetEndPoint(0);
                    points.Add(startpoint);
                }
            }

                foreach (CurveArray curveArr in curveArrArray)
            {  
                List<Curve> curves = new List<Curve>();
                
                foreach (Curve curve in curveArr)
                {                    
                    curves.Add(curve);                                     
                }

                using (Transaction acTrans = new Transaction(doc, "TempSkecth"))
                {
                    acTrans.Start();
                    TopographySurface topography = TopographySurface.Create(doc, points);
                    CurveLoop curveLoop = CurveLoop.Create(curves);
                    List<CurveLoop> curveLoops = new List<CurveLoop>();
                    curveLoops.Add(curveLoop);
                    XYZ origin = new XYZ(0,0,0);
                    SiteSubRegion region = SiteSubRegion.Create(doc, curveLoops, topography.Id);

                    if (true == region.TopographySurface.ContainsPoint(origin))
                    {
                        System.Windows.Forms.MessageBox.Show("in");
                    }

                    else
                    {
                        System.Windows.Forms.MessageBox.Show("out");
                    }

                    acTrans.Commit();
                }
               
            } 
            return true; 
        }        
    }

 

0 Likes
Accepted solutions (1)
849 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Nam,

 

Thank you for your query.

 

`ContainsPoint` tells you whether the given point 'exists in the topography surface':

 

http://www.revitapidocs.com/2018.1/d0e5a2f0-eb77-4efb-91f2-ce5428b53ab1.htm

 

That presumably means that the point is one of the topography surface defining points.

 

It sounds to me as if you are looking for a different kind of containment, e.g., whether the given point lies inside the extents of the topography surface.

 

That is a different thing entirely.

 

I do not believe that the topography surface offers this functionality.

 

You will probably be better off implementing it yourself, for instance by making use of a simple point in polygon algorithm or 2D Boolean operation library:

 

 

I hope this helps.

 

Best regards,

 

Jeremy



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