'Autodesk Revit plugin crashing
I am working on a plugin for Autodesk Revit 2014 converting room geometry to conceptual masses. But revit completely shuts down when i run the script. I've isolated the code that's causing the crash:
Extrusion m_Extrusion = m_FamDoc.FamilyCreate.NewExtrusion(true, m_CurveArArray, m_SketchPlane, 8);
And the revit logs show this error:
DBG_INFO: Detected unfrozen change of selection.: line 571 of n:\build\2014_ship_x64_inst_20130308_1515\source\revit\revitui\modscope\ModScope.cpp
Does anyone know if there is something wrong with my use of the extrusion command? Or is it something in Revit?
Thanks in advance.
Solution 1:[1]
It's strange to completely froze... it may be related to your code (before the NewExtrusion call)
In fact there is a complete sample around this method, see createSolid method (around line 170) at this file on github: https://github.com/ADN-DevTech/RevitTrainingMaterial/blob/master/Labs/3_Revit_Family_API/SourceCS/1_ColumnRectangle.cs :
// ==========================================
// (1) create a simple solid by extrusion
// ==========================================
Extrusion createSolid()
{
//
// (1) define a simple rectangular profile
//
// 3 2
// +---+
// | | d h = height
// +---+
// 0 1
// 4 w
//
CurveArrArray pProfile = createProfileRectangle();
//
// (2) create a sketch plane
//
// we need to know the template. If you look at the template (Metric Column.rft) and "Front" view,
// you will see "Reference Plane" at "Lower Ref. Level". We are going to create an extrusion there.
// findElement() is a helper function that find an element of the given type and name. see below.
//
ReferencePlane pRefPlane = findElement(typeof(ReferencePlane), "Reference Plane") as ReferencePlane;
//SketchPlane pSketchPlane = _doc.FamilyCreate.NewSketchPlane( pRefPlane.Plane ); // 2013
SketchPlane pSketchPlane = SketchPlane.Create( _doc, pRefPlane.Plane ); // 2014
// (3) height of the extrusion
//
// once again, you will need to know your template. unlike UI, the alightment will not adjust the geometry.
// You will need to have the exact location in order to set alignment.
// Here we hard code for simplicity. 4000 is the distance between Lower and Upper Ref. Level.
// as an exercise, try changing those values and see how it behaves.
//
double dHeight = mmToFeet(4000.0);
// (4) create an extrusion here. at this point. just an box, nothing else.
//
bool bIsSolid = true;
return _doc.FamilyCreate.NewExtrusion(bIsSolid, pProfile, pSketchPlane, dHeight);
}
Solution 2:[2]
did you create a transaction for this? something like: using (Transaction trans = new Transaction(doc, "Extrude")) { trans.Start(); Extrusion m_extrusion = m_FamDoc.FamilyCreate.NewExtrusion...... trans.Commit(); }
Solution 3:[3]
I had same problem in my code by define any kind of Array. By huge search after several week I find nothing but I realized that I used dot net framework version 5.0, when I changed it to dot net framework 4.8 everything got OK.
Solution 4:[4]
A. Not having created any extrusion code of my own, and B. Not understanding the larger context of what you're doing,
My best suggestion would be to check out the book Mastering Revit Architecture 2014. I'm looking at the 2013 book right now, and there's a section on the API (Chapter 25). In that chapter, they go in depth on an addin that takes rooms and generates masses. it looks to be exactly what you're looking for.
I just took a detour to look if the API reference is in the 2014 book, and it is not listed in the TOC, so you might be out of luck with that version (I can't imagine why they would eliminate it), but 2013 definitely does.
http://www.wiley.com/WileyCDA/WileyTitle/productCd-1118174089.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kmeixner |
| Solution 2 | mtumminello |
| Solution 3 | Farzin |
| Solution 4 | Ben Humphrey |
