"A problem has been detected" View section Creation

"A problem has been detected" View section Creation

MiguelGT17
Advocate Advocate
576 Views
5 Replies
Message 1 of 6

"A problem has been detected" View section Creation

MiguelGT17
Advocate
Advocate

In summary,

This exception is throwned when creating an elevations views (doesnt have too much details unfortunately):

MiguelGT17_0-1669610129764.png

the code I'm using:

                                        	//a). Determine view family type to use
										    ViewFamilyType vft
										      = new FilteredElementCollector( doc )
										        .OfClass( typeof( ViewFamilyType ) )
										        .Cast<ViewFamilyType>()
										        .FirstOrDefault<ViewFamilyType>( x =>
										          ViewFamily.Section == x.ViewFamily  && x.Name == "Building Section"); //is it enough to not include building section and always return this one??
                                        	
                                        	//b). Determine section box (The Min and Max properties of the bounding box determine the crop region and far clip distance)
                                        	LocationCurve locCv = wall.Location as LocationCurve;
                                        	if (locCv != null && wallFace is PlanarFace) {
                                        	
                                        		
                                        		PlanarFace planarWallFc = wallFace as PlanarFace;
                                        		Line line = locCv.Curve as Line;
                                        		if (line != null && planarWallFc != null) {
                                        			
													List<double> zVal = new List<double>();
													
                                        			foreach (Face face in roomSolidFinish.Faces) //try using up to the center for determining the coordinates
                                        			{
														PlanarFace plFc = face as PlanarFace;
														if (plFc != null) {
															if (plFc.FaceNormal.Z <= -0.98 || plFc.FaceNormal.Z >= 0.98) //here is an issue, some of the bottom faces do not have a flat -1 negative value!!
															{
																foreach (EdgeArray edgeArray in face.EdgeLoops) {
																	foreach (Edge edge in edgeArray) {
																		Curve cv = edge.AsCurve();
																		
																		zVal.Add(cv.GetEndPoint(0).Z);
																		zVal.Add(cv.GetEndPoint(1).Z);
																	}
																}
															}
														}
													}
													XYZ min = new XYZ(line.Length,zVal.Min(),- wall.WallType.Width);
                                        			XYZ max = new XYZ(-line.Length,zVal.Max() + wall.WallType.Width,0);
                                        			
                                        			Transform t = Transform.Identity;
                                        			t.Origin = line.Evaluate(0.5,true);
                                        			t.BasisX = line.Direction;
                                        			t.BasisY = XYZ.BasisZ;
                                        			t.BasisZ = -line.Direction.CrossProduct(XYZ.BasisZ);
                                        			
                                        			BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();
                                        			sectionBox.Transform = t;
//                                        			sectionBox.Min = min;
//                                        			sectionBox.Max = max;
//                                        			
//                                        			
//                                        			ViewSection vwSec = ViewSection.CreateSection(doc,vft.Id,sectionBox);

the exception is throwed at line 47. If I comment line 47, there is no exception, and I can not create the view section.

 

Any possible root cause for this one?

Cheers,

Miguel G.

Accepted solutions (1)
577 Views
5 Replies
Replies (5)
Message 2 of 6

jeremy_tammik
Alumni
Alumni

Assert t.IsConformal? t.Determinant == +1?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 6

Revitalizer
Advisor
Advisor

Hi,

 

does this help?

 

BoundingBoxXYZ sectionBox = new BoundingBoxXYZ();
sectionBox.Enabled = true;
sectionBox.Transform = t;




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 6

MiguelGT17
Advocate
Advocate

Hi @Revitalizer, Negative,

MiguelGT17_1-1669835594716.png

I was playing around with T.determinant as @jeremy_tammik suggested and this error pops up now:

MiguelGT17_1-1669835379096.png

0 Likes
Message 5 of 6

RPTHOMAS108
Mentor
Mentor
Accepted solution

I believe you need to rethink your Min/Max

 

Every ord of min should be less than every ord of max
XYZ min = new XYZ(line.Length,zVal.Min(),- wall.WallType.Width);
XYZ max = new XYZ(-line.Length,zVal.Max() + wall.WallType.Width,0);

 

The above doesn't achieve that since your min.x > max.x.

 

The min/max is local to the bounding box transform i.e. relative to transform origin and aligned with the transform basis vectors so min is never > than max. So you just need to order the ords accordingly e.g. if the transform origin was at the centre of the box (it doesn't have to be) then the min/max could be opposite coord values with all values of min -ve and all values of max +ve (that is just an example).

 

Another simple way of getting the values is to align the transform in terms of how the view is set up to be created, then use Transform.Inverse.OfPoint on the two 'global' corner points you decide on for the bounding box. Then from those transformed points get the max/min.

 

Also when creating view section I believe from experience the Basis.Z to create the view is pointing away from viewer contrast this with view direction pointing towards viewer (what you end up with). 

 

"The view direction of the resulting section will be sectionBox.Transform.BasisZ and the up direction will be sectionBox.Transform.BasisY. The right hand direction will be computed so that (right, up, view direction) form a left handed coordinate system."

 

The result is right handed I believe, you can check this by drawing a section west to east on plan. In such an instance the view will be looking north but the view direction will be pointing south. This is the reason why people get a section in the opposite direction to what they expect when they create it by copying in the section box from another section.

 

Lastly regardless of above quote I keep the transform of the bounding box used to create the section right-handed by making the right direction actually opposite to right. I don't think the transform will work otherwise. I think the quote is just awkward wording to state that view direction is the opposite of what you end up with. The classic example is a plan view where you are looking down upon the model but the view direction is XYZ.BasisZ.

Message 6 of 6

MiguelGT17
Advocate
Advocate

Thanks for the solution Thomas, It worked for me. Sorry for the late response, I was feeling ill those days.

All the best!