private void Configurer(Component2 composant, Double ag1, Double ag2, Double lg, Feature esquisse) { if (esquisse.IsRef()) { DisplayDimension DispDim = (DisplayDimension)esquisse.GetFirstDisplayDimension(); while (DispDim.IsRef()) { Dimension D = (Dimension)DispDim.GetDimension(); if (D.Name == Ag1) { D.SetSystemValue3(ag1, (int)swSetValueInConfiguration_e.swSetValue_InThisConfiguration, null); } else if (D.Name == Ag2) { D.SetSystemValue3(ag2, (int)swSetValueInConfiguration_e.swSetValue_InThisConfiguration, null); } else if (D.Name == Lg) { D.SetSystemValue3(lg, (int)swSetValueInConfiguration_e.swSetValue_InThisConfiguration, null); } DispDim = (DisplayDimension)esquisse.GetNextDisplayDimension(DispDim); } } else { this.LogMethode(new String[] { "Ne trouve pas la fonction d'esquisse" }); } }
public override void Select(bool append) { if (!DisplayDimension.IGetAnnotation().Select3(append, null)) { throw new Exception("Failed to select dimension"); } }
/// <summary> /// Gets the dimensions in the active model /// </summary> /// <returns></returns> public DesignCapture GetDimensions() { var designCapture = new DesignCapture(); var featureSubTypes = typeof(FeatureSubTypes).GetConstants() .Where(x => x.GetCategoryAttribute() == FeatureSubTypeCategories.Body || x.GetCategoryAttribute() == FeatureSubTypeCategories.SheetMetal || x.GetCategoryAttribute() == FeatureSubTypeCategories.Weldment || x.GetCategoryAttribute() == FeatureSubTypeCategories.Component) .Select(x => x.GetValue(x).ToString()); Feature feature = _doc.FirstFeature(); while (feature != null) { Feature subFeature = feature.GetFirstSubFeature(); while (subFeature != null) { DisplayDimension disDimSubFeature = subFeature.GetFirstDisplayDimension(); while (disDimSubFeature != null) { Dimension dimSubFeature = disDimSubFeature.GetDimension(); designCapture.AddDim(new DimensionCapture(dimSubFeature.FullName, dimSubFeature.Value)); disDimSubFeature = subFeature.GetNextDisplayDimension(disDimSubFeature); } subFeature = subFeature.GetNextSubFeature(); } DisplayDimension disdim = feature.GetFirstDisplayDimension(); while (disdim != null) { Dimension dim = disdim.GetDimension(); designCapture.AddDim(new DimensionCapture(dim.FullName, dim.Value)); disdim = feature.GetNextDisplayDimension(disdim); } var featureType = feature.GetTypeName(); var name = feature.Name; if (featureSubTypes.Any(x => x == featureType)) { designCapture.Features.Add(new FeatureCapture(name, featureType, feature.IsSuppressed())); } feature = feature.GetNextFeature(); } return(designCapture); }
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); }
void dimensionH(double value, string text = "") { DisplayDimension dispDim = Model.AddHorizontalDimension2(0, 10 * mm, 10 * mm); string name = dispDim.GetNameForSelection(); dispDim.CenterText = true; Dimension Dim = Dimensions[iDimensions++] = Model.Parameter(name); if (text != "") { Dim.Name = text; } Dim.SystemValue = value * mm; }
private void addDimList(Feature ft, List <string> dimlist) { do { DisplayDimension swDispDim = ft.GetFirstDisplayDimension() as DisplayDimension; if (swDispDim != null) { do { //Annotation swAnn = swDispDim.GetAnnotation() as Annotation; Dimension swDim = swDispDim.GetDimension() as Dimension; dimlist.Add(swDim.FullName); swDispDim = ft.GetNextDisplayDimension(swDispDim) as DisplayDimension; } while (swDispDim != null); } ft = ft.GetNextSubFeature() as Feature; } while (ft != null); }
void dimensionR(double angle, string text = "") { if (angle < 0) { angle = 180 - abs(angle); } DisplayDimension dispDim = Model.AddDimension2(0, 10 * mm, 10 * mm); string name = dispDim.GetNameForSelection(); dispDim.CenterText = true; Dimension Dim = Dimensions[iDimensions++] = Model.Parameter(name); if (text != "") { Dim.Name = text; } Dim.SystemValue = angle * pi / 180; }
// BendRadius is in mm public bool BendRadius(double BendRadius) { DisplayDimension swDisplayDimension = (DisplayDimension)swFeat.GetFirstDisplayDimension(); while (swDisplayDimension != null) { // the radius dimension is radial or diametric if (swDisplayDimension.GetType() == (int)swDimensionType_e.swRadialDimension || swDisplayDimension.GetType() == (int)swDimensionType_e.swDiameterDimension) { Dimension swDimension = (Dimension)swDisplayDimension.GetDimension(); int retval = swDimension.SetSystemValue2(BendRadius / 1000.0, 0); if (retval == 0) return true; return false; } // Get next dimension swDisplayDimension = (DisplayDimension)swFeat.GetNextDisplayDimension(swDisplayDimension); } return false; }
private void ChangeDimConfigurations(Feature ft) { DisplayDimension swDispDim = ft.GetFirstDisplayDimension() as DisplayDimension; if (swDispDim != null) { do { //Annotation swAnn = swDispDim.GetAnnotation() as Annotation; Dimension swDim = swDispDim.GetDimension() as Dimension; if (!swDim.ReadOnly) { swDim.SetSystemValue3(swDim.SystemValue, 1, null); } //swDim.SetValue3(swDim.Value , 1, null); //System.Windows.Forms.MessageBox.Show(swDim.Value.ToString()); swDispDim = ft.GetNextDisplayDimension(swDispDim) as DisplayDimension; } while (swDispDim != null); } }
/// <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()); }
// Thickness is in mm public bool Thickness(double Thickness) { DisplayDimension swDisplayDimension = (DisplayDimension)swFeat.GetFirstDisplayDimension(); while (swDisplayDimension != null) { // the display dimension of the thickness is not radial or diametric if (swDisplayDimension.GetType() != (int)swDimensionType_e.swRadialDimension && swDisplayDimension.GetType() != (int)swDimensionType_e.swDiameterDimension) { Dimension swDimension = (Dimension)swDisplayDimension.GetDimension(); // thickness dimension has reference points and a direction if (swDimension.ReferencePoints != null) { object[] swMathPointsObj = (object[])swDimension.ReferencePoints; foreach (object swMathPointObj in swMathPointsObj) { MathPoint swMathPoint = (MathPoint)swMathPointObj; if (!IsPointZero(swMathPoint)) { int retval = swDimension.SetSystemValue2(Thickness / 1000.0, 0); if (retval == 0) return true; return false; } } } } // Get next dimension swDisplayDimension = (DisplayDimension)swFeat.GetNextDisplayDimension(swDisplayDimension); } return false; }
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); }
public static void DimensionWith(this SketchLine l1, SketchLine l2, string linkName, SldWorks swApp) { ModelDoc2 swDoc = (ModelDoc2)swApp.ActiveDoc; bool bl = false; swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, false); swDoc.ClearSelection2(true); bl = ((SketchSegment)l1).Select(false); bl = ((SketchSegment)l2).Select(true); Point textPoint = new Point((l1.toLine().Start.X + l2.toLine().Start.X) / 2, (l1.toLine().Start.Y + l2.toLine().Start.Y) / 2, (l1.toLine().Start.Z + l2.toLine().Start.Z) / 2); DisplayDimension disDim = swDoc.AddDimension2(textPoint.X, textPoint.Y, 0); disDim.SetLinkedText("" + linkName + ""); swDoc.ClearSelection2(true); swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate, true); }
private bool FoundParamsOfCuvites(out Annotation annH, out DisplayDimension swDispDimH) { bool ret = false; annH = null; var swDrawing = (DrawingDoc)_swModel; int i = 0; do { using (var a = new GetDimensions()) { swDispDimH = a.GetDisplayDim(swDrawing, _ent, _swSelData); } i++; } while (swDispDimH == null && i < 3); if (swDispDimH != null) { var dimObjH = (Dimension)swDispDimH.GetDimension(); string holeDepSuffix = swDispDimH.GetText((int)swDimensionTextParts_e.swDimensionTextPrefix); if (dimObjH != null) { double diam = Convert.ToDouble(Strings.Left(holeDepSuffix, 1) == "R" ? (dimObjH.Value * 2).ToString("0.00") : (dimObjH.Value).ToString("0.00")); var holeDepSuffix1 = swDispDimH.GetText((int)swDimensionTextParts_e.swDimensionTextSuffix); if (string.IsNullOrEmpty(holeDepSuffix1) && !string.IsNullOrEmpty(holeDepSuffix)) { var tt =holeDepSuffix.Split(new string[1]{"<HOLE-DEPTH>"},5,StringSplitOptions.RemoveEmptyEntries); if (tt.Length>=2) holeDepSuffix1 = "<HOLE-DEPTH> " + tt[1]; } double depth; try { string holeDepSuffixAbridgement = Strings.Right(holeDepSuffix1, holeDepSuffix1.Length - 12); depth = Convert.ToDouble(holeDepSuffixAbridgement.Replace('.', ',')); } catch { try { string holeDepSuffixAbridgement = Strings.Right(holeDepSuffix1, holeDepSuffix1.Length - 12); depth = Convert.ToDouble(holeDepSuffixAbridgement); } catch { depth = 0; } } int drType = 7; var swView = swDrawing.IActiveDrawingView; if (swView != null) drType = swView.Type; bool type = drType == 4; var diamAndDepth = SetManualDiametrAndDepth(diam, depth, type); if (_doThroughHoles || diamAndDepth.Y != 0)//if (_side.AsBoolean() || diamAndDepth.Y != 0) // насколько я понимаю, только этот if определяет, указывать ли сквознае отверстия { StrType = GetStringHoleType(diamAndDepth.X, diamAndDepth.Y); _holeType = DefinitionHolesType(diamAndDepth.X, diamAndDepth.Y); annH = swDispDimH.IGetAnnotation(); ret = true; } else { swDispDimH.IGetAnnotation().Select(true); _swModel.DeleteSelection(true); } } } _swModel.ClearSelection(); return ret; }
private static double SetPositionHole(Annotation annotation, DisplayDimension displayDimension, Ordinate vertex, double x, double vScale, double[] boundBox, int numbers, string type, int posNumb, bool side) { string newstring; if (type.Contains("8.11h")) newstring = Convert.ToString(numbers + " отв. " + "<MOD-DIAM>" + "8" + type.Substring(type.IndexOf('h'))); else { if (type.Contains("7,33")) newstring = Convert.ToString(numbers + " отв. по схеме A25SK"); else newstring = Convert.ToString(numbers + " отв. " + "<MOD-DIAM>" + type); if (type.Contains("накернить")) newstring = Convert.ToString(numbers + " отв. накернить"); } displayDimension.SetText((int)swDimensionTextParts_e.swDimensionTextAll, newstring); if (side) annotation.SetPosition(vertex.X + x / 1000 / vScale, boundBox[1] - 0.004 * posNumb, 0); else annotation.SetPosition(vertex.X - x / 1000 / vScale, boundBox[1] - 0.004 * posNumb, 0); int textCount = newstring.Length; return (((double[])annotation.GetPosition())[0] + textCount * 0.001); }
public CoordH(double inX, double inY, Annotation inAnnH, DisplayDimension inDispDim) { X = inX; Y = inY; AnnH = inAnnH; DispDim = inDispDim; }
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); }
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 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); } } } }