Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rotate cropBox

2 REPLIES 2
Reply
Message 1 of 3
salemmelu
220 Views, 2 Replies

Rotate cropBox

Hi! Is there a way to rotate a CropBox through Revit´s API?

Context:

I am working with assemblies, automating their view, sheet and dimensions creation. I have assemblies in 2 orientations: "vertical" on the screen (N-S) and "horizontal" on the screen (E-W). I want all the sheets to look something like this:

salemmelu_0-1711553174425.png (Section A, Section B, Bottom and Top views)

With "horizontal" assemblies it works OK, but with "vertical" assemblies the Bottom (and Top) views are shown like this, because of the elements´ position/orientation:

salemmelu_1-1711553392981.png

If I rotate the Bottom view´s viewport through its "Rotation on Sheet" parameter, dimensions end up up-side-down:

salemmelu_2-1711553507854.png

Through different forum posts and tutorials I found another way to do it is to rotate the view´s cropbox. This way dimmensions are seen properly:

salemmelu_3-1711553642467.png                         salemmelu_4-1711553665975.png

I have managed to do this manually, but I haven´t found a way to do it through the API (or Dynamo nodes) in order to automate it. Is there a way to do so?

 

P.S.: I have worked around it by rotating the viewport through the "Rotation on Sheet" parameter, and creating a new dimension type with different "Read Convention" parameter. But I was still wondering if there is a way to automate the cropbox rotation, so that I don´t have to work with/update/mantain 2 differnet types of dimmensions 

 

I have been working with Dynamo for sometime, but I am pretty new to programming with the API. Any suggestions are welcomed. Thank you!

2 REPLIES 2
Message 2 of 3
TripleM-Dev.net
in reply to: salemmelu

Hi @salemmelu,

 

Don't know about Dynamo, I'm sure there will be package(s) around that can do it (or can do the steps below).

 

For C# you can try the following (haven't tested it, but should be doable for floorplans, the results in RevitLookup do confirm it)

Try to repeat the manual steps in Revit in the UI in the API:

- Select the Cropline of the view

- rotate box around a point, use RotateElement for this

 

Retrieving the Id of the crop line element is not so easy, you can't directly filter for it or get it as a property of the view.

1. Check if the view is Cropped (doesn't need to be visible)

2. retrieve the Id of the view and add 1 (view = 312, Crop will be 313)

3. check if the Crop Id has the builtinparameter "VIEW_NAME" and it's value is equal to the view thats being evaluated, if it matches it's the correct element.

4. now the rotation point can be determined and rotated with RotateElement.

 

- Michel

 

Message 3 of 3
esatis
in reply to: salemmelu

Hi,

haven't done the way you propose - rotate existing Crop Region, but for regular sections, the Crop Region are BoundigBoxXYZ.
You find elements, create and transform BoundigBoxXYZ around them, then create ViewSections with ViewSection.CreateSection(_document, _viewFamilyType.Id, sectionBox); where sectionBox are your BoundigBoxXYZ

private BoundingBoxXYZ CreateSectionBoundingBox(double elementWidth, double elementHeight, XYZ elementPosition, XYZ facingOrientation)
{
	double viewportWidth = elementWidth / 2 + _viewportOffset;
	double viewportBottom = elementPosition.Z - _viewportOffset;
	double viewportTop = elementPosition.Z + elementHeight + _viewportOffset;

	XYZ min = new XYZ(-viewportWidth, viewportBottom, -_sectionDepth);
	XYZ max = new XYZ(viewportWidth, viewportTop, _sectionDepth);

	XYZ up = new XYZ(0, 0, elementPosition.Z + 1).Normalize();

	XYZ viewDirection = facingOrientation;
	XYZ elementDirection = up.CrossProduct(viewDirection);

	Transform transform = Transform.Identity;

	// We have to normalize the element Z position, otherwise the section box MIN MAX will be added to this value.
	transform.Origin = new XYZ(elementPosition.X, elementPosition.Y, elementPosition.Normalize().Z);
	transform.BasisX = elementDirection;
	transform.BasisY = up;
	transform.BasisZ = viewDirection;

	return new BoundingBoxXYZ
	{
		Transform = transform,
		Min = min,
		Max = max
	};
}



Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community