private string GetExtents(Inventor.SurfaceBody SurfaceBody) { string VectorDirection = "X"; double[] Lengths = new double[3]; Inventor.Box ExtentsBox = SurfaceBody.RangeBox; Lengths[0] = Math.Abs(ExtentsBox.MaxPoint.X) + Math.Abs(ExtentsBox.MinPoint.X); Lengths[1] = Math.Abs(ExtentsBox.MaxPoint.Y) + Math.Abs(ExtentsBox.MinPoint.Y); Lengths[2] = Math.Abs(ExtentsBox.MaxPoint.Z) + Math.Abs(ExtentsBox.MinPoint.Z); int Mx = Array.IndexOf(Lengths, Lengths.Max()); int Mn = Array.IndexOf(Lengths, Lengths.Min()); // RangeMid = GetMedian(Lengths); // int Md = Array.IndexOf(Lengths, RangeMid); if (Mx == 0) { VectorDirection = "X"; } if (Mx == 1) { VectorDirection = "Y"; } if (Mx == 2) { VectorDirection = "Z"; } return(VectorDirection); }
public Inventor.Face GetBiggestFace(Inventor.SurfaceBody mSurfaceBody) { double Max = mSurfaceBody.Faces[1].Evaluator.Area * 100; double currentValue = 0; Inventor.Face TargetFace = null; foreach (Inventor.Face Face in mSurfaceBody.Faces) { currentValue = Face.Evaluator.Area * 100; if (currentValue > Max) { Max = Face.Evaluator.Area * 100; TargetFace = Face; } } if (TargetFace != null) { return(TargetFace); } else { return(null); } }
//Used By DXF public Inventor.Face GetFaceLargestArea(Inventor.SurfaceBody mSurfaceBody) { Inventor.Face WorkFace = null; System.Collections.ArrayList Areas = new ArrayList(); Dictionary <double, object> AreaValue = new Dictionary <double, object>(); double Max = mSurfaceBody.Faces[1].Evaluator.Area * 100; double currentValue = 0; WorkFace = mSurfaceBody.Faces[1]; Inventor.UnitVector zVector = mInvApplication.TransientGeometry.CreateUnitVector(0, 0, 1); for (int i = 1; i < mSurfaceBody.Faces.Count + 1; i++) { currentValue = mSurfaceBody.Faces[i].Evaluator.Area * 100; AreaValue.Add(currentValue, mSurfaceBody.Faces[i]); if (currentValue > Max) { Max = mSurfaceBody.Faces[i].Evaluator.Area * 100; WorkFace = mSurfaceBody.Faces[i]; } } if (WorkFace != null) { return(WorkFace); } else { return(null); } }
private void GetFaceToSetView(Inventor.SurfaceBody mSurfaceBody, Inventor.PartDocument PartDocument) { Inventor.Face WorkFace = null; System.Collections.ArrayList Areas = new ArrayList(); Dictionary <double, object> AreaValue = new Dictionary <double, object>(); double Max = mSurfaceBody.Faces[1].Evaluator.Area * 100; double currentValue = 0; WorkFace = mSurfaceBody.Faces[1]; Inventor.UnitVector zVector = mInvApplication.TransientGeometry.CreateUnitVector(0, 0, 1); ArrayList SortArray = new ArrayList(); ArrayList SortArray2 = new ArrayList(); Inventor.Plane Plane; for (int i = 1; i < mSurfaceBody.Faces.Count + 1; i++) { currentValue = mSurfaceBody.Faces[i].Evaluator.Area * 100; //SortArray.Add(currentValue); if (!mSurfaceBody.Faces[i].IsParamReversed) { if (currentValue >= Max) { Inventor.Face fc = mSurfaceBody.Faces[i]; Inventor.UnitVector vect = PartDocument.ComponentDefinition.WorkPlanes["XY Plane"].Plane.Normal; if (fc.Geometry is Inventor.Plane) { Plane = fc.Geometry; Inventor.UnitVector pVect = GetMidPointAtFaceNormal(ref fc); Max = mSurfaceBody.Faces[i].Evaluator.Area * 100; if (pVect.IsParallelTo(vect, 0.00001)) { if (Plane.Normal.DotProduct(vect) > 0) { SortArray2.Add(currentValue); WorkFace = mSurfaceBody.Faces[i]; } } } } } } if (WorkFace != null) { SetViewDirection(WorkFace); } else { return; } }
private void GetFaceDirction(Inventor.SurfaceBody mSurfaceBody) { foreach (Inventor.Face face in mSurfaceBody.Faces) { if (face.SurfaceType == Inventor.SurfaceTypeEnum.kPlaneSurface) { Inventor.UnitVector YDir; Inventor.Point FacePoint = face.PointOnFace; Inventor.UnitVector normal = GetFaceNormalPoint(face, FacePoint); Inventor.UnitVector XDir = GetXDir(face, FacePoint); YDir = normal.CrossProduct(XDir); } } }
private void GetFaceSize(Inventor.SurfaceBody mSurfaceBody) { ArrayList Area = new ArrayList(); foreach (Inventor.Face Face in mSurfaceBody.Faces) { Area.Add(Face.Evaluator.Area * 100); } Area.Reverse(); foreach (double x in Area) { //lstNames.Items.Add(x.ToString() + " ...Area"); } }
private void GetFaceToView(Inventor.SurfaceBody mSurfaceBody, ref Inventor.PartDocument PartDocument, ref Inventor.Camera Camera) { double Max = mSurfaceBody.Faces[1].Evaluator.Area * 100; double currentValue = 0; GetExtents(mSurfaceBody); Inventor.Face TargetFace = null; foreach (Inventor.Face Face in mSurfaceBody.Faces) { currentValue = Face.Evaluator.Area * 100; if (currentValue >= Max) { Max = Face.Evaluator.Area * 100; TargetFace = Face; } } SetDrawingView(mSurfaceBody, ref Camera, TargetFace); }
private void SetDrawingView(Inventor.SurfaceBody mSurfaceBody, ref Inventor.Camera Camera, Inventor.Face TargetFace) { if (TargetFace != null) { if (!TargetFace.IsParamReversed) { if (TargetFace.Geometry is Inventor.Plane) { //Inventor.Face TargetFace = Face; Inventor.Point FacePoint = TargetFace.PointOnFace; Inventor.UnitVector Normal = GetFaceNormal(ref TargetFace, ref FacePoint); Inventor.UnitVector UplDirection = mInvApplication.TransientGeometry.CreateUnitVector(0, 1, 0); Inventor.UnitVector Z_PosDirection = mInvApplication.TransientGeometry.CreateUnitVector(0, 0, 1); Inventor.UnitVector Z_NegDirection = mInvApplication.TransientGeometry.CreateUnitVector(0, 0, -1); Inventor.UnitVector X_PosDirection = mInvApplication.TransientGeometry.CreateUnitVector(1, 0, 0); Inventor.UnitVector Y_PosDirection = mInvApplication.TransientGeometry.CreateUnitVector(0, 1, 0); Inventor.UnitVector X_NegDirection = mInvApplication.TransientGeometry.CreateUnitVector(-1, 0, 0); Inventor.UnitVector Y_NegDirection = mInvApplication.TransientGeometry.CreateUnitVector(0, -1, 0); if (Z_PosDirection.IsEqualTo(Normal)) { if (GetExtents(mSurfaceBody) == "X") { UplDirection = Y_NegDirection; } else if (GetExtents(mSurfaceBody) == "Y") { UplDirection = X_NegDirection; } else if (GetExtents(mSurfaceBody) == "Z") { UplDirection = GetXDir(ref TargetFace, ref FacePoint); } FacePoint = Camera.Eye.Copy(); FacePoint.TranslateBy(GetMidPointAtFaceNormal(ref TargetFace).AsVector()); Camera.Target = FacePoint; Camera.UpVector = UplDirection; Camera.Fit(); Camera.Apply(); } else if (Z_NegDirection.IsEqualTo(Normal)) { if (GetExtents(mSurfaceBody) == "X") { UplDirection = Y_PosDirection; } else if (GetExtents(mSurfaceBody) == "Y") { UplDirection = X_PosDirection; } else if (GetExtents(mSurfaceBody) == "Z") { UplDirection = GetXDir(ref TargetFace, ref FacePoint); } FacePoint = Camera.Eye.Copy(); FacePoint.TranslateBy(GetMidPointAtFaceNormal(ref TargetFace).AsVector()); Camera.Target = FacePoint; Camera.UpVector = UplDirection; Camera.Fit(); Camera.Apply(); } } } } }