Error on familyDocument NewExtrusion method

Error on familyDocument NewExtrusion method

Anonymous
Not applicable
1,103 Views
8 Replies
Message 1 of 9

Error on familyDocument NewExtrusion method

Anonymous
Not applicable

Hello,

 

I'm trying to insert geometry (mass) into my project, by making a family, creating the extrusions, and then inserting it into the project. But for some reason I can't make the extrusion. Whenever it tries to, I get this error (which isn't all too helpfull):

Screenshot_1.png

 

Do any of you know what I'm doing wrong?

 

public void CreateFamily()
        {
            //TODO: Family conceptual template option
            string templateFileName = "C:\\ProgramData\\Autodesk\\RVT 2019\\Family Templates\\English\\Conceptual Mass\\Metric Mass.rft";

            Autodesk.Revit.DB.Document familyDocument = RevitDocument.Application.NewFamilyDocument(templateFileName);

            if (null == familyDocument)
            {
                return;
            }
            Transaction transaction = new Transaction(familyDocument, "Create Enveo family");
transaction.Start();
CreateMass(familyDocument); transaction.Commit(); SaveAsOptions opt = new SaveAsOptions(); opt.OverwriteExistingFile = true; string fileName = Path.Combine(Path.GetTempPath(), "EnveoOmgeving"); familyDocument.SaveAs(fileName, opt); familyDocument.Close(false); } public void CreateMass(Autodesk.Revit.DB.Document familyDocument) { FamilyItemFactory factory = familyDocument.FamilyCreate; //Application creapp = RevitDocument.Application.Create; SketchPlane sketch = FindElementByTypeAndName(familyDocument, typeof(SketchPlane), "Level 1") as SketchPlane; foreach (var bagMember in BagObjects) { for (int i = 0; i < bagMember.PolyLines.Size; i++) { try { factory.NewExtrusion(true, bagMember.PolyLines, sketch, bagMember.BuildingHeight); } catch (Exception exp) { TaskDialog.Show("ERROR", exp.Message); } } } } /// <summary> /// Return the first element found of the /// specific target type with the given name. /// </summary> Element FindElementByTypeAndName(Autodesk.Revit.DB.Document doc, Type targetType, string targetName) { var test = new FilteredElementCollector(doc) .OfClass(targetType).First<Element>(e => e.Name.Equals(targetName)); return test; }

 

0 Likes
Accepted solutions (1)
1,104 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Please step though your code in the debugger line by line to determine exactly which statement is throwing the exception, and what exact exception is being thrown. Thank you!

 



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

0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi Jeremy,

 

The line of the code that's throwing the exception is this one:Screenshot_2.pngScreenshot_3.png

But the exception isn't really telling me much.

 

 

 

0 Likes
Message 4 of 9

stever66
Advisor
Advisor

Can you verify that all your variables are holding the values you expect?  Is buildingheight a non-zero value?  Is the size greater than 0?

 

 

Also, it might be better to start with a single extrusion instead of wrapping it inside a foreach and another for loop.  That makes it hard to figure out what is going on.  Start simple and add to it.

 

I'm not sure your try-catch isn't getting this error?  It makes me think it might be something with the loops.

0 Likes
Message 5 of 9

jeremytammik
Autodesk
Autodesk

Here are suggestions on how to debug this:

 

http://thebuildingcoder.typepad.com/blog/2009/07/debug-geometric-form-creation.html

 

Create model curves representing the input to the extrusion creation method and use those manually in the user interface to receive more detailed information on what is causing the problem.

 



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

0 Likes
Message 6 of 9

Anonymous
Not applicable

It seems that they are all correct? I've changed the code a bit, so it only creates an extrusion from the first BagObject.

It has a height. The 

 

Screenshot_3.jpg

 

 

But what might be an issue is the following:

Screenshot_4.jpg

 

It doesn't stop my program, but it does seem to give some kind of error when creating the family document?

0 Likes
Message 7 of 9

Anonymous
Not applicable

Hi Jeremy,

 

I just tested my data by creating modelcurves in my Revit Document and creating in-place mass from those modelcurves. This seems to be working fine. Before trying to make a family in the background, I also succeeded in creating mass with DirectShape. So I think the data is fine.

 

 public void CreateMass(Autodesk.Revit.DB.Document familyDocument)
        {
            FamilyItemFactory factory = familyDocument.FamilyCreate;

            //Application creapp = RevitDocument.Application.Create;

            SketchPlane sketch = FindElementByTypeAndName(RevitDocument, typeof(SketchPlane), "Level 1") as SketchPlane;

            View view = FindElementByTypeAndName(RevitDocument, typeof(View), "Level 1") as View;

            foreach (var test in BagObjects)
            {
                for (int i = 0; i < test.PolyLines.get_Item(0).Size; i++)
                {
                    RevitDocument.Create.NewModelCurve(test.PolyLines.get_Item(0).get_Item(i) as Curve, sketch);
                }
            }
}

 

Screenshot_5.jpg

 

0 Likes
Message 8 of 9

FAIR59
Advisor
Advisor
Accepted solution

You are using the wrong method for creation. In the "Mass environment" you need to use the Document.FamilyCreate.NewExtrusionForm() method. The result is an instance of the Form-class.

 

The method you're using is for the "normal" familydocuments (Windows, Doors etc) , and results in an instance of the Extrusion-class.  

0 Likes
Message 9 of 9

Anonymous
Not applicable

Hi FAIR59,

 

You mean because I'm using the Conceptual Mass family template?

 

I am going to try this tonight. Will keep you updated!

0 Likes