private void AddNewGrouFaceDim()//创建一个新的油孔位置信息表 { string sqlcreate = @"CREATE TABLE " + codenumber + "Footprint(ID AUTOINCREMENT,油孔名称 TEXT(50),Dia" + codename + " TEXT(50),X" + codename + " TEXT(50),Y" + codename + " TEXT(50))"; m_connectToAccess.CreateTable(sqlcreate); foreach (DataGridViewRow dr in dataGridViewdim.Rows) { dataGridViewdim.AllowUserToAddRows = false; string sqlupdate1 = "update " + IndexName + " set " + dr.Cells[0].Value.ToString() + "dmax='" + dr.Cells[1].Value.ToString() + "' where 编码 ='" + codename + "'"; if (m_connectToAccess.UpdateInformation(sqlupdate1)) { } ; string sqlupdate2 = "update " + IndexName + " set " + dr.Cells[0].Value.ToString() + "coordX='" + dr.Cells[2].Value.ToString() + "' where 编码 ='" + codename + "'"; if (m_connectToAccess.UpdateInformation(sqlupdate2)) { } ; string sqlupdate3 = "update " + IndexName + " set " + dr.Cells[0].Value.ToString() + "coordY='" + dr.Cells[3].Value.ToString() + "' where 编码 ='" + codename + "'"; if (m_connectToAccess.UpdateInformation(sqlupdate3)) { } ; string sqlinsert = "insert into " + codenumber + "Footprint(油孔名称,Dia" + codename + ",X" + codename + ",Y" + codename + ") values('" + dr.Cells[0].Value.ToString() + "','" + dr.Cells[1].Value.ToString() + "','" + dr.Cells[2].Value.ToString() + "','" + dr.Cells[3].Value.ToString() + "')"; if (m_connectToAccess.InsertInformation(sqlinsert)) { MessageBox.Show("坐标位置信息添加成功"); } } }
//用于给具有安装面的元件端口着色 private void ColorFootprintPort(iFeature ifeature, Face face, int portCount, string netName, string portName) { PartDocument oPartDoc = (PartDocument)m_inventorApplication.ActiveDocument; SelectSet oSelectSet = oPartDoc.SelectSet; PartComponentDefinition oPartCompDef; oPartCompDef = oPartDoc.ComponentDefinition; double portDepth = System.Math.Round(GetValueFromExpression(m_connectToaccess.SelectConnectToAccess(portName + "depth")), 2); foreach (Face oFace in ifeature.Faces) { if (oFace.SurfaceType == SurfaceTypeEnum.kCylinderSurface) { Edges oEdges; oEdges = oFace.Edges; if (oEdges.Count == 2 && oEdges[1].GeometryType == CurveTypeEnum.kCircleCurve && oEdges[2].GeometryType == CurveTypeEnum.kCircleCurve) { double dis1 = System.Math.Round(GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[1], face), 2); double dis2 = System.Math.Round(GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[2], face), 2); if ((dis1 == 0 && dis2 == portDepth) || (dis2 == 0 && dis1 == portDepth)) { Edge startEdge; if (dis1 < dis2) { startEdge = oEdges[1]; } else { startEdge = oEdges[2]; } if (startEdge != null) { WorkPlane startPlane; startPlane = oPartCompDef.WorkPlanes.AddByPlaneAndOffset(face, 0, true); PlanarSketch oPortFaceSketch; oPortFaceSketch = oPartCompDef.Sketches.Add(startPlane); oPortFaceSketch.AddByProjectingEntity(startEdge); Profile profile; profile = oPortFaceSketch.Profiles.AddForSurface(); ExtrudeDefinition portFaceExtruDef; portFaceExtruDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kSurfaceOperation); portFaceExtruDef.SetDistanceExtent(portDepth, PartFeatureExtentDirectionEnum.kNegativeExtentDirection); ExtrudeFeature portFaceExtru; portFaceExtru = oPartCompDef.Features.ExtrudeFeatures.Add(portFaceExtruDef); portFaceExtru.Name = ifeature.Name + "-" + portName; //创建底部圆锥面 WorkPoint coneBasePoint; coneBasePoint = oPartCompDef.WorkPoints.AddAtCentroid(portFaceExtru.Faces[1].Edges[1], true); WorkPlane coneStartPlane; coneStartPlane = oPartCompDef.WorkPlanes.AddByPlaneAndPoint(face, coneBasePoint, true); PlanarSketch oConeSketch; oConeSketch = oPartCompDef.Sketches.Add(coneStartPlane); oConeSketch.AddByProjectingEntity(startEdge); Profile coneProfile; coneProfile = oConeSketch.Profiles.AddForSurface(); Double dAngle = double.Parse(m_connectToaccess.SelectConnectToAccess("Angle")); Double rAngle = ConvertUnit(dAngle, "degree", "radian"); ExtrudeDefinition coneFaceExtruDef; coneFaceExtruDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(coneProfile, PartFeatureOperationEnum.kSurfaceOperation); coneFaceExtruDef.SetThroughAllExtent(PartFeatureExtentDirectionEnum.kNegativeExtentDirection); coneFaceExtruDef.TaperAngle = rAngle; ExtrudeFeature coneFaceExtru; coneFaceExtru = oPartCompDef.Features.ExtrudeFeatures.Add(coneFaceExtruDef); coneFaceExtru.Name = ifeature.Name + "-" + portName + "cone"; Asset asset = null; foreach (Asset asset1 in oPartDoc.Assets) { if (asset1.DisplayName == netName) { asset = asset1; break; } } portFaceExtru.Appearance = asset; coneFaceExtru.Appearance = asset; WritePortFaceAttribute(portFaceExtru, ifeature, 1, 1); WritePortFaceAttribute(portFaceExtru, ifeature, portCount, portName); } } } } } ConnectToAccess connectToAccessNET = new ConnectToAccess(@"F:\CavityLibrary", "项目数据库"); string sql = "insert into NETList(PortName," + netName + ") values('" + ifeature.Name + "-" + portName + "','" + ifeature.Name + "-" + portName + "')"; if (connectToAccessNET.InsertInformation(sql)) { } else { MessageBox.Show("保存网络出错!"); } }
//没有安装面的阀或油孔的其他port着色函数 private void ColorCavPort(iFeature ifeature, Face face, Double portDia, Double portCenterDepth, string netName, int portNumber, int portIndex) { PartDocument oPartDoc = (PartDocument)m_inventorApplication.ActiveDocument; SelectSet oSelectSet = oPartDoc.SelectSet; PartComponentDefinition oPartCompDef; oPartCompDef = oPartDoc.ComponentDefinition; WorkPlane portCenterPlane; portCenterPlane = oPartCompDef.WorkPlanes.AddByPlaneAndOffset(face, -portCenterDepth, true); Faces insertiFeatureFaces; insertiFeatureFaces = ifeature.Faces; string portName = (portIndex + 1).ToString(); foreach (Face oFace in insertiFeatureFaces) { if (oFace.SurfaceType == SurfaceTypeEnum.kCylinderSurface) { Edges oEdges; oEdges = oFace.Edges; if (oEdges.Count == 2 && oEdges[1].GeometryType == CurveTypeEnum.kCircleCurve && oEdges[2].GeometryType == CurveTypeEnum.kCircleCurve) { double dis1 = GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[1], face); double dis2 = GetDistanceBetwEdgeAndFace(oPartCompDef, oEdges[2], face); if ((dis1 >= portCenterDepth && dis2 <= portCenterDepth) || (dis2 >= portCenterDepth && dis1 <= portCenterDepth)) { PlanarSketch oPortFaceSketch; oPortFaceSketch = oPartCompDef.Sketches.Add(portCenterPlane); oPortFaceSketch.AddByProjectingEntity(oEdges[1]); Profile profile; profile = oPortFaceSketch.Profiles.AddForSurface(); ExtrudeDefinition portFaceExtruDef; portFaceExtruDef = oPartCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kSurfaceOperation); portFaceExtruDef.SetDistanceExtent(portDia, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection); ExtrudeFeature portFaceExtru; portFaceExtru = oPartCompDef.Features.ExtrudeFeatures.Add(portFaceExtruDef); portFaceExtru.Name = ifeature.Name + "-" + portName; Asset asset = null; foreach (Asset asset1 in oPartDoc.Assets) { if (asset1.DisplayName == netName) { asset = asset1; } } portFaceExtru.Appearance = asset; WritePortFaceAttribute(portFaceExtru, ifeature, portNumber, portIndex + 1); break; } } } } ConnectToAccess connectToAccessNET = new ConnectToAccess(@"F:\CavityLibrary", "项目数据库"); string sql = "insert into NETList(PortName," + netName + ") values('" + ifeature.Name + "-" + portName + "','" + ifeature.Name + "-" + portName + "')"; if (connectToAccessNET.InsertInformation(sql)) { } else { MessageBox.Show("保存网络出错!"); } }
private void btnsave_Click(object sender, EventArgs e) { IndexName = cmbIndexName.Text.ToString(); codenumber = combcodenumber.Text.ToString(); codename = tb1.Text.ToString(); string sql = "insert into " + IndexName + "(索引编号,编码) values('" + codenumber + "','" + codename + "')"; m_connectToAccess = new ConnectToAccess(deFaultpath, "CavityLibrary"); if (m_connectToAccess.InsertInformation(sql)) { foreach (Control ctr in this.groBcavitydim.Controls) //输入孔的尺寸参数 { if (ctr is TextBox) { //TextBox ctr1=new ctr as TextBox; if ((ctr as TextBox).Text.Length != 0) { string sqlupdate = "update " + IndexName + " set " + (ctr as TextBox).Name + "='" + (ctr as TextBox).Text + "' where 编码 ='" + codename + "'"; if (m_connectToAccess.UpdateInformation(sqlupdate)) { } ; } } } foreach (Control ctr in this.groBThread.Controls) //输入螺纹的参数信息 { if (ctr is TextBox) { //TextBox ctr1=new ctr as TextBox; if ((ctr as TextBox).Text.Length != 0) { string sqlupdate = "update " + IndexName + " set " + (ctr as TextBox).Name + "='" + (ctr as TextBox).Text + "' where 编码 ='" + codename + "'"; if (m_connectToAccess.UpdateInformation(sqlupdate)) { } ; } } } foreach (Control ctr in this.groBcarvalve.Controls) //输入油孔的参数信息 { if (ctr is TextBox) { //TextBox ctr1=new ctr as TextBox; if ((ctr as TextBox).Text.Length != 0) { string sqlupdate = "update " + IndexName + " set " + (ctr as TextBox).Name + "='" + (ctr as TextBox).Text + "' where 编码 ='" + codename + "'"; if (m_connectToAccess.UpdateInformation(sqlupdate)) { } ; } } } if (groBfacedim.Enabled == true) //输入安装面的油孔位置信息 { int i = 0; while (i < combcodenumber.Items.Count && combcodenumber.Text.ToString() != combcodenumber.Items[i].ToString()) { i++; } if (combcodenumber.Text.ToString() == combcodenumber.Items[i].ToString()) { EditGrouFaceDim(); } else { AddNewGrouFaceDim(); } } MessageBox.Show("插入新元件成功"); } }