Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Unable to stretch with the grip a fabricarea done with the API in GUI without editing the sketch

antoine_ferron
Explorer

Unable to stretch with the grip a fabricarea done with the API in GUI without editing the sketch

antoine_ferron
Explorer
Explorer

Hi all,

I have a small issue when I want to create a fabricarea with the API.

The curves of the sketch are not detected as joined so I can't stretch it with the grip I have the error message the loop is not closed. I tried many stuffs without any success 

Find a simple example below with a 2 feet square from the hit point of the selected floor

 

thanks for your help

            // Comon statements
            UIApplication uiApp = commandData.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            Document doc = uiDoc.Document;
            
            
            Reference reference;

            try
            {
                reference = uiDoc.Selection.PickObject(ObjectType.Element, new CatSelectionFilter(BuiltInCategory.OST_Floors, doc));
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Autodesk.Revit.UI.Result.Cancelled;
            }

           
            XYZ xyz = reference.GlobalPoint;
            XYZ xyz0 = new XYZ(xyz.X, xyz.Y, 0);
            Floor floor = doc.GetElement(reference) as Floor;

            CurveLoop curveLoop = new CurveLoop();

            Line curve1 = Line.CreateBound(xyz0, xyz0 + new XYZ(0, 2, 0));
            curveLoop.Append(curve1);
            Line curve2 = Line.CreateBound(xyz0 + new XYZ(0, 2, 0), xyz0 + new XYZ(2, 2, 0));
            curveLoop.Append(curve2);
            Line curve3 = Line.CreateBound(xyz0 + new XYZ(2, 2, 0), xyz0 + new XYZ(2, 0, 0));
            curveLoop.Append(curve3);
            Line curve4 = Line.CreateBound(xyz0 + new XYZ(2, 0, 0), xyz0);
            curveLoop.Append(curve4);

            IList<CurveLoop> loop = new List<CurveLoop>();
            loop.Add(curveLoop);

            IList<FabricAreaType> listOfFabricAreaType = new FilteredElementCollector(doc)
                    .OfClass(typeof(FabricAreaType)).Cast<FabricAreaType>()
                    .ToList();

            IList<Element> listOfFabricSheetType = new FilteredElementCollector(doc)
                          .OfClass(typeof(FabricSheetType))
                          .ToList();


            FabricArea fabricarea;
            using (Transaction ts = new Transaction(doc, "create fabricsheetarea"))
            {
                ts.Start();
                fabricarea = FabricArea.Create(doc, floor, loop, XYZ.BasisY, xyz0, listOfFabricAreaType.First().Id, listOfFabricSheetType.First().Id);
                ts.Commit();
            }

            return Result.Succeeded;

 

0 Likes
Reply
417 Views
5 Replies
Replies (5)

jeremy_tammik
Autodesk
Autodesk

Sounds strange. The loop looks good to me. Have you tried creating the same fabric area manually in the UI and analysing its properties? Do they exactly match the properties that you are trying to feed into the API? For instance, maybe the Z coordinate is different? 

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

antoine_ferron
Explorer
Explorer

Hi Jeremy,
Thank you for your time.
I have already check the Z coordinate, I checked also with 2 new modelcurves with the same coordonate and no problem they are correctly automatically joined and can be stretched in the UI.
I also compared an "hand made" fabricaera and this one done by the API. The only difference I found is the fact that the BoundaryCurves created are not joined to each other. You can see it with the following code. I tried the method SetGeometryCurve after the creation of the fabricarea without more success.
You can make them joined after in the UI by editing the sketch and "Re-snap" the end cuvre, then the fabricArea can be stretched.
Do I miss something ?

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

            try
            {
                reference = uiDoc.Selection.PickObject(ObjectType.Element, new CatSelectionFilter2(BuiltInCategory.OST_Floors));
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return Autodesk.Revit.UI.Result.Cancelled;
            }

            XYZ xyz = reference.GlobalPoint;
            XYZ xyz0 = new XYZ(xyz.X, xyz.Y, 0);
            Floor floor = doc.GetElement(reference) as Floor;

            CurveLoop curveLoop = new CurveLoop();
            XYZ xyz1 = xyz0;
            XYZ xyz2 = xyz0 + new XYZ(0, 2, 0);
            XYZ xyz3 = xyz0 + new XYZ(2, 2, 0);
            XYZ xyz4 = xyz0 + new XYZ(2, 0, 0);

            Line curve1 = Line.CreateBound(xyz1, xyz2);
            Line curve2 = Line.CreateBound(xyz2, xyz3);
            Line curve3 = Line.CreateBound(xyz3, xyz4);
            Line curve4 = Line.CreateBound(xyz4, xyz1);

            curveLoop.Append(curve1);
            curveLoop.Append(curve2);
            curveLoop.Append(curve3);
            curveLoop.Append(curve4);
            IList<CurveLoop> loop = new List<CurveLoop>();
            loop.Add(curveLoop);

            IList<FabricAreaType> listOfFabricAreaType = new FilteredElementCollector(doc)
                    .OfClass(typeof(FabricAreaType)).Cast<FabricAreaType>()
                    .ToList();

            IList<Element> listOfFabricSheetType = new FilteredElementCollector(doc)
                          .OfClass(typeof(FabricSheetType))
                          .ToList();
            
            FabricArea fabricarea;
            ModelCurve ml1;
            ModelCurve ml2;
            
            using (Transaction ts = new Transaction(doc, "create fabricsheetarea"))
            {
                ts.Start();
                fabricarea = FabricArea.Create(doc, floor, loop, XYZ.BasisY, xyz0, listOfFabricAreaType.First().Id, listOfFabricSheetType.First().Id);
                Sketch sketch = doc.GetElement(fabricarea.SketchId) as Sketch;
                ml1 = doc.Create.NewModelCurve(curve1, sketch.SketchPlane);
                ml2 = doc.Create.NewModelCurve(curve2, sketch.SketchPlane);
                ts.Commit();
            }

            MessageBox.Show((string.Format("The element id {0} is joined to the elemnt id {1} ", ml1.Id.ToString(), ml1.GetAdjoinedCurveElements(1).First().ToString())));
            
            IList<ElementId> listId = fabricarea.GetBoundaryCurveIds();
           
            {
                foreach (ElementId elementId in listId)
                {
                    ModelLine modelLine = doc.GetElement(elementId) as ModelLine;
                    using (Transaction ts = new Transaction(doc, "create fabricsheetarea"))
                    {
                        ts.Start();
                        modelLine.SetGeometryCurve(modelLine.GeometryCurve, true);
                        ts.Commit();
                    }
                    if (modelLine.GetAdjoinedCurveElements(0).Count != 0)
                    { 
                        MessageBox.Show(string.Format("The element id {0} is joined to the elemnt id {1} ",elementId.ToString(), modelLine.GetAdjoinedCurveElements(0).First().ToString())); 
                    }
                    else
                    { 
                        MessageBox.Show(string.Format("No joined element found for element id {0}", elementId.ToString())); 
                    }
                }
            }
            return Result.Succeeded;
        }
    }
    public class CatSelectionFilter2 : ISelectionFilter
    {
        private BuiltInCategory bc;

        public CatSelectionFilter2(BuiltInCategory builtInCategory)
        {
            bc = builtInCategory;
        }
        public bool AllowElement(Element element)
        {
            if (element.Category.BuiltInCategory == bc) return true;
            return false;
        }

        public bool AllowReference(Reference refer, XYZ point)
        {
            return false;
        }

    }

 

0 Likes

antoine_ferron
Explorer
Explorer

Hi Jeremy,

I investigated a bit more yesterday and I don't see a solution. So I wonder if it is not a limitation or an issue of the method FabricArea.Create which not manage adjoined curves. Any Idea ?

0 Likes

jeremy_tammik
Autodesk
Autodesk

Hmm. Generally, the UI functionality should be achievable programmatically as well. I passed on the question to the development team for their take on things.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

jeremy_tammik
Autodesk
Autodesk

I heard back from the development team on this; they say it is a known limitation tracked by the issue REVIT-141145

Please make a note of this number for future reference.

  

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

  

This issue is important to me. What can I do to help? This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

   

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

   

This information is crucial. Our engineering team has limited resources and must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes