Dimension is not created in the view from south and north when wall is inclined in floor plan.

Dimension is not created in the view from south and north when wall is inclined in floor plan.

munhtushig0806
Explorer Explorer
136 Views
0 Replies
Message 1 of 1

Dimension is not created in the view from south and north when wall is inclined in floor plan.

munhtushig0806
Explorer
Explorer

Hi, My name is Munkhtushig. I have written the command to create dimensions of walls automatically. It creates dimensions in the view from north and south when a wall is placed horizontally in floor plan. But, when wall is inclined, command generates error that ' The direction of dimension is invalid'. Here are the screenshots you can see imagination and code I wrote below. I will greatly appreciate if you share your thoughts on how to solve this problem. Feel free to ask anything. Thank you very much.  

 

namespace firsttab
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;

// Access current selection

Selection sel = uidoc.Selection;

// Retrieve elements from database

FilteredElementCollector col
= new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.OfCategory(BuiltInCategory.INVALID)
.OfClass(typeof(Wall));

// Filtered element collector is iterable

foreach (Element e in col)
{
Debug.Print(e.Name);
}

// Modify document within a transaction
using (Transaction tx = new Transaction(doc))
{
tx.Start("Transaction Name");
foreach(Element e in col)
{
DimensionLine(doc ,e ,20);
}
tx.Commit();
}
return Result.Succeeded;
}

private void DimensionLine(Document doc, Element wall, double dist)
{
Line Dimline = null;
ReferenceArray reference = null;
Wall wall1 = wall as Wall;

if (wall1 != null)
{
Dimline = CalcDimLine(doc.ActiveView, wall1, dist);
reference = SearchLine(wall1);
Dimension dimension = doc.Create.NewDimension(doc.ActiveView, Dimline, reference);
}
}

private Line CalcDimLine(View view, Wall wall1, double dist)
{
Line DLine = null;
LocationCurve walllocation = wall1.Location as LocationCurve;


XYZ SP = walllocation.Curve.GetEndPoint(0);
XYZ EP = walllocation.Curve.GetEndPoint(1);

GeoPoint gSP = new GeoPoint(SP);
GeoPoint gEP = new GeoPoint(EP);


GeoVector vecWall = new GeoVector();
vecWall.SetByPointToPoint(gSP, gEP);


GeoVector vecView = new GeoVector();
XYZ nView = view.ViewDirection;
vecView.SetRevitPoint(nView);


GeoVector vecCross = new GeoVector();
vecCross = vecWall.GetOuterProduct(vecView);

double angle = vecWall.GetAngleTo(vecView, mdlGeoModule.GeoVector_ZAxis());
if (angle < 0.0D)
{
vecCross.Negate();
}

 

GeoVector uvecDist = vecCross.GetNormal();
GeoVector vecDist = uvecDist.GetMultipled(dist);

GeoPoint DS = gSP.GetMoved(vecDist);
GeoPoint DE = gEP.GetMoved(vecDist);

DLine = Line.CreateBound(DS.GetRevitPoint(), DE.GetRevitPoint());
return DLine;
}

private ReferenceArray SearchLine(Wall wall1)
{
ReferenceArray frontbackrefs = new ReferenceArray();

LocationCurve wallLocation = wall1.Location as LocationCurve;

XYZ SP = wallLocation.Curve.GetEndPoint(0);
XYZ EP = wallLocation.Curve.GetEndPoint(1);

GeoPoint gSP = new GeoPoint(SP);
GeoPoint gEP = new GeoPoint(EP);

GeoCurve curWall = new GeoCurve();
curWall.SetLine(gSP, gEP);

Options options = new Options();
options.ComputeReferences = true;
options.DetailLevel = ViewDetailLevel.Fine;
options.IncludeNonVisibleObjects = false;
GeometryElement ge = wall1.get_Geometry(options).GetTransformed(Transform.Identity);

List<Edge> edges = new List<Edge>();
foreach(GeometryObject go in ge)
{
Solid solid = go as Solid;
if (solid != null && solid.Edges.Size > 0 && solid.Faces.Size > 0)
{
foreach(Edge edge in solid.Edges)
{
Curve cur = edge.AsCurve();
GeoVector geoCurVec = new GeoVector();
geoCurVec.SetByCurve(new GeoCurve(cur as Line));
edges.Add(edge);
}
}
}

GeoPointArray gpa=new GeoPointArray();

foreach(Edge edge in edges)
{
Curve curve = edge.AsCurve();
GeoCurve geoCurve = new GeoCurve(curve as Line);
GeoPoint midPoints = geoCurve.GetMiddlePoint();
gpa.Append(midPoints);
}

IntegerArray lineIDs = gpa.SortByDistAlongLine(curWall);

Reference frontref = edges[(int)lineIDs.Front].Reference;
Reference backref = edges[(int)lineIDs.Back].Reference;

frontbackrefs.Append(frontref);
frontbackrefs.Append(backref);


return frontbackrefs;
}

}
}

 

 

1a) a wall is placed horizontally.

1a.png

1b) dimension is created when wall is horizontal

1b) Dimension is created when wall is placed horizontally1b) Dimension is created when wall is placed horizontally

 

2a) Wall is inclined. 

2a) wall is inclined2a) wall is inclined

0 Likes
137 Views
0 Replies
Replies (0)