How to create Elevation View ?

How to create Elevation View ?

Anonymous
Not applicable
4,541 Views
14 Replies
Message 1 of 15

How to create Elevation View ?

Anonymous
Not applicable

How to create Elevation View ?

0 Likes
4,542 Views
14 Replies
Replies (14)
Message 2 of 15

Revitalizer
Advisor
Advisor

Hi,

 

there is a code sample in the comments section of this TBC posting:

http://thebuildingcoder.typepad.com/blog/2012/06/create-section-view-parallel-to-wall.html?cid=6a00e...

 

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 15

Anonymous
Not applicable

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!

Message 4 of 15

Revitalizer
Advisor
Advisor

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




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 5 of 15

Anonymous
Not applicable

Thanks!

0 Likes
Message 6 of 15

Anonymous
Not applicable

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);

0 Likes
Message 7 of 15

Revitalizer
Advisor
Advisor

Hi,

 

for the rotation, see here:

https://forums.autodesk.com/t5/revit-api-forum/elevationmarker-not-rotating/m-p/7114473/highlight/tr...

 

For the section's view depth, it depends on the view's BoudingBox, see the posting i mentioned in my first reply:

 

http://thebuildingcoder.typepad.com/blog/2012/06/create-section-view-parallel-to-wall.html?cid=6a00e...

(There, depth is defined by the sample wall's thickness.)

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 8 of 15

Anonymous
Not applicable
 

 

 

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? 

0 Likes
Message 9 of 15

Anonymous
Not applicable

 

I have box infomation. 

 

No set box  by  create function.

 

0 Likes
Message 10 of 15

Revitalizer
Advisor
Advisor
0 Likes
Message 11 of 15

Anonymous
Not applicable

 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 ?

0 Likes
Message 12 of 15

Anonymous
Not applicable

2017 is OK

0 Likes
Message 13 of 15

Anonymous
Not applicable

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;

0 Likes
Message 14 of 15

Anonymous
Not applicable

[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;
}
}

Message 15 of 15

ianmotabr
Contributor
Contributor

One review: at index now we can determine what's the elevation orientation.

 

 

0 Likes