Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Set non rectangular crop shape

MiguelGT17
Advocate

Set non rectangular crop shape

MiguelGT17
Advocate
Advocate

Greetings to everybody,

 

I have a problem with the crop shape, I wish to create floorplans and set the crop shape as this sample:

MiguelGT17_0-1667409550819.png

but eventually Revit throws an exception that says that I can not associate non-rectangular shapes with the view.

Is it for real, I'm not be able to set those shapes through the API ? or is it that anything is wrong with my code:

					//method 2: get the room solid and use the bottom face boundary
					SpatialElementGeometryCalculator cal = new SpatialElementGeometryCalculator(doc,sebOp);
					SpatialElementGeometryResults results = cal.CalculateSpatialElementGeometry(room);
					Solid roomSolid2 = results.GetGeometry();
					foreach (Face face in roomSolid2.Faces) {
						PlanarFace plFace = face as PlanarFace;
						if (plFace != null) {
							XYZ normalFace = plFace.FaceNormal;
							if (normalFace.Z == -1) {
								roomBoundary = plFace.GetEdgesAsCurveLoops()[0];
								
								break;
							}
						}
					}
					
					//set the crop layout
					ViewCropRegionShapeManager cropManager = vplan.GetCropRegionShapeManager();
					if (roomBoundary != null) {
						cropManager.SetCropShape(roomBoundary);
					}

best regards,

Miguel G.

0 Likes
Reply
Accepted solutions (1)
339 Views
4 Replies
Replies (4)

jeremy_tammik
Autodesk
Autodesk

The GetEdgesAsCurveLoops method return value is IList<CurveLoop>.

  

The input argument to the SetCropShape method is a single CurveLoop boundary, not an ILIst.

  

Does that help?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

MiguelGT17
Advocate
Advocate

Actually, I'm requesting the first curve loop out of the Ilist<Curvelopp> returned by the GetEdgesAsCurveLoops().

 

In another note, I've even tried to set rectangular crop shapes:

					//method 3: set rectangular shape					
					SpatialElementGeometryCalculator cal = new SpatialElementGeometryCalculator(doc,sebOp);
					SpatialElementGeometryResults results = cal.CalculateSpatialElementGeometry(room);
					Solid roomSolid2 = results.GetGeometry();
					
					List<double> xcoord = new List<double>();
					List<double> ycoord = new List<double>();
					List<double> zcoord = new List<double>();
					
					foreach (Face face in roomSolid2.Faces) {
						PlanarFace plFace = face as PlanarFace;
						if (plFace != null) {
							XYZ normalFace = plFace.FaceNormal;
							if (normalFace.Z == -1) {
								roomBoundary = plFace.GetEdgesAsCurveLoops()[0];
								
								foreach (Curve curve in roomBoundary) {
									Line line = curve as Line;
									if (line != null) {
										xcoord.Add(line.GetEndPoint(0).X);
										xcoord.Add(line.GetEndPoint(1).X);
										ycoord.Add(line.GetEndPoint(0).Y);
										ycoord.Add(line.GetEndPoint(1).Y);
										zcoord.Add(line.GetEndPoint(0).Z);
										zcoord.Add(line.GetEndPoint(1).Z);
									}
								}
								
								break;
							}
						}
					}
					IList<Curve> curves = new List<Curve>();
					XYZ minPt = new XYZ(xcoord.Min(),ycoord.Min(),zcoord.Min());
					XYZ maxPt = new XYZ(xcoord.Max(),ycoord.Max(),zcoord.Min());
					
					Line lineA = Line.CreateBound(minPt,new XYZ(minPt.X,maxPt.Y,minPt.Z));
					Line lineB = Line.CreateBound(new XYZ(minPt.X,maxPt.Y,minPt.Z), maxPt);
					Line lineC = Line.CreateBound(maxPt,new XYZ(maxPt.X,minPt.Y,minPt.Z));
					Line lineD = Line.CreateBound(new XYZ(maxPt.X,minPt.Y,minPt.Z), minPt);
					
					curves.Add(lineA);
					curves.Add(lineB);
					curves.Add(lineC);
					curves.Add(lineD);
					roomBoundary = CurveLoop.Create(curves);
					
					//set the crop layout
					ViewCropRegionShapeManager cropManager = vplan.GetCropRegionShapeManager();
					if (roomBoundary != null) {
						cropManager.SetCropShape(roomBoundary);
					}

and I still having the same error:

MiguelGT17_0-1667411289387.png

any clarifications on how to set the view crop shape properly?

 

All the best,

0 Likes

MiguelGT17
Advocate
Advocate
Accepted solution

Hey @jeremy_tammik I solved this issue, I though the view template already set the CropBoxActive and CropBoxVisible as true values

 

					//set view template Id
					vplan.ViewTemplateId = walksheetVtemplate.Id;

 

but I guess it's not the case. Since I added these line of code:

 

 

					vplan.CropBoxActive = true;
					vplan.CropBoxVisible = true;

 

before setting the crop shape, it's working fine.

MiguelGT17_0-1667411814393.png

Now I'm moving forward with Elevation view for each room, probably you going to hear from me again

All the best,

Miguel G.

jeremy_tammik
Autodesk
Autodesk

Oh yes, sorry, I overlooked the [0].

  

Can you provide a minimal reproducible case to share with the development team?

  

Ah, maybe, no, first, please take a look at this blog post and the repository and discussion threads it summarises:

  

  

As far as I can tell offhand, it describes a successful use of this method.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes