public RelationVO(SketchRelation swSkRel, String sketchName, ModelDoc2 swModel) { int j; SketchPoint swSkPt = null; SketchSegment swSkSeg = null; typeName = Enum.GetName(typeof(swConstraintType_e), swSkRel.GetRelationType()); type = swSkRel.GetRelationType(); //Dimensions need to check if required DisplayDimension dispDim = (DisplayDimension)swSkRel.GetDisplayDimension(); if (dispDim != null) { dimensionValue = dispDim.GetDimension().GetSystemValue2(""); } int[] vEntTypeArr = (int[])swSkRel.GetEntitiesType(); object[] vEntArr = (object[])swSkRel.GetEntities(); object[] vDefEntArr = (object[])swSkRel.GetDefinitionEntities2(); if ((vDefEntArr == null)) { } if ((vEntTypeArr != null) & (vEntArr != null)) { if (vEntTypeArr.GetUpperBound(0) == vEntArr.GetUpperBound(0)) { j = 0; foreach (swSketchRelationEntityTypes_e vType in vEntTypeArr) { SketchRelationEntityVO entity = new SketchRelationEntityVO(); entity.typeName = "" + vType; entity.type = (int)vType; switch (vType) { case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Unknown: break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_SubSketch: break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Point: swSkPt = (SketchPoint)vEntArr[j]; entity.name = swSkPt.X + "," + swSkPt.Y + "," + swSkPt.Z; entity.sketchName = sketchName; entity.id = swModel.Extension.GetPersistReference3(swSkPt); // bRet = swSkPt.Select4(false, swSelData); break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Line: case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Arc: case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Ellipse: case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Parabola: case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Spline: swSkSeg = (SketchSegment)vEntArr[j]; Sketch sk = (Sketch)swSkSeg.GetSketch(); // sk. entity.id = swModel.Extension.GetPersistReference3(swSkSeg); entity.name = swSkSeg.GetName(); entity.sketchName = sketchName; break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Hatch: break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Text: break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Plane: break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Cylinder: break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Sphere: break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Surface: break; case swSketchRelationEntityTypes_e.swSketchRelationEntityType_Dimension: break; default: break; } j = j + 1; entities.Add(entity); } } } }
protected override void Command() { try { Face2 face = null; SketchSegment segment = null; if (MdlBase.eSelect_RecupererTypeObjet(1) == e_swSelectType.swSelFACES) { face = MdlBase.eSelect_RecupererObjet <Face2>(1); segment = MdlBase.eSelect_RecupererObjet <SketchSegment>(2); } else { face = MdlBase.eSelect_RecupererObjet <Face2>(2); segment = MdlBase.eSelect_RecupererObjet <SketchSegment>(1); } if (face == null || segment == null) { return; } MdlBase.eEffacerSelection(); Boolean r = false; Boolean reverse = false; var sk = segment.GetSketch(); var xform = (MathTransform)sk.ModelToSketchTransform.Inverse(); if (segment.GetType() != (int)swSketchSegments_e.swSketchLINE) { return; } var sl = (SketchLine)segment; var start = new ePoint(sl.GetStartPoint2()); var end = new ePoint(sl.GetEndPoint2()); start.ApplyMathTransform(xform); end.ApplyMathTransform(xform); WindowLog.Ecrire(start.IsRef() + " " + start.ToString()); WindowLog.Ecrire(end.IsRef() + " " + end.ToString()); var box = (Double[])face.GetBox(); var pt = new ePoint((box[3] + box[0]) * 0.5, (box[4] + box[1]) * 0.5, (box[5] + box[2]) * 0.5); WindowLog.Ecrire(pt.IsRef() + " " + pt.ToString()); if (start.Distance2(pt) > end.Distance2(pt)) { reverse = true; } r = face.eSelectEntite(MdlBase, 4, false); r = segment.eSelect(MdlBase, 1, true); var cp = (Body2)face.GetBody(); r = cp.eSelect(MdlBase, 512, true); var fm = MdlBase.FeatureManager; var featRepetDef = (CurveDrivenPatternFeatureData)fm.CreateDefinition((int)swFeatureNameID_e.swFmCurvePattern); featRepetDef.D1AlignmentMethod = 0; featRepetDef.D1CurveMethod = 0; featRepetDef.D1InstanceCount = 3; featRepetDef.D1IsEqualSpaced = true; featRepetDef.D1ReverseDirection = reverse; featRepetDef.D1Spacing = 0.001; featRepetDef.D2InstanceCount = 1; featRepetDef.D2IsEqualSpaced = false; featRepetDef.D2PatternSeedOnly = false; featRepetDef.D2ReverseDirection = false; featRepetDef.D2Spacing = 0.001; featRepetDef.GeometryPattern = true; var featRepet = fm.CreateFeature(featRepetDef); WindowLog.Ecrire(featRepet != null); } catch (Exception e) { this.LogMethode(new Object[] { e }); WindowLog.Ecrire(new Object[] { e }); } }