public bool MergeDWG(string SourcePath, EntityFilter filter = null) { if (File.Exists(SourcePath)) { BlockHelper TargetSpace = BlockMgr.ModelSpace; //目标DWG模型空间 TargetSpace.StartTransaction(); //开启事务 using (Database SourceDB = new Database(false, false)) { SourceDB.ReadDwgFile(SourcePath, FileShare.Read, false, null); BlockTableRecord SourceBtr = SourceDB.CurrentSpaceId.GetObject(OpenMode.ForRead) as BlockTableRecord;//来源DWG模型空间 foreach (ObjectId ObjId in SourceBtr) { Entity ent = ObjId.GetObject(OpenMode.ForRead) as Entity; if (filter == null || filter.Check(ent)) { TargetSpace.CloneEntity(ent); } } } TargetSpace.CommitTransaction();//提交事务 return(true); } else { Logger.log("MergeDWG", "DWG文件不存在"); } return(false); }
public static void consulta(string IdSesion) { Console.Clear(); Console.WriteLine("Escriba el id sobre el que consultar las operaciones"); var IdConsulta = Console.ReadLine(); IdConsulta = conversion(IdConsulta); var objetoId = new ObjId(IdConsulta); Console.Clear(); var streamS = new MemoryStream(); var conversor = new DataContractJsonSerializer(typeof(ObjId)); conversor.WriteObject(streamS, objetoId); streamS.Position = 0; var leido = new StreamReader(streamS); var JsonFinal = leido.ReadToEnd(); leido.Close(); var res = new respuesta(); var salida = res.responder($"{servidor}/Calculator/Journal", JsonFinal, IdSesion); var SalidaOperaciones = deserializeResponse.DeserializeResponseYConvertir(salida); Console.Clear(); ImprimirDatos(SalidaOperaciones); continuar(); }
/// <summary> /// /// </summary> protected override void DoWork(CodeActivityContext context) { int objId = ObjId.Get(context); string template = Template.Get(context); EscribeOperations.MergeInboundDocument(objId, template); }
public VarList AddObj(ObjId val) { VarType item = VarType.Obj; int count = _objs.Count; _types.Add(item); _indexs.Add(count); _objs.Add(val); Count++; return(this); }
public JsonResult Journal([FromBody] ObjId EviId) { if (System.IO.File.Exists($"Journal\\{EviId.id}.txt")) { return(Json(JournalModel.PedirJournal(EviId.id))); } else { return(ErrorDatos("No existen datos de ese usuario")); } }
/// <summary> /// TODO /// </summary> /// <returns></returns> public string PrintInfo(bool supressPartName, int count = 0) { var acCurDb = Application.DocumentManager.MdiActiveDocument.Database; //Get variables to strings var countStr = count.ToString(); var objIdStr = ObjId.ToString(); var lengthStr = acCurDb.ConvertToDwgUnits(Length); var widthStr = acCurDb.ConvertToDwgUnits(Width); var thickStr = acCurDb.ConvertToDwgUnits(Thickness); var volStr = acCurDb.ConvertToDwgUnits(Volume); var asymStr = Asymmetry.RoundToTolerance(); //Remove parenthesis from ObjIds objIdStr = objIdStr.Replace("(", string.Empty); objIdStr = objIdStr.Replace(")", string.Empty); if (count < 10) { countStr = "0" + countStr; } var prntStr = string.Empty; if (count > 0) { prntStr += count + ":"; } if (!supressPartName) { if (!string.IsNullOrEmpty(RcName)) { prntStr += RcName; } else { prntStr += " #" + objIdStr; } } prntStr += " - L:" + lengthStr + " W:" + widthStr + " T:" + thickStr + " V:" + volStr + " A:" + asymStr + " [" + AsymVStr(AsymmetryVector) + "] P:" + ProdType; //Print to the current editor return(prntStr); }
private static int AccessibleObjectFromWindow(IntPtr hWnd, ObjId idObject, ref IAccessible acc) { var guid = new Guid("{618736e0-3c3d-11cf-810c-00aa00389b71}"); object obj = null; var num = AccessibleObjectFromWindow(hWnd, (uint)idObject, ref guid, ref obj); acc = (IAccessible)obj; return(num); }
public void ExtractAttributesStart() { #region Init local vars List <Block> OriginalBlockDefs = new List <Block>(); List <Block> OriginalBlockRefs = new List <Block>(); SortedList <string, double> AttsTotals = new SortedList <string, double>(); ObjectIdCollection OrigBlockRefsIds = new ObjectIdCollection(); ObjectIdCollection OrigBlockDefsIds = new ObjectIdCollection(); Document Doc = Application.DocumentManager.MdiActiveDocument; Database Db = Doc.Database; Editor Ed = Doc.Editor; char[] badChars = { '\'', ' ', '-', '`', '~', '"', '_' }; string dateFormat = "yyyy.MM.dd_HH.mm.ss"; string[] stringSeparators = new string[] { "\\" }; string[] fileNameExploded = Db.Filename.Split(stringSeparators, StringSplitOptions.None); string outputFileName = fileNameExploded[fileNameExploded.Length - 2] + "." + DateTime.Now.ToString(dateFormat) + ".xls"; string outputDir = Db.Filename.Remove(Db.Filename.LastIndexOf("\\") + 1); ExcelDocument document = new ExcelDocument(); document.UserName = Environment.UserName; document.CodePage = CultureInfo.CurrentCulture.TextInfo.ANSICodePage; document.ColumnWidth(0, 120); document.ColumnWidth(1, 80); int XLSrows = 0; int XLScols = 0; document.WriteCell(XLSrows, 4, fileNameExploded[fileNameExploded.Length - 2]); XLSrows += 3; #endregion #region Prompt user for BlockRefs and dwg file/dir opts PromptEntityOptions PromptForBlocksOpts = new PromptEntityOptions("\nSelect single block"); PromptForBlocksOpts.SetRejectMessage("\nYou can select blocks only."); PromptForBlocksOpts.AddAllowedClass(typeof(BlockReference), true); PromptForBlocksOpts.AllowNone = true; PromptEntityResult PromptForBlocksRes = Ed.GetEntity(PromptForBlocksOpts); if (PromptForBlocksRes.Status == PromptStatus.Cancel) { return; } // Prompt the user for blocks while (PromptForBlocksRes.Status == PromptStatus.OK) { using (Transaction Tr = Db.TransactionManager.StartTransaction()) { BlockReference Bref = (BlockReference)Tr.GetObject(PromptForBlocksRes.ObjectId, OpenMode.ForRead); Bref.Highlight(); // highlight the selected BlockReference OrigBlockRefsIds.Add(PromptForBlocksRes.ObjectId); // extract the BlockTableRecord from the BlockReference BlockTableRecord Btr = (BlockTableRecord)Tr.GetObject(Bref.BlockTableRecord, OpenMode.ForRead); bool BlockIsAlreadyIn = false; foreach (Block BlockDef in OriginalBlockDefs) { if (BlockDef.Name == Btr.Name) { BlockIsAlreadyIn = true; } } if (!BlockIsAlreadyIn) { StringCollection AttributeTags = new StringCollection(); StringBuilder Atts = new StringBuilder(); foreach (ObjectId ObjId in Btr) { AttributeDefinition attDef = ObjId.GetObject(OpenMode.ForRead) as AttributeDefinition; if (attDef != null) { Atts.Append(attDef.Tag + ";"); AttributeTags.Add(attDef.Tag); } } if (AttributeTags.Count > 0) { OriginalBlockDefs.Add(new Block(Btr.Name)); OriginalBlockDefs[OriginalBlockDefs.Count - 1].AttributeTags = AttributeTags; XLScols = 1; foreach (string AttTag in AttributeTags) { document.WriteCell(XLSrows, XLScols, AttTag); XLScols++; } XLSrows++; } else // If a Block Def does not contain AttributeDefs - it is excluded { //ProcLogger.WriteToLog( "Block Definition ;" + Btr.Name + " was excluded becase it has no attributes" ); } } else { //ProcLogger.WriteToLog( "Block Definition not imported : ; already in." ); } Tr.Commit(); } #region If the user presses cancel in the middle //unhighlight all Block References and flush the collections PromptForBlocksRes = Ed.GetEntity(PromptForBlocksOpts); if (PromptForBlocksRes.Status == PromptStatus.Cancel) { using (Transaction Tr = Db.TransactionManager.StartTransaction()) { foreach (ObjectId BlockRefId in OrigBlockRefsIds) { BlockReference Bref = (BlockReference)Tr.GetObject(BlockRefId, OpenMode.ForWrite); Bref.Unhighlight(); Bref.DowngradeOpen(); } OriginalBlockDefs.Clear(); OriginalBlockRefs.Clear(); Tr.Commit(); } return; } #endregion } #region Unhighlight all entities and get their BlockTableRecords ObjectIds using (Transaction Tr = Db.TransactionManager.StartTransaction()) { foreach (ObjectId BlockRefId in OrigBlockRefsIds) { BlockReference Bref = (BlockReference)Tr.GetObject(BlockRefId, OpenMode.ForRead); Bref.Unhighlight(); } Tr.Commit(); } #endregion #region prompt for file or dir option PromptKeywordOptions KeywordsOpts = new PromptKeywordOptions("Scan current DWG or all files in DWGs dir?"); KeywordsOpts.AllowArbitraryInput = false; KeywordsOpts.AllowNone = false; KeywordsOpts.Keywords.Add("File"); KeywordsOpts.Keywords.Add("Dir"); PromptResult FileOrDirRes = Ed.GetKeywords(KeywordsOpts); // If the user pressed cancel - return with no error if (FileOrDirRes.Status != PromptStatus.OK) { return; } List <string> Files = new List <string>(); string[] tempFiles; if (FileOrDirRes.StringResult == "Dir") { string currFile = Db.Filename; string currDir = currFile.Remove(currFile.LastIndexOf("\\") + 1); tempFiles = Directory.GetFiles(currDir, "*.dwg", SearchOption.AllDirectories); foreach (string tempFile in tempFiles) { Files.Add(tempFile); } } else { Files.Add(Db.Filename); } // return; #endregion #endregion #region Traverse Dwgs and extract raw data Database UnopenedDb; Files.Sort(); // Open every file foreach (string file in Files) { document.WriteCell(XLSrows, 0, file.Remove(0, file.LastIndexOf("\\") + 1)); if (!file.EndsWith(".dwg", StringComparison.CurrentCultureIgnoreCase)) { continue; } // Open the Db from the file using (UnopenedDb = new Database(false, false)) { if (Db.Filename != file) { UnopenedDb.ReadDwgFile(file, FileShare.Read, true, ""); } else { UnopenedDb = Db; } List <string> AppendedTags = new List <string>(); List <StringCollection> AttributeValues = new List <StringCollection>(); // open transaction to the db using (Transaction Tr = UnopenedDb.TransactionManager.StartTransaction()) { try { // Get the BlockTable BlockTable Bt = (BlockTable)Tr.GetObject(UnopenedDb.BlockTableId, OpenMode.ForRead); // Traverse all the layouts for Block References foreach (ObjectId ObjId in Bt) { BlockTableRecord LayoutBtr = (BlockTableRecord)Tr.GetObject(ObjId, OpenMode.ForRead); if (LayoutBtr.IsLayout) { Layout currLayout = (Layout)Tr.GetObject(LayoutBtr.LayoutId, OpenMode.ForRead); if (!currLayout.LayoutName.Contains("Model")) { document.WriteCell(XLSrows++, 0, currLayout.LayoutName); } foreach (ObjectId LayoutObjId in LayoutBtr) { BlockReference Bref = Tr.GetObject(LayoutObjId, OpenMode.ForRead) as BlockReference; // Dont tuch this! if (Bref != null) { StringCollection AttRefValuesForXLS = new StringCollection(); foreach (Block BDef in OriginalBlockDefs) { if (Bref.Name == BDef.Name) { for (int i = 0; i < Bref.AttributeCollection.Count; i++) { AttributeReference AttRef = (AttributeReference)Tr.GetObject(Bref.AttributeCollection[i], OpenMode.ForRead); AttRefValuesForXLS.Add(AttRef.TextString.Trim(badChars).Trim()); continue; } AttributeValues.Add(AttRefValuesForXLS); } } } } #region // bubble sort the attributes by PartNr string tempAA = ""; string tempBB = ""; int tempA = 0; int tempB = 0; bool parseAIsOk = false; bool parseBIsOk = false; Match MatchA; Match MatchB; //string AlphaPattern = @"[a-z]|[A-Z]"; string NumericPattern = @"[0-9]+"; try { if (AttributeValues.Count > 1) { for (int j = 0; j < AttributeValues.Count; j++) { for (int i = 1; i < AttributeValues.Count; i++) { tempBB = AttributeValues[i][0] = AttributeValues[i][0]; tempAA = AttributeValues[i - 1][0] = AttributeValues[i - 1][0]; MatchA = Regex.Match(tempAA, NumericPattern); MatchB = Regex.Match(tempBB, NumericPattern); parseAIsOk = Int32.TryParse(MatchA.ToString(), out tempA); parseBIsOk = Int32.TryParse(MatchB.ToString(), out tempB); if (parseAIsOk && parseBIsOk) { if (tempA > tempB) { StringCollection temp = AttributeValues[i]; AttributeValues[i] = AttributeValues[i - 1]; AttributeValues[i - 1] = temp; } } } } } } catch (System.Exception Ex) { Ed.WriteMessage(Ex.Message + Ex.Source + Ex.StackTrace); } #endregion #region Parse and write the attribute collection to XLS file try { foreach (StringCollection BlockRefAttValues in AttributeValues) { if (!AttsTotals.Keys.Contains(BlockRefAttValues[4])) { double value; if (Double.TryParse(BlockRefAttValues[2], out value)) { AttsTotals.Add(BlockRefAttValues[4], value); } else { AttsTotals.Add(BlockRefAttValues[4], 0); } } else { double value; double z; if (Double.TryParse(BlockRefAttValues[2], out value)) { z = value; } else { z = 0; } double x; if (Double.TryParse(BlockRefAttValues[4], out value)) { x = value; } else { x = 0; } //double total = AttsTotals[BlockRefAttValues[4]]; //AttsTotals[BlockRefAttValues[4]] = total + z + x; AttsTotals[BlockRefAttValues[4]] += z + x; } XLScols = 1; foreach (string AttVal in BlockRefAttValues) { string tmp = AttVal; double tempInt = 0; if (Double.TryParse(tmp, out tempInt)) { document.WriteCell(XLSrows, XLScols, tempInt); } else { document.WriteCell(XLSrows, XLScols, tmp); } XLScols++; } XLSrows++; } } catch (System.Exception Ex) { MessageBox.Show(Ex.Message + "\n" + Ex.Source + "\n" + Ex.StackTrace); } #endregion AttributeValues.Clear(); } } } catch (System.Exception Ex) { Ed.WriteMessage(Ex.Message + Ex.Source + Ex.StackTrace); } } } XLSrows += 3; }// foreach ( file in files ) try { document.WriteCell(XLSrows, 5, "Parts"); document.WriteCell(XLSrows, 3, "Totals"); XLSrows++; foreach (KeyValuePair <string, double> Total in AttsTotals) { //document.WriteCell(XLSrows, 5, Total.Key.ToString()); document.WriteCell(XLSrows, 5, Total.Key); double value; if (Double.TryParse(Total.Value.ToString(), out value)) { document.WriteCell(XLSrows, 3, value); } else { document.WriteCell(XLSrows, 3, Total.Value.ToString()); } document.WriteCell(XLSrows, 4, "Stk"); XLSrows++; } } catch (System.Exception Ex) { MessageBox.Show(Ex.Message + "\n" + Ex.Source + "\n" + Ex.StackTrace); } FileStream stream = new FileStream(outputDir + outputFileName, FileMode.Create); document.Save(stream); stream.Close(); #endregion }
public static extern int GetScrollBarInfo(IntPtr hWnd, ObjId idObject, ref SCROLLBARINFO psbi);
public static bool ResizeRect( object obj, Vector2 mousePos, ref Rect rect, int border = 6, Vector2 minSize = new Vector2()) { bool resized = false; Rect leftRect = new Rect(rect.x - border / 2, rect.y + border, border, rect.height - border * 2); Rect zoomedRect = UI.current.scrollZoom == null ? leftRect : UI.current.scrollZoom.ToScreen(leftRect.position, leftRect.size); UnityEditor.EditorGUIUtility.AddCursorRect(zoomedRect, UnityEditor.MouseCursor.ResizeHorizontal); ObjId obj1 = new ObjId(obj, 1); if (TryDrag(obj1, mousePos)) { rect.x = (initialRect).position.x + totalDelta.x; rect.width = (initialRect).width - totalDelta.x; if (rect.width < minSize.x) { rect.x = (initialRect).xMax - minSize.x; rect.width = minSize.x; } resized = true; } if (TryRelease(obj1, mousePos)) { resized = true; } if (TryStart(obj1, mousePos, leftRect)) { initialRect = rect; resized = true; } //re-assigning initial rect to full one, not left rect Rect rightRect = new Rect(rect.x - border / 2 + rect.width, rect.y + border, border, rect.height - border * 2); zoomedRect = UI.current.scrollZoom == null ? rightRect : UI.current.scrollZoom.ToScreen(rightRect.position, rightRect.size); UnityEditor.EditorGUIUtility.AddCursorRect(zoomedRect, UnityEditor.MouseCursor.ResizeHorizontal); ObjId obj2 = new ObjId(obj, 2); if (TryDrag(obj2, mousePos)) { rect.width = initialRect.width + totalDelta.x; if (rect.width < minSize.x) { rect.width = minSize.x; } resized = true; } if (TryRelease(obj2, mousePos)) { resized = true; } if (TryStart(obj2, mousePos, rightRect)) { initialRect = rect; resized = true; } Rect topRect = new Rect(rect.x + border, rect.y - border / 2, rect.width - border * 2, border); zoomedRect = UI.current.scrollZoom == null ? topRect : UI.current.scrollZoom.ToScreen(topRect.position, topRect.size); UnityEditor.EditorGUIUtility.AddCursorRect(zoomedRect, UnityEditor.MouseCursor.ResizeVertical); ObjId obj3 = new ObjId(obj, 3); if (TryDrag(obj3, mousePos)) { rect.y = initialRect.position.y + totalDelta.y; rect.height = initialRect.height - totalDelta.y; if (rect.height < minSize.y) { rect.y = initialRect.yMax - minSize.y; rect.height = minSize.y; } resized = true; } if (TryRelease(obj3, mousePos)) { resized = true; } if (TryStart(obj3, mousePos, topRect)) { initialRect = rect; resized = true; } Rect bottomRect = new Rect(rect.x + border, rect.y - border / 2 + rect.height, rect.width - border * 2, border); zoomedRect = UI.current.scrollZoom == null ? bottomRect : UI.current.scrollZoom.ToScreen(bottomRect.position, bottomRect.size); UnityEditor.EditorGUIUtility.AddCursorRect(zoomedRect, UnityEditor.MouseCursor.ResizeVertical); ObjId obj4 = new ObjId(obj, 4); if (TryDrag(obj4, mousePos)) { rect.height = initialRect.height + totalDelta.y; if (rect.height < minSize.y) { rect.height = minSize.y; } resized = true; } if (TryRelease(obj4, mousePos)) { resized = true; } if (TryStart(obj4, mousePos, bottomRect)) { initialRect = rect; resized = true; } Rect topLeftRect = new Rect(rect.x - border, rect.y - border, border * 2, border * 2); zoomedRect = UI.current.scrollZoom == null ? topLeftRect : UI.current.scrollZoom.ToScreen(topLeftRect.position, topLeftRect.size); UnityEditor.EditorGUIUtility.AddCursorRect(zoomedRect, UnityEditor.MouseCursor.ResizeUpLeft); ObjId obj5 = new ObjId(obj, 5); if (TryDrag(obj5, mousePos)) { rect.position = initialRect.position + totalDelta; rect.size = initialRect.size - totalDelta; if (rect.width < minSize.x) { rect.x = initialRect.xMax - minSize.x; rect.width = minSize.x; } if (rect.height < minSize.y) { rect.y = initialRect.yMax - minSize.y; rect.height = minSize.y; } resized = true; } if (TryRelease(obj5, mousePos)) { resized = true; } if (TryStart(obj5, mousePos, topLeftRect)) { initialRect = rect; resized = true; } Rect topRightRect = new Rect(rect.x - border + rect.width, rect.y - border, border * 2, border * 2); zoomedRect = UI.current.scrollZoom == null ? topRightRect : UI.current.scrollZoom.ToScreen(topRightRect.position, topRightRect.size); UnityEditor.EditorGUIUtility.AddCursorRect(zoomedRect, UnityEditor.MouseCursor.ResizeUpRight); ObjId obj6 = new ObjId(obj, 6); if (TryDrag(obj6, mousePos)) { rect.position = initialRect.position + new Vector2(0, totalDelta.y); rect.size = initialRect.size + new Vector2(totalDelta.x, -totalDelta.y); if (rect.width < minSize.x) { rect.width = minSize.x; } if (rect.height < minSize.y) { rect.y = initialRect.yMax - minSize.y; rect.height = minSize.y; } resized = true; } if (TryRelease(obj6, mousePos)) { resized = true; } if (TryStart(obj6, mousePos, topRightRect)) { initialRect = rect; resized = true; } Rect bottomLeftRect = new Rect(rect.x - border, rect.y - border + rect.height, border * 2, border * 2); zoomedRect = UI.current.scrollZoom == null ? bottomLeftRect : UI.current.scrollZoom.ToScreen(bottomLeftRect.position, bottomLeftRect.size); UnityEditor.EditorGUIUtility.AddCursorRect(zoomedRect, UnityEditor.MouseCursor.ResizeUpRight); ObjId obj7 = new ObjId(obj, 7); if (TryDrag(obj7, mousePos)) { rect.position = initialRect.position + new Vector2(totalDelta.x, 0); rect.size = initialRect.size + new Vector2(-totalDelta.x, totalDelta.y); if (rect.width < minSize.x) { rect.x = initialRect.xMax - minSize.x; rect.width = minSize.x; } if (rect.height < minSize.y) { rect.height = minSize.y; } resized = true; } if (TryRelease(obj7, mousePos)) { resized = true; } if (TryStart(obj7, mousePos, bottomLeftRect)) { initialRect = rect; resized = true; } Rect bottomRightRect = new Rect(rect.x - border + rect.width, rect.y - border + rect.height, border * 2, border * 2); zoomedRect = UI.current.scrollZoom == null ? bottomRightRect : UI.current.scrollZoom.ToScreen(bottomRightRect.position, bottomRightRect.size); UnityEditor.EditorGUIUtility.AddCursorRect(zoomedRect, UnityEditor.MouseCursor.ResizeUpLeft); ObjId obj8 = new ObjId(obj, 8); if (TryDrag(obj8, mousePos)) { rect.size = initialRect.size + totalDelta; if (rect.width < minSize.x) { rect.width = minSize.x; } if (rect.height < minSize.y) { rect.height = minSize.y; } resized = true; } if (TryRelease(obj8, mousePos)) { resized = true; } if (TryStart(obj8, mousePos, bottomRightRect)) { initialRect = rect; resized = true; } return(resized); }
public static extern int AccessibleObjectFromWindow(IntPtr hwnd, ObjId id, ref Guid iid, ref IAccessible ppvObject);