Building Coder (Revit Secondary Development)-create dimensions between two lines

Source: Internet
Author: User

How to Create a dimension is a frequently asked question. I recently spent some time researching and finding a solution to correct a related error in RevitLookup.

Problem

I tried to create detailed drawings programmatically, especially using the ItemFactoryBase. NewDimension () method. I draw a Detail Line in the sketch view based on the geometric characteristics of the wall element, and then want to insert the relevant size. But the question is, how can I obtain a Reference object for the NewDimension () method that belongs to the Reference?

Jeremy

I suggest that you first study the following materials when you encounter the problem of Revit secondary development:
The Revit API help document (RevitAPI. chm)
The Revit API Development Guide (PDF version is not available at The beginning of 2013 and can only be viewed in Autodesk WikiHelp)
Note: I personally think the 2012 version is enough. The Revit API has greatly changed from 2011 to 2012, but it has not changed much from 2012 to 2013.
The Revit SDK routine
In fact, I did the same. The results show that there are related implementations in RevitLookup:

[Csharp]
XYZ location1 = GeomUtils. kOrigin;
XYZ location2 = new XYZ (20.0, 0.0, 0.0 );
XYZ location3 = new XYZ (0.0, 20.0, 0.0 );
XYZ location4 = new XYZ (20.0, 20.0, 0.0 );
 
Curve curve1 = m_revitApp.Application.Create.NewLine (location1, location2, true );
Curve curve2 = m_revitApp.Application.Create.NewLine (location3, location4, true );
 
DetailCurve dCurve1 = null;
DetailCurve dCurve2 = null;
 
If (! Doc. IsFamilyDocument)
{
DCurve1 = doc. Create. NewDetailCurve (doc. ActiveView, curve1 );
DCurve2 = doc. Create. NewDetailCurve (doc. ActiveView, curve2 );
}
Else
{
// Only Detail-based family documents can create a Detail Curve (Detail Curve)
If (null! = Doc. OwnerFamily
& Null! = Doc. OwnerFamily. FamilyCategory)
{
If (! Doc. OwnerFamily. FamilyCategory. Name. Contains ("Detail "))
{
MessageBox. Show (
"Please make sure you open a detail based family template .",
"RevitLookup", MessageBoxButtons. OK,
MessageBoxIcon. Information );
 
Return;
}
}
DCurve1 = doc. FamilyCreate. NewDetailCurve (doc. ActiveView, curve1 );
DCurve2 = doc. FamilyCreate. NewDetailCurve (doc. ActiveView, curve2 );
}
 
Line line = m_revitApp.Application.Create.NewLine (location2, location4, true );
 
ReferenceArray refArray = new ReferenceArray ();
 
RefArray. Append (dCurve1.GeometryCurve. Reference );
RefArray. Append (dCurve2.GeometryCurve. Reference );
 
If (! Doc. IsFamilyDocument)
{
Doc. Create. NewDimension (doc. ActiveView, line, refArray );
}
Else
{
Doc. FamilyCreate. NewDimension (doc. ActiveView, line, refArray );
}

You can use Add-Ins> Revit Lookup> Test Framework...> Object Hierarchy> APIObject> Element> Dimension to call the DimensionHardWired external command. It implements the above Code. However, RevitLookup has a small BUG: no transaction is added for the above Code. Therefore, you need to add the following code to the periphery of the above Code to run correctly:


[Csharp]
Using (Transaction tx = new Transaction (doc ))
{
Tx. Start ("DimensionHardWired ");
......
Tx. Commit ();
}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.