Misoriented Detail in SectionView

Misoriented Detail in SectionView

bahaaeldien.metwaly
Contributor Contributor
555 Views
3 Replies
Message 1 of 4

Misoriented Detail in SectionView

bahaaeldien.metwaly
Contributor
Contributor

Hi,

 

I'm creating a number of sections programmatically to represent "Door Views".

The code will look for doors of specific type, collect the location and orientation, and then generate the BoundingBox and sectionView. No any issues so far.

Now I want to place detail families in these section views, first test : some detail families are rotated 180degrees.

from plan view all I could recognize is that these doors are facing Y Axis. but how can I programmatically expect a certain section to have a wrongly oriented detail ?

Below is the data I could collect, sec 1 & 4 are having the issue.

 

-> SEC-01

Transform.BasisX = [(1.000000000, 0.000000000, 0.000000000)]

Transform.BasisY = [(0.000000000, 0.000000000, 1.000000000)]

Transform.BasisZ = [(0.000000000, -1.000000000, 0.000000000)]

Min = [(-4.757217848, -1.476377953, -1.968503937)]

Max = [(4.757217848, 8.464566929, 0.656167979)]

Detail Hand = [(1.000000000, 0.000000000, 0.000000000)]

Detail Facing = [(0.000000000, 1.000000000, 0.000000000)]

 

-> SEC-02

Transform.BasisX = [(0.000000000, 1.000000000, 0.000000000)]

Transform.BasisY = [(0.000000000, 0.000000000, 1.000000000)]

Transform.BasisZ = [(1.000000000, 0.000000000, 0.000000000)]

Min = [(-4.494750656, -1.476377953, -1.968503937)]

Max = [(4.494750656, 9.120734908, 0.656167979)]

Detail Hand = [(1.000000000, 0.000000000, 0.000000000)]

Detail Facing = [(0.000000000, 1.000000000, 0.000000000)]

 

 

-> SEC-03

Transform.BasisX = [(0.000000000, 1.000000000, 0.000000000)]

Transform.BasisY = [(0.000000000, 0.000000000, 1.000000000)]

Transform.BasisZ = [(1.000000000, 0.000000000, 0.000000000)]

Min = [(-4.494750656, -1.476377953, -1.968503937)]

Max = [(4.494750656, 9.120734908, 0.656167979)]

Detail Hand = [(1.000000000, 0.000000000, 0.000000000)]

Detail Facing = [(0.000000000, 1.000000000, 0.000000000)]

 

-> SEC-04

Transform.BasisX = [(1.000000000, 0.000000000, 0.000000000)]

Transform.BasisY = [(0.000000000, 0.000000000, 1.000000000)]

Transform.BasisZ = [(0.000000000, -1.000000000, 0.000000000)]

Min = [(-4.757217848, -1.476377953, -1.968503937)]

Max = [(4.757217848, 8.464566929, 0.656167979)]

Detail Hand = [(1.000000000, 0.000000000, 0.000000000)]

Detail Facing = [(0.000000000, 1.000000000, 0.000000000)]

 

 

-> SEC-05

Transform.BasisX = [(0.000000000, 1.000000000, 0.000000000)]

Transform.BasisY = [(0.000000000, 0.000000000, 1.000000000)]

Transform.BasisZ = [(1.000000000, 0.000000000, 0.000000000)]

Min = [(-4.494750656, -1.476377953, -2.460629921)]

Max = [(4.494750656, 9.120734908, 0.656167979)]

Detail Hand = [(1.000000000, 0.000000000, 0.000000000)]

Detail Facing = [(0.000000000, 1.000000000, 0.000000000)]

 

-> SEC-06

Transform.BasisX = [(0.000000000, 1.000000000, 0.000000000)]

Transform.BasisY = [(0.000000000, 0.000000000, 1.000000000)]

Transform.BasisZ = [(1.000000000, 0.000000000, 0.000000000)]

Min = [(-4.494750656, -1.476377953, -2.460629921)]

Max = [(4.494750656, 9.120734908, 0.656167979)]

Detail Hand = [(1.000000000, 0.000000000, 0.000000000)]

Detail Facing = [(0.000000000, 1.000000000, 0.000000000)]

 

-> SEC-08

Transform.BasisX = [(0.000000000, 1.000000000, 0.000000000)]

Transform.BasisY = [(0.000000000, 0.000000000, 1.000000000)]

Transform.BasisZ = [(1.000000000, 0.000000000, 0.000000000)]

Min = [(-4.494750656, -1.476377953, -2.526246719)]

Max = [(4.494750656, 9.120734908, 0.656167979)]

Detail Hand = [(1.000000000, 0.000000000, 0.000000000)]

Detail Facing = [(0.000000000, 1.000000000, 0.000000000)]

 

0 Likes
556 Views
3 Replies
Replies (3)
Message 2 of 4

Revitalizer
Advisor
Advisor

Hi,

 

may it be that the detail elements are rotated because the view itself is rotated?

You can check that by reading the view.UpDirection - if you have a ViewSection, it may direct downwards, in some cases.

 

So the solution would be to rotate the inserted elements after placement.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 3 of 4

bahaaeldien.metwaly
Contributor
Contributor

Hi Revitalizer,

 

I was very much hoping for a test such as view.UpDirection to work, but sadly it gives (0,1,0) for all views. I also expected a vertical section view to give me the UpDirection as (0,0,1), but no, always (0,1,0).

Now I added a line to rotate the detail if transform.Z = (0,-1,0) to get things going, but i know it won't solve the problem when rotation angle for doors start to vary. (currently it's just 0,90,180,270)

 

 

0 Likes
Message 4 of 4

aignatovich
Advisor
Advisor

Hi!

 

Try the code below. It creates section view for selected door family instance and adds detail component family at view section center. I didn't find any misoriented details for any door family instance position and orientation. This works in default English project template (C:\ProgramData\Autodesk\RVT 2018\Templates\Generic\Default_M_ENU.rte):

 

[Transaction(TransactionMode.Manual)]
public class CreateSectionViewCommand : IExternalCommand
{
	public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
	{
		var uiapp = commandData.Application;
		var uidoc = uiapp.ActiveUIDocument;
		var doc = uidoc.Document;

		var door = SelectDoor(uidoc);

		if (door == null)
			return Result.Cancelled;

		var familySymbol = FindDetailComponentSymbol(doc);

		if (familySymbol == null)
		{
			message = "Detail family symbol not found in the document";

			return Result.Failed;
		}

		using (var transaction = new Transaction(doc, "create section view"))
		{
			transaction.Start();

			var view = CreateViewSection(door);

			var box = view.CropBox;

			var familyPosition = box.Transform.OfPoint(0.5*(box.Min + box.Max));

			doc.Create
				.NewFamilyInstance(familyPosition, familySymbol, view);

			transaction.Commit();
		}

		return Result.Succeeded;
	}

	private static ViewSection CreateViewSection(FamilyInstance door)
	{
		var instanceTransform = door.GetTotalTransform();

		var viewBoxTransform = Transform.Identity;

		viewBoxTransform.BasisZ = instanceTransform.BasisY;
		viewBoxTransform.BasisY = XYZ.BasisZ;
		viewBoxTransform.BasisX = XYZ.BasisZ.CrossProduct(instanceTransform.BasisY);

		var sign = Math.Sign(viewBoxTransform.BasisX.DotProduct(instanceTransform.BasisX));

		var width = door.Symbol.get_Parameter(BuiltInParameter.DOOR_WIDTH).AsDouble();

		var height = door.Symbol.get_Parameter(BuiltInParameter.DOOR_HEIGHT).AsDouble();

		var distance = 0.5 * width;

		viewBoxTransform.Origin = instanceTransform.Origin - sign * distance * instanceTransform.BasisX - 0.5 * instanceTransform.BasisY;

		var sectionBox = new BoundingBoxXYZ
			{
				Min = XYZ.Zero,
				Max = new XYZ(width, height, 1),
				Transform = viewBoxTransform
			};

		var document = door.Document;

		return ViewSection.CreateSection(document, document.GetDefaultElementTypeId(ElementTypeGroup.ViewTypeSection), sectionBox);
	}

	private static FamilySymbol FindDetailComponentSymbol(Document document)
	{
		var collector = new FilteredElementCollector(document);

		return collector
			.OfClass(typeof (FamilySymbol))
			.OfType<FamilySymbol>()
			.FirstOrDefault(x => x.Name == "Rowlock" && x.FamilyName == "Brick - UK Standard");
	}

	private static FamilyInstance SelectDoor(UIDocument uidoc)
	{
		try
		{
			var doorRef = uidoc
				.Selection
				.PickObject(ObjectType.Element, new DoorSelectionFilter(), "select a door");

			return (FamilyInstance) uidoc.Document.GetElement(doorRef);
		}
		catch (OperationCanceledException)
		{
			return null;
		}
	}
}

public class DoorSelectionFilter : ISelectionFilter
{
	private readonly ElementId doorCategoryId =new ElementId(BuiltInCategory.OST_Doors);

	public bool AllowElement(Element elem)
	{
		return elem is FamilyInstance && elem.Category?.Id == doorCategoryId;
	}

	public bool AllowReference(Reference reference, XYZ position)
	{
		return false;
	}
}