Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating Height Dimension for Form

7 REPLIES 7
Reply
Message 1 of 8
mra1242
1490 Views, 7 Replies

Creating Height Dimension for Form

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,

Mohammad Rahmnai Asl

7 REPLIES 7
Message 2 of 8
jeremytammik
in reply to: mra1242

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:

report.png


I do not see any buildings generated, however:

 

topography_surface.png

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



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

Message 3 of 8
zarrinmehr
in reply to: mra1242

Hi Jeremy,

 
I appreciate your attention and the time that you spent on the issue which Mohammad reported. Although I have never contacted you but I have read every single post of your blog. I owe you a lot. Let me know when you come over College Station, Texas to take you out to a restaurant 🙂 
 
Since you have spent quite a bit of time reading and trying to understand our code you might be curious to have an overview of the application. I am the main developer of an application in Revit that reads ArcGIS shape files and automatically creates a BIM model that contains GIS tabular information in the form of Revit parameters. Developing this application is only possible in Revit 2014 in which the API library includes constructors for SiteSubRegion and BuildingPaDType. This application is part of a research project in which the user interface also conducts queries in Revit to search, find and visualize building masses based on their parameter values. The UI also automates the creation of facades on the faces of a mass. The project is at its final steps. 
 
My colleague, Mohammad, was working to connect the parameters to control the geometry of the mass. Since Mohammad and I were working on the same class "DataToBuilding.cs" we made some mistakes. The "ray tracer" view was created on the main project document to find the elevation of the building (which is not usually available in GIS). In this view rays will be shot vertically from the corners of the building footprint; the closet distances will be measured, and the average distances will be calculated to find the elevation of the building on the topography. Then we will create a new mass family and locate it on the topography. Here is where we used the address of the template family using imperial folder. We will create the new "Conceptual Mass" families in Revit API and that is where the issues are raised.
 
It is easy to create a new family document and create new extrusions using Revit API library. The corners of building footprints that are retrieved from GIS data are set according to the north american datum and the numbers might be big double values. As a result when you create a new extrusion in a mass family that is generated with API, the extrusion is very likely be placed far from the default visible range of the default view of a family. You can nonetheless load these families in the project and see their preview on the project browser when you want to place an instance of these families! Creating new dimensions also has the same view issue. A family document that is created by API does not have active view and manipulating the view properties to expand the range of visibility seems to be impossible maybe because there is not any view at all. I could solve the problem of family visibility by translating the building footprint to the canter of the family datum, creating the extrusion, saving the family, loading the family into the project file and finally translating the family back in its original location. This strategy worked to solve the problem of viewing the geometry of the family; however, it cannot be applied to take care of the dimension issue. Like many other geometric elements, dimensions in Revit are also view-dependent. 
 
I can summarize our problem in this way, "how could we create a 2D elevation view in a family that was generated by Revit API?" 
 
Thanks again for your attention. I would be happy to provide more detailed explanation of the application for your blog when the development is completed.
 
PS: In the previous model you can activate the visibility of masses to see the buildings. Our results will look like the attached image which is part of Texas A&M main campus. the clipper library was used to perform polygon boolean operations. We also worked with a couple of other external libraries but when simplifying the application to send it to you we forgot to remove the clipper library.

 Texas A&M Campus.PNG

Message 4 of 8
zarrinmehr
in reply to: mra1242

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?

Message 5 of 8
zarrinmehr
in reply to: mra1242

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.

Message 6 of 8
jeremytammik
in reply to: zarrinmehr

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:


To submit the revised code, you could simply zip up all the revised code, including the Visual Studio project, solution and addin manifest, and attach that to this thread.

I will happily give it a run and post it on The Building Coder for future reference as an full-fledged easy-to-read self-contained discussion.

Thank you!

Cheers,

Jeremy



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

Message 7 of 8
jeremytammik
in reply to: jeremytammik

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



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

Message 8 of 8
jeremytammik
in reply to: jeremytammik

To round this off, a summary of this discussion is now published on The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/2014/11/creating-topography-contours-and-building-masses.ht...

 

Enjoy!



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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community