private PartUnit GetPartUnit(DataRow dr) { if (dr == null) { return(null); } PartUnit pu = new PartUnit(); pu.PartUnitOID = Convert.ToInt32(dr["PartUnitOID"]); pu.PartUnitName = Convert.ToString(dr["PartUnitName"]); return(pu); }
public PartUnit FindPartUnitByPartUnitOID(int PartUnitOID) { string strCmd = @"SELECT PartUnitOID, PartUnitName FROM dbo.PartUnit where PartUnitOID = @PartUnitOID"; List <SqlParameter> parameters = new List <SqlParameter>(); parameters.Add(SqlHelper.CreateParameter("@PartUnitOID", SqlDbType.Int, PartUnitOID)); DataTable dt = SqlHelper.AdapterFill(strCmd, parameters); if (dt.Rows.Count == 0) { return(null); } PartUnit pu = this.GetPartUnit(dt.Rows[0]); return(pu); }
private PartData ParsePartData(Transform trans, PartUnit partUnit, string customValue) { PartData partData; switch (partUnit.type) { case PartType.Bone: { var data = new BoneData(); for (int i = 0; i < trans.childCount; i++) { var t = trans.GetChild(i); if (!t.name.StartsWith(ModelFBXParser.GroupMark)) { continue; } var group = t; for (int j = 0; j < @group.childCount; j++) { var child = @group.GetChild(j); data.num = customValue; var childName = ModelFBXParser.ToLegalName(child.name); data.items.Add(childName); } break; } partData = data; break; } case PartType.MC: { var data = new MCData(); data.type = 1; partData = data; break; } case PartType.Wire: { var data = new WireData(); data.num = customValue; partData = data; break; } case PartType.Servo: { var data = new ServoData(); data.id = int.Parse(customValue); data.type = 1; data.angle = 120; partData = data; break; } case PartType.Motor: { var data = new MotorData(); data.id = int.Parse(customValue); partData = data; break; } case PartType.Sensor: { var data = new SensorData(); data.id = int.Parse(customValue); partData = data; break; } default: { partData = new PartData(); break; } } partData.name = trans.name; partData.source = partUnit.source; partData.transform = new DTransform(); partData.transform.position = trans.localPosition; partData.transform.angle = trans.localEulerAngles; partData.transform.scale = GetScale(trans, partData.partType); partData.parent = GetParentName(trans); return(partData); }
public static MenuBarManager.CallbackStatus Import3DMFile(string filePath) { using (File3dm model = File3dm.Read(filePath)) { var scaleFactor = RhinoMath.UnitScale(model.Settings.ModelUnitSystem, PartUnit.ToRhinoUnits()); var elements = new List <NXOpen.NXObject>(); //model.Objects.Select(obj => obj.Geometry.GetType().ToString()).ToList().ForEach(obj => obj.ListingWindowWriteLine()); foreach (var obj in model.Objects.Where(x => !x.Attributes.IsInstanceDefinitionObject && x.Attributes.Space == ActiveSpace.ModelSpace)) { if (!obj.Attributes.Visible) { continue; } var layer = model.AllLayers.FindIndex(obj.Attributes.LayerIndex); if (layer?.IsVisible != true) { continue; } var geometry = obj.Geometry; if (geometry is Extrusion extrusion) { geometry = extrusion.ToBrep(); } else if (geometry is SubD subD) { geometry = subD.ToBrep(new SubDToBrepOptions()); } try { switch (geometry) { case Point point: var referncePoint = WorkPart.Points.CreatePoint(point.Location.ToXYZ(scaleFactor)); referncePoint.SetVisibility(NXOpen.SmartObject.VisibilityOption.Visible); elements.Add(referncePoint); break; case Curve curve: if (curve.TryGetPlane(out var plane, DistanceTolerance)) // 平面曲线转换 { if (CurveEncoder.ToNXCurve(curve, scaleFactor) is NXOpen.Curve crv) { elements.Add(crv); } } else { var shape = curve.ToShape(scaleFactor); elements.AddRange(shape); } break; case Brep brep: BrepEncoder.ToSolid(brep); //if (brep.ToSolid(scaleFactor) is DB.Solid solid) //{ // if (DB.FreeFormElement.Create(doc, solid) is DB.FreeFormElement freeForm) // { // elements.Add(freeForm.Id); // { // var categoryId = ImportLayer(doc, model, layer, categories, materials); // if (categoryId != DB.ElementId.InvalidElementId) // freeForm.get_Parameter(DB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY).Set(categoryId); // } // if (obj.Attributes.MaterialSource == ObjectMaterialSource.MaterialFromObject) // { // if (model.AllMaterials.FindIndex(obj.Attributes.MaterialIndex) is Material material) // { // var categoryId = ImportMaterial(doc, material, materials); // if (categoryId != DB.ElementId.InvalidElementId) // freeForm.get_Parameter(DB.BuiltInParameter.MATERIAL_ID_PARAM).Set(categoryId); // } // } // } //} break; } } catch (NXOpen.NXException ex) { } } } return(MenuBarManager.CallbackStatus.Continue); }