/// <summary> /// 获得配合类型 /// </summary> /// <param name="SwComp"></param> public static void GetMateRefrence(Component2 SwComp) { object[] CompMateObjs = SwComp.GetMates(); StringBuilder Sb = new StringBuilder(""); foreach (object ObjMate in CompMateObjs) { if (ObjMate is Mate2) { Mate2 SwMate = (Mate2)ObjMate; Sb.Append("配合【" + ((Feature)SwMate).Name + "】参考对象:\r\n"); //配合名称 int n = SwMate.GetMateEntityCount(); for (int i = 0; i < n; i++) //配合参考 { MateEntity2 SwMateEntity2 = SwMate.MateEntity(i); string reftype = Enum.Parse(typeof(swSelectType_e), SwMateEntity2.ReferenceType2.ToString().Trim()).ToString().Trim(); string comp = SwMateEntity2.ReferenceComponent.Name2; string refname = SwMateEntity2.Reference.Name; Sb.Append("部件【" + comp + "】,参考【" + refname + "】" + ",类型【" + reftype + "】"); DisplayDimension SwDispDim = SwMate.DisplayDimension2[0]; if (SwDispDim != null) { if (SwMate.Type == (int)swMateType_e.swMateANGLE) { Sb.Append(",角度=" + SwDispDim.GetDimension2(0).Value.ToString().Trim()); } else if (SwMate.Type == (int)swMateType_e.swMateDISTANCE) { Sb.Append(",尺寸=" + SwDispDim.GetDimension2(0).Value.ToString().Trim()); } } Sb.Append("\r\n"); } Sb.Append("\r\n"); } } System.Windows.MessageBox.Show(Sb.ToString().Trim()); }
public virtual double GetValue(string confName = "") { var dim = DisplayDimension.GetDimension2(0); swInConfigurationOpts_e opts; string[] confs; GetDimensionParameters(confName, out opts, out confs); var val = (dim.GetSystemValue3((int)opts, confs) as double[])[0]; return(val); }
private void MajAngle(Object sender) { ListeMarches = MdlBase.eSelect_RecupererListeComposants(_Select_Marche.Marque); if (ListeMarches.Count == 0) { return; } foreach (Component2 cp in ListeMarches) { Object[] Mates = cp.GetMates(); if (Mates.IsRef()) { foreach (Mate2 mate in Mates) { if (mate.Type == (int)swMateType_e.swMateANGLE) { DisplayDimension DD = mate.DisplayDimension2[0]; Dimension D = DD.GetDimension2(0); ListeNomComp.Add(cp.Name2); ListeDim.Add(D); break; } } } } _TextListBox_Marche.Liste = ListeNomComp; GroupeParametres.Expanded = true; foreach (Component2 cp in ListeMarches) { cp.DeSelect(); } _TextListBox_Marche.SelectedIndex = 0; }
public virtual double GetValue(string confName = "") { var dim = DisplayDimension.GetDimension2(0); swInConfigurationOpts_e opts; string[] confs; if (!string.IsNullOrEmpty(confName)) { confs = new string[] { confName }; opts = swInConfigurationOpts_e.swSpecifyConfiguration; } else { opts = swInConfigurationOpts_e.swThisConfiguration; confs = null; } var val = (dim.GetSystemValue3((int)opts, confs) as double[])[0]; return(val); }
private void OpenAssemblyButtonClick(object sender, EventArgs e) { // display an open file dialog where user can select an assembly file OpenFileDialog openAssemblyFileDialog = new OpenFileDialog { InitialDirectory = "E:\\Files\\KPI\\macro", Filter = "SolidWorks2014 assembly files|*.sldasm", Title = "Select a SolidWorks Assembly File" }; // show the dialog // if the user clicked OK in the dialog and // a file was selected, get name of the file if (openAssemblyFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // get name of the assembly file string fileName = openAssemblyFileDialog.FileName; // start solidworks swApp = new SldWorks { Visible = this.swVisible.Checked }; // open assembly file swDoc = OpenAssembly(fileName); // activate opened document swApp.ActivateDoc2("sborka", false, 0); // get active document swDoc = (ModelDoc2)swApp.ActiveDoc; // get assembly object swAsm = (AssemblyDoc)swDoc; // get first feature in the doc feature = swDoc.FirstFeature(); List <string> featureNames = new List <string>(); while (feature != null) { featureNames.Add("Feature: " + feature.GetTypeName2()); if (feature.GetTypeName2() == "MateGroup") { // get first sub feature in the mate group subFeature = feature.GetFirstSubFeature(); // for all sub features get all dimesions while (subFeature != null) { featureNames.Add("-> SubFeature: " + subFeature.GetTypeName2()); displayDimension = subFeature.GetFirstDisplayDimension(); // for all display dimensions show their dimension while (displayDimension != null) { dimension = displayDimension.GetDimension2(0); displayDimension = subFeature.GetNextDisplayDimension(displayDimension); } subFeature = subFeature.GetNextSubFeature(); } } else { subFeature = feature.GetFirstSubFeature(); while (subFeature != null) { featureNames.Add("-> SubFeature: " + subFeature.GetTypeName2()); subFeature = subFeature.GetNextSubFeature(); } } feature = feature.GetNextFeature(); } this.textBox.AppendText("\n====== Start ======\n"); this.textBox.AppendText("File path: " + fileName + "\n"); this.textBox.AppendText(String.Join("\n", featureNames)); this.textBox.AppendText("\n====== End ======\n"); } swApp.ExitApp(); }
public void CheckAndUpdateGaugeNotes2() { String currPage = swDraw.GetCurrentSheet().ToString(); Int32 shtCount = swDraw.GetSheetCount(); String[] shtName = (String[])swDraw.GetSheetNames(); for (int page = 0; page < shtCount; page++) { swFrame.SetStatusBarText(String.Format("Activating page {0}...", shtName[page])); swDraw.ActivateSheet(shtName[page]); swView = (View)swDraw.GetFirstView(); while (swView != null) { swDispDim = swView.GetFirstDisplayDimension5(); while (swDispDim != null) { swDim = (Dimension)swDispDim.GetDimension2(0); swFrame.SetStatusBarText(String.Format("Processing '{0}' => '{1}'...", swDim.Name, swDim.Value.ToString())); string dimtext = swDispDim.GetText((Int32)swDimensionTextParts_e.swDimensionTextCalloutBelow); dimtext = dimtext.Replace(@"(", string.Empty).Replace(@")", string.Empty).Trim(); if (gaugeRegex.IsMatch(dimtext)) { string[] texts_ = dimtext.Split(' '); gaugeNote = Regex.Replace(texts_[texts_.Length - 1], "[0-9]", string.Empty); Double og; if (!Double.TryParse(swDim.GetSystemValue2("").ToString(), out og)) { throw new GaugeSetterException("Couldn't parse dimension value."); } ourGauge = og / 0.0254; for (int i = 0; i < Gauges.Gauge.Length; i++) { Double dCellVal; if (!Double.TryParse(Gauges.Gauge[i].Thickness, out dCellVal)) { throw new GaugeSetterException("Couldn't parse gauge thickness."); } else if (Math.Abs(ourGauge - dCellVal) < 0.00003) { String gaugeCell = String.Empty; String gaugeString = String.Empty; gaugeNotFound = false; swDispDim.ShowParenthesis = true; gaugeString = String.Format("{0} {1}", Gauges.Gauge[i].GaugeNumber, gaugeNote.ToUpper()); swDispDim.SetText((int)swDimensionTextParts_e.swDimensionTextCalloutBelow, gaugeString); } } if (gaugeNotFound) { if (!APathSet.SilenceGaugeErrors) { StringBuilder sb = new StringBuilder("Non-standard gauge thickness detected:\n"); sb.AppendFormat(get_format_txt(), swDim.Name, swView.Name, ourGauge); swApp.SendMsgToUser2(sb.ToString() , (int)swMessageBoxIcon_e.swMbWarning , (int)swMessageBoxBtn_e.swMbOk); } gaugeNotFound = false; } } swDispDim = swDispDim.GetNext5(); } swView = (View)swView.GetNextView(); } } swDraw.ActivateSheet(currPage); if (gaugeNotFound) // Why waste time rebuilding? { swFrame.SetStatusBarText("Rebuilding"); swDraw.ForceRebuild(); } swFrame.SetStatusBarText(String.Empty); }