Hi,
I am creating an application that needs to create dimension for height of a form. I read Building coders blog and the forum posts and used the sample in SDK folder (Window Wizard). I was able to manage everything well but the following error:
The direction of dimension is invalid.
I tried a lot to solve this issue, but I could not find the solution. Two other peoplehad the same problem in the blog but there is no answer for their questions.I would appreciate if you could help me. Here is the related part of the code:
//The from is created with extrusion command
FaceArray faces =newFaceArray();
if (form.IsSolid)
{
Options options =newOptions();
options.ComputeReferences =true;
IEnumerator<GeometryObject> Objects = form.get_Geometry(options).GetEnumerator();
while (Objects.MoveNext())
{
GeometryObject geoObj = Objects.Current;
if (geoObjisSolid)
{
Solid s = geoObjasSolid;
foreach (Face fcin s.Faces)
{
//Gets the top and bottom face of the form
if (Math.Round((fc.ComputeNormal(newUV(0, 0))).Z) == 1 ||Math.Round((fc.ComputeNormal(newUV(0, 0))).Z) == -1)
{
faces.Append(fc);
}
}
//Here is the line with the error*************************
windowInsetDimension = AddDimension(FamDoc, view3d, faces.get_Item(0), faces.get_Item(1));
}
}
}
publicDimension AddDimension(Document doc, Autodesk.Revit.DB.View3D view,Face face1,Face face2)
{
Dimension dim;
Autodesk.Revit.DB.XYZ startPoint =new Autodesk.Revit.DB.XYZ();
Autodesk.Revit.DB.XYZ endPoint =new Autodesk.Revit.DB.XYZ();
Line line;
Reference ref1;
Reference ref2;
ReferenceArray refArray =newReferenceArray();
PlanarFace pFace1 = face1asPlanarFace;
ref1 = pFace1.Reference;
PlanarFace pFace2 = face2asPlanarFace;
ref2 = pFace2.Reference;
if (null != ref1 &&null != ref2)
{
refArray.Append(ref1);
refArray.Append(ref2);
}
startPoint = pFace1.Origin;
endPoint =new Autodesk.Revit.DB.XYZ(startPoint.X, startPoint.Y, pFace2.Origin.Z);
SubTransaction subTransaction =newSubTransaction(doc);
subTransaction.Start();
line =Line.CreateBound(startPoint, endPoint);
dim = doc.FamilyCreate.NewDimension(view, line, refArray);
subTransaction.Commit();
return dim;
}
Thanks,
Dear Mohammad,
Thank you for your query.
I had some issues rebuilding your project which proved surmountable.
I first tried to use the current version of the clipper library, clipper_ver6.1.3a.zip.
That no longer defines the AddPolygons method, but AddPaths instead.
I then reverted back to a version I had used previously, clipper_ver5.1.6.zip.
That does not yet define the StrictlySimple property.
After commenting out that in your code I was able to compile.
I tried running it, and encountered the error System.ArgumentException: "Could not find the path!"
That was due to your implementation of the familyTemplateAddress method, which only provides support for the imperial library.
I only have the metric library installed, and added support for that, albeit rather rough.
I was then able to reproduce the error that you run into:
The direction of dimension is invalid. A transaction or sub-transaction was opened but not closed in document 'Family2'. All uncommitted changes to this document made by External Command will be discarded.'
Looking at the name of the view, I see "RayTracer View", created by your method createView3d using the .CreateIsometric method.
Try adding a dimension to that view in the user interface and see what happens 🙂
As far as I know, adding dimensioning requires a 2D view, and the dimensioning must lie in the view plane.
I would therefore suggest that you seach for or create a suitable such view, presumably an elevation view, and use that to create the dimensioning.
Some samples are available on the net:
http://lmgtfy.com/?q=revit+api+NewDimension
I hope this helps.
After commenting out the dimensioning method, the command completes for me:
I do not see any buildings generated, however:
I very much like your sample as far as I currently understand it and would love to publish a description of it on the blog once it is up and running in all its glory, if you are happy with that.
Thank you!
I attached my version of your code to this message in DataToBim.zip with the small changes mentioned above. Please see if you can use that for your future enhancements, so the changes are not lost. Thanks again!
Best regards,
Jeremy
Hi Jeremy,
Jeremy,
I found this post on your website:
Section View Creation
http://thebuildingcoder.typepad.com/blog/2011/07/section-view-creation.html
The doc.Create.NewViewSection(..) method in API 2014 is replaced by an static member of ViewSection class. I guess viewSection is what we need to use. Is that true?
Jeremy,
The problem is solved. A new family document has a list of views which could be collected using a FilteredElementCollector and filtered to find views of type elevation (ViewType.Elevation). We even did not need to generate new views.
How can I send the revised code here?
I appreciate your help!
Saied.
Dear Saied,
I am very glad to hear that you solved it.
The approach searching for an existing elevation view and adding the dimensioning to that sounds perfect, as long as you do not care specifically which view it is added to.
Yes, you would use the static ViewSection.CreateSection method nowadays instead of NewViewSection. Here are4 some samples of using that:
I finally got around to testing this now.
I published the working add-in on GitHub:
https://github.com/jeremytammik/DataToBimCountoursAndBuildings
I also migrated it to Revit 2015, while I was at it.
Thank you for sharing this interesting sample!
Cheers,
Jeremy
To round this off, a summary of this discussion is now published on The Building Coder:
Enjoy!