Hi,
there is a code sample in the comments section of this TBC posting:
Revitalizer
I know create section view.
I want to know : how to create elevation view?
ViewSection.CreateSection(m_doc, ViewId, box);
ViewId is "ViewFamily.Elevation"
but catch say : The viewFamilyType must be a Section ViewFamily!
Hi,
in the comment I mentioned it says:
<cite>
ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, viewFamilyTypes.First().Id, xyz, elevationScale);
//create 4 internal elevations for on each marker index
for (int i = 0; i < 4; i++)
{
ViewSection elevationView =
marker.CreateElevation(doc, floorView.Id, i);
</cite>
So obviously you need to create an ElevationMarker first.
Then you create a ViewSection for at least one of its slots.
Revitalizer
Thanks!
hi,
create is OK!
But another question :
How to set view direction and deep?
I try to rotate marker, but it does not work.
ElementTransformUtils.RotateElement(m_doc, marker.Id, lineBase, dAng);
Hi,
for the rotation, see here:
For the section's view depth, it depends on the view's BoudingBox, see the posting i mentioned in my first reply:
(There, depth is defined by the sample wall's thickness.)
Revitalizer
ViewSection.CreateSection( doc, vft.Id, sectionBox );
BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();
sectionBox.Transform = t; //Dir
sectionBox.Min = min; //DEEP AND Widht
sectionBox.Max = max;
CreateSection is OK! I can set direction and deep.
But, Elevation view I can not set sectionBox infomation.
marker.CreateElevation(m_doc, m_doc.ActiveView.Id, idx);
where is box?
I have box infomation.
No set box by create function.
Hi,
Revitalizer
Yes , I modify
sv.CropBox = newBox;
cropBox trasform BasisX is always : 1,0,0
but, after Commit(), cropBox value is changed.
My question is same to grahamcook's question.
How can I set cropBox ?
2017 is OK
viewRet.CropBox = sectionBox;
2016 is does not work!!
2017 can set.
But, the dir is wrong!
for example:
sectionBox.Transform.BasisX = 0, -1, 0;
sectionBox.Transform..BasisY = 0, 0, 1;
sectionBox.Transform..BasisZ = -1, 0, 0;
after Commit();
CropBox.Transform is changed:
CropBox.Transform.BasisX = -0.707, -0.707, 0;
CropBox.Transform..BasisY = 0, 0, 1;
CropBox.Transform..BasisZ = -0.707, 0.707, 0;
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class WallViewCmd : IExternalCommand
{
public Autodesk.Revit.DB.Document m_doc;
public Autodesk.Revit.UI.Result Execute(ExternalCommandData cmdData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
UIApplication uiapp = cmdData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
m_doc = uidoc.Document;
// Retrieve wall from selection set
Wall wall = null;
try
{
Reference selected = uidoc.Selection.PickObject(ObjectType.Element, "Pick Wall:");
Element elemPick = m_doc.GetElement(selected.ElementId);
wall = elemPick as Wall;
if (wall == null)
return Result.Succeeded;
}
catch (System.Exception)
{
return Result.Succeeded;
}
LocationCurve lc = wall.Location as LocationCurve;
Line line = lc.Curve as Line;
if (null == line)
{
message = "Unable to retrieve wall location line.";
return Result.Failed;
}
ViewFamilyType vft = new FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
.Cast<ViewFamilyType>()
.FirstOrDefault<ViewFamilyType>(x =>
ViewFamily.Elevation == x.ViewFamily);
// Determine section box
ViewSection viewRet = null;
BoundingBoxXYZ sectionBox = GetSectionViewParallelToWall(wall);
using (Transaction tx = new Transaction(doc))
{
tx.Start("Create Wall Section View");
// ViewSection.CreateSection(doc, vft.Id, sectionBox); //ok
XYZ ptMid = line.Evaluate(0.5, true);
XYZ vtNew = Tools.RotateBy(line.Direction, XYZ.BasisZ, Math.PI / 2.0);
XYZ ptLoc = ptMid + vtNew * Metric.ToRvt(1000, m_doc);
int idx = 1;
double dAng = XYZ.BasisX.AngleOnPlaneTo(vtNew, XYZ.BasisZ);
if (dAng < Math.PI)
idx = 3;
ElevationMarker marker = ElevationMarker.CreateElevationMarker(m_doc, vft.Id, ptLoc, 100);
viewRet = marker.CreateElevation(m_doc, m_doc.ActiveView.Id, idx);
viewRet.CropBox = sectionBox; //Only 2017
tx.Commit();
}
return Result.Succeeded;
}
BoundingBoxXYZ GetSectionViewParallelToWall(Wall wall)
{
LocationCurve lc = wall.Location
as LocationCurve;
Curve curve = lc.Curve;
// view direction sectionBox.Transform.BasisZ
// up direction sectionBox.Transform.BasisY
// right hand is computed so that (right, up, view direction) form a left handed coordinate system.
// crop region projections of BoundingBoxXYZ.Min and BoundingBoxXYZ.Max onto the view cut plane
// far clip distance difference of the z-coordinates of BoundingBoxXYZ.Min and BoundingBoxXYZ.Max
XYZ p = curve.GetEndPoint(0);
XYZ q = curve.GetEndPoint(1);
XYZ v = q - p;
BoundingBoxXYZ bb = wall.get_BoundingBox(null);
double minZ = bb.Min.Z;
double maxZ = bb.Max.Z;
double w = v.GetLength();
double h = maxZ - minZ;
double d = wall.WallType.Width;
double offset = 0.1 * w;
XYZ min = new XYZ(-w, minZ - offset, -offset);
//XYZ max = new XYZ( w, maxZ + offset, 0 ); // section view dotted line in center of wall
XYZ max = new XYZ(w, maxZ + offset, offset); // section view dotted line offset from center of wall
XYZ midpoint = p + 0.5 * v;
XYZ walldir = v.Normalize();
XYZ up = XYZ.BasisZ;
XYZ viewdir = walldir.CrossProduct(up);
Transform t = Transform.Identity;
t.Origin = midpoint;
t.BasisX = walldir;
t.BasisY = up;
t.BasisZ = viewdir;
BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();
sectionBox.Transform = t;
sectionBox.Min = min;
sectionBox.Max = max;
return sectionBox;
}
}