Revit二次开发之“创建尺寸标注”
生活随笔
收集整理的這篇文章主要介紹了
Revit二次开发之“创建尺寸标注”
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
運(yùn)行該命令,選中一個(gè)可標(biāo)注的對(duì)象,即實(shí)現(xiàn)標(biāo)注。 [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public?class?TestCommand?:?IExternalCommand
{
????public?Result?Execute(ExternalCommandData?commandData,?ref?string?message,?Autodesk.Revit.DB.ElementSet?elements)
????{
????????UIDocument?uiDoc?=?commandData.Application.ActiveUIDocument;
????????Autodesk.Revit.ApplicationServices.Application?app?=?commandData.Application.Application;
????????Document?doc?=?uiDoc.Document;
????????Autodesk.Revit.DB.View?view?=?doc.ActiveView;
????????ViewType?vt?=?view.ViewType;
????????if?(vt?==?ViewType.FloorPlan?||?vt?==?ViewType.Elevation)
????????{
????????????Reference?eRef?=?uiDoc.Selection.PickObject(ObjectType.Element,?"Please?pick?a?curve?based?element?like?wall.");
????????????if?(eRef?!=?null?&&?eRef.Element?!=?null)
????????????{
????????????????XYZ?dirVec?=?new?XYZ();
????????????????XYZ?viewNormal?=?view.ViewDirection;
????????????????LocationCurve?locCurve?=?eRef.Element.Location?as?LocationCurve;
????????????????if?(locCurve?==?null?||?locCurve.Curve?==?null)
????????????????{
????????????????????TaskDialog.Show("Prompt",?"Selected?element?isn’t?curve?based!");
????????????????????return?Result.Cancelled;
????????????????}
????????????????//?location?curve?needs?to?be?perpendicular?to?view?normal
????????????????XYZ?dirCur?=?locCurve.Curve.get_EndPoint(0).Subtract(locCurve.Curve.get_EndPoint(1)).Normalize();
????????????????double?d?=?dirCur.DotProduct(viewNormal);
????????????????if?(d?>?-0.000000001?&&?d?<?0.000000001)
????????????????{
????????????????????dirVec?=?dirCur.CrossProduct(viewNormal);
????????????????????XYZ?p1?=?locCurve.Curve.get_EndPoint(0);
????????????????????XYZ?p2?=?locCurve.Curve.get_EndPoint(1);
????????????????????XYZ?dirLine?=?XYZ.Zero.Add(p1);
????????????????????XYZ?newVec?=?XYZ.Zero.Add(dirVec);
????????????????????newVec?=?newVec.Normalize().Multiply(3);
????????????????????dirLine?=?dirLine.Subtract(p2);
????????????????????p1?=?p1.Add(newVec);
????????????????????p2?=?p2.Add(newVec);
????????????????????//?move?the?dimension?line?a?little?away?the?element’s?curve
????????????????????Line?newLine?=?app.Create.NewLine(p1,?p2,?true);
????????????????????ReferenceArray?arrRefs?=?new?ReferenceArray();
????????????????????Options?options?=?app.Create.NewGeometryOptions();
????????????????????options.ComputeReferences?=?true;
????????????????????options.DetailLevel?=?DetailLevels.Fine;
????????????????????GeometryElement?element?=?eRef.Element.get_Geometry(options);
????????????????????GeometryObjectArray?geoObjectArray?=?element.Objects;
????????????????????//enum?the?geometry?element
????????????????????for?(int?j?=?0;?j?<?geoObjectArray.Size;?j++)
????????????????????{
????????????????????????GeometryObject?geoObject?=?geoObjectArray.get_Item(j);
????????????????????????Solid?solid?=?geoObject?as?Solid;
????????????????????????if?(solid?==?null)
????????????????????????????continue;
????????????????????????FaceArrayIterator?fIt?=?solid.Faces.ForwardIterator();
????????????????????????while?(fIt.MoveNext())
????????????????????????{
????????????????????????????PlanarFace?p?=?fIt.Current?as?PlanarFace;
????????????????????????????if?(p?==?null)
????????????????????????????????continue;
????????????????????????????p2?=?p.Normal.CrossProduct(dirLine);
????????????????????????????if?(p2.IsZeroLength())
????????????????????????????{
????????????????????????????????arrRefs.Append(p.Reference);
????????????????????????????}
????????????????????????????if?(2?==?arrRefs.Size)
????????????????????????????{
????????????????????????????????break;
????????????????????????????}
????????????????????????}
????????????????????????if?(2?==?arrRefs.Size)
????????????????????????{
????????????????????????????break;
????????????????????????}
????????????????????}
????????????????????if?(arrRefs.Size?!=?2)
????????????????????{
????????????????????????TaskDialog.Show("Prompt",?"Couldn’t?find?enough?reference?for?creating?dimension");
????????????????????????return?Result.Cancelled;
????????????????????}
????????????????????Transaction?trans?=?new?Transaction(doc,?"create?dimension");
????????????????????trans.Start();
????????????????????doc.Create.NewDimension(doc.ActiveView,?newLine,?arrRefs);
????????????????????trans.Commit();
????????????????}
????????????????else
????????????????{
????????????????????TaskDialog.Show("Prompt",?"Selected?element?isn’t?curve?based!");
????????????????????return?Result.Cancelled;
????????????????}
????????????}
????????}
????????else
????????{
????????????TaskDialog.Show("Prompt",?"Only?support?Plan?View?or?Elevation?View");
????????}
????????return?Result.Succeeded;
????}
}from:http://revit.5d6d.com/thread-866-1-4.html 與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public?class?TestCommand?:?IExternalCommand
{
????public?Result?Execute(ExternalCommandData?commandData,?ref?string?message,?Autodesk.Revit.DB.ElementSet?elements)
????{
????????UIDocument?uiDoc?=?commandData.Application.ActiveUIDocument;
????????Autodesk.Revit.ApplicationServices.Application?app?=?commandData.Application.Application;
????????Document?doc?=?uiDoc.Document;
????????Autodesk.Revit.DB.View?view?=?doc.ActiveView;
????????ViewType?vt?=?view.ViewType;
????????if?(vt?==?ViewType.FloorPlan?||?vt?==?ViewType.Elevation)
????????{
????????????Reference?eRef?=?uiDoc.Selection.PickObject(ObjectType.Element,?"Please?pick?a?curve?based?element?like?wall.");
????????????if?(eRef?!=?null?&&?eRef.Element?!=?null)
????????????{
????????????????XYZ?dirVec?=?new?XYZ();
????????????????XYZ?viewNormal?=?view.ViewDirection;
????????????????LocationCurve?locCurve?=?eRef.Element.Location?as?LocationCurve;
????????????????if?(locCurve?==?null?||?locCurve.Curve?==?null)
????????????????{
????????????????????TaskDialog.Show("Prompt",?"Selected?element?isn’t?curve?based!");
????????????????????return?Result.Cancelled;
????????????????}
????????????????//?location?curve?needs?to?be?perpendicular?to?view?normal
????????????????XYZ?dirCur?=?locCurve.Curve.get_EndPoint(0).Subtract(locCurve.Curve.get_EndPoint(1)).Normalize();
????????????????double?d?=?dirCur.DotProduct(viewNormal);
????????????????if?(d?>?-0.000000001?&&?d?<?0.000000001)
????????????????{
????????????????????dirVec?=?dirCur.CrossProduct(viewNormal);
????????????????????XYZ?p1?=?locCurve.Curve.get_EndPoint(0);
????????????????????XYZ?p2?=?locCurve.Curve.get_EndPoint(1);
????????????????????XYZ?dirLine?=?XYZ.Zero.Add(p1);
????????????????????XYZ?newVec?=?XYZ.Zero.Add(dirVec);
????????????????????newVec?=?newVec.Normalize().Multiply(3);
????????????????????dirLine?=?dirLine.Subtract(p2);
????????????????????p1?=?p1.Add(newVec);
????????????????????p2?=?p2.Add(newVec);
????????????????????//?move?the?dimension?line?a?little?away?the?element’s?curve
????????????????????Line?newLine?=?app.Create.NewLine(p1,?p2,?true);
????????????????????ReferenceArray?arrRefs?=?new?ReferenceArray();
????????????????????Options?options?=?app.Create.NewGeometryOptions();
????????????????????options.ComputeReferences?=?true;
????????????????????options.DetailLevel?=?DetailLevels.Fine;
????????????????????GeometryElement?element?=?eRef.Element.get_Geometry(options);
????????????????????GeometryObjectArray?geoObjectArray?=?element.Objects;
????????????????????//enum?the?geometry?element
????????????????????for?(int?j?=?0;?j?<?geoObjectArray.Size;?j++)
????????????????????{
????????????????????????GeometryObject?geoObject?=?geoObjectArray.get_Item(j);
????????????????????????Solid?solid?=?geoObject?as?Solid;
????????????????????????if?(solid?==?null)
????????????????????????????continue;
????????????????????????FaceArrayIterator?fIt?=?solid.Faces.ForwardIterator();
????????????????????????while?(fIt.MoveNext())
????????????????????????{
????????????????????????????PlanarFace?p?=?fIt.Current?as?PlanarFace;
????????????????????????????if?(p?==?null)
????????????????????????????????continue;
????????????????????????????p2?=?p.Normal.CrossProduct(dirLine);
????????????????????????????if?(p2.IsZeroLength())
????????????????????????????{
????????????????????????????????arrRefs.Append(p.Reference);
????????????????????????????}
????????????????????????????if?(2?==?arrRefs.Size)
????????????????????????????{
????????????????????????????????break;
????????????????????????????}
????????????????????????}
????????????????????????if?(2?==?arrRefs.Size)
????????????????????????{
????????????????????????????break;
????????????????????????}
????????????????????}
????????????????????if?(arrRefs.Size?!=?2)
????????????????????{
????????????????????????TaskDialog.Show("Prompt",?"Couldn’t?find?enough?reference?for?creating?dimension");
????????????????????????return?Result.Cancelled;
????????????????????}
????????????????????Transaction?trans?=?new?Transaction(doc,?"create?dimension");
????????????????????trans.Start();
????????????????????doc.Create.NewDimension(doc.ActiveView,?newLine,?arrRefs);
????????????????????trans.Commit();
????????????????}
????????????????else
????????????????{
????????????????????TaskDialog.Show("Prompt",?"Selected?element?isn’t?curve?based!");
????????????????????return?Result.Cancelled;
????????????????}
????????????}
????????}
????????else
????????{
????????????TaskDialog.Show("Prompt",?"Only?support?Plan?View?or?Elevation?View");
????????}
????????return?Result.Succeeded;
????}
}from:http://revit.5d6d.com/thread-866-1-4.html 與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖
總結(jié)
以上是生活随笔為你收集整理的Revit二次开发之“创建尺寸标注”的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 出现“cannot identify i
- 下一篇: Linux系统:centos7下搭建Ro