/*2016.6.21 /// <summary> /// ModAtrMD5() - calculate MD5 of the model read from Tekla in ModAtr /// </summary> /// <remarks>It could take few minutes for the large model</remarks> public static string ModAtrMD5() { // DateTime t0 = DateTime.Now; string str = ""; foreach (var att in ModAtr) str += att.mat + att.prf + att.lng.ToString(); ModelMD5 = Lib.ComputeMD5(str); return ModelMD5; // new Log("MD5 time = " + (DateTime.Now - t0).ToString()); } // ModAtrMD5 2016.6.21 */ public static string GetTeklaDir(ModelDir mode) { string TSdir = ""; switch (mode) { case ModelDir.exceldesign: // 6/4/17 TeklaStructuresSettings.GetAdvancedOption("XS_EXTERNAL_EXCEL_DESIGN_PATH", ref TSdir); TSdir = "C:\\ProgramData\\Tekla Structures\\2016i\\\\environments\\common\\exceldesign\\"; break; case ModelDir.model: TSM.Model model = new TSM.Model(); ModInfo = model.GetInfo(); TSdir = ModInfo.ModelPath; break; case ModelDir.macro: TeklaStructuresSettings.GetAdvancedOption("XS_MACRO_DIRECTORY", ref TSdir); string[] str = TSdir.Split(';'); TSdir = str[0] + @"\modeling"; // this Split is to ignore other, than common TS Enviroments break; case ModelDir.environment: TSdir = GetTeklaDir(ModelDir.exceldesign); TSdir = Path.Combine(TSdir, @"..\.."); TSdir = Path.GetFullPath(TSdir); break; } ////////// var ff = TeklaStructuresInfo.GetCurrentProgramVersion(); ////////// var dd = TeklaStructuresFiles.GetAttributeFile(TSdir); ////////// TSdir = TS.TeklaStructuresFiles(); return TSdir; }
/// <summary> /// IsTeklaActice() - return true if TeklaStructures Process exists in Windows, and model is available /// </summary> /// <returns>true if Tekla is up and running</returns> public static bool isTeklaActive() { Log.set("isTeklaActive()"); bool ok = false; const string Tekla = "TeklaStructures"; foreach (Process clsProcess in Process.GetProcesses()) { if (clsProcess.ProcessName.ToLower().Contains(Tekla.ToLower())) { TSM.Model model = new TSM.Model(); if (!model.GetConnectionStatus()) goto error; try { ModInfo = model.GetInfo(); ok = model.GetConnectionStatus() && ModInfo.ModelName != ""; } catch { goto error; } break; } } Log.exit(); return ok; error: throw new Exception("isTeklaActive no model Connection"); }
public static string getModInfo() { string result = string.Empty; TSM.Model model = new TSM.Model(); ModInfo = model.GetInfo(); result = Path.GetFileNameWithoutExtension(ModInfo.ModelName); // if (!isTeklaModel(result)) Msg.F("TS_Open API getModInfo error"); return result; }
public List<Elm> Read(string dir = "", string name = "") { Log.set("TS_OpenAPI.Read"); List<Elm> elements = new List<Elm>(); ModInfo = model.GetInfo(); if (dir != "" && ModInfo.ModelPath != dir || name != "" && ModInfo.ModelName != String.Concat(name, ".db1")) Msg.F("Tekla.Read: Another model loaded, not", name); ModInfo.ModelName = ModInfo.ModelName.Replace(".db1", ""); dicParts = ReadModObj<TSM.Part>(); //20/11/17 ArrayList part_string = new ArrayList() { "MATERIAL", "MATERIAL_TYPE", "PROFILE" }; //20/11/17 ArrayList part_double = new ArrayList() { "LENGTH", "WEIGHT", "VOLUME" }; //20/11/17 ArrayList part_int = new ArrayList(); //20/11/17 Hashtable all_val = new Hashtable(); foreach (var part in dicParts) { Elm elm = new Elm(); elm.mat = part.Value.Material.MaterialString; elm.prf = part.Value.Profile.ProfileString; part.Value.GetReportProperty("LENGTH", ref elm.length); part.Value.GetReportProperty("WEIGHT", ref elm.weight); part.Value.GetReportProperty("VOLUME", ref elm.volume); part.Value.GetReportProperty("MATERIAL_TYPE", ref elm.mat_type); //////////////////double lng = 0, weight = 0, vol = 0; //////////////////var p = part.Value; //////////////////p.GetReportProperty("LENGTH", ref lng); //////////////////p.GetReportProperty("WEIGHT", ref weight); //////////////////p.GetReportProperty("VOLUME", ref vol); //////////////////elm.volume = vol; //////////////////elm.weight = weight; //////////////////elm.length = lng; //20/11/17 part.Value.GetAllReportProperties(part_string, part_double, part_int, ref all_val); //20/11/17 elm.mat = (string)all_val[part_string[0]]; //20/11/17elm.mat_type = (string)all_val[part_string[1]]; //20/11/17 elm.prf = (string)all_val[part_string[2]]; //20/11/17 elm.length = (double)all_val[part_double[0]]; //20/11/17elm.weight = (double)all_val[part_double[1]]; //20/11/17elm.volume = (double)all_val[part_double[2]]; elm.guid = part.Key; elements.Add(elm); } Scale(elements); elements.Sort(); Log.exit(); return elements; } // Read
/// <summary> /// isTeklaModel(name) -- check if Tekla open with the model name /// </summary> /// <param name="name"></param> /// <returns>true if in Tekla active and open model == name</returns> /// <history>5.6.2016</history> public static bool isTeklaModel(string name) { Log.set("TS_OpenAPI.isTeklaModel(\"" + name + "\")"); bool ok = false; if (isTeklaActive()) { TSM.Model model = new TSM.Model(); ModInfo = model.GetInfo(); name = Path.GetFileNameWithoutExtension(name); // ModInfo.ModelName = ModInfo.ModelName.Replace(".db1", ""); string inTS = Path.GetFileNameWithoutExtension(ModInfo.ModelName); ok = Path.GetFileNameWithoutExtension(ModInfo.ModelName) == name; } Log.exit(); return ok; }
public Tekla() { } // конструктор класса Tekla - пока пустой 6.4.17 public List<Elm> Read(string dir = "", string name = "") { Log.set("TS_OpenAPI.Read"); List<Elm> elements = new List<Elm>(); // 6.4.17 //TSM.Model model = new TSM.Model(); ////////////List<Part> parts = new List<Part>(); ModInfo = model.GetInfo(); if (dir != "" && ModInfo.ModelPath != dir || name != "" && ModInfo.ModelName != String.Concat(name, ".db1")) Msg.F("Tekla.Read: Another model loaded, not", name); ModInfo.ModelName = ModInfo.ModelName.Replace(".db1", ""); TSM.ModelObjectSelector selector = model.GetModelObjectSelector(); System.Type[] Types = new System.Type[1]; Types.SetValue(typeof(Part), 0); TSM.ModelObjectEnumerator objectList = selector.GetAllObjectsWithType(Types); int totalCnt = objectList.GetSize(); var progress = new TSM.Operations.Operation.ProgressBar(); bool displayResult = progress.Display(100, "TSmatch", "Reading model. Pass component records:", "Cancel", " "); int ii = 0; while (objectList.MoveNext()) { TSM.Part myPart = objectList.Current as TSM.Part; if (myPart != null) { ii++; double lng = 0.0; double weight = 0.0; double vol = 0.0; string guid = ""; string mat_type = ""; double price = 0.0; myPart.GetReportProperty("GUID", ref guid); myPart.GetReportProperty("LENGTH", ref lng); myPart.GetReportProperty("WEIGHT", ref weight); myPart.GetReportProperty("VOLUME", ref vol); myPart.GetReportProperty("MATERIAL_TYPE", ref mat_type); lng = Math.Round(lng, 0); //string cut = ""; //myPart.GetReportProperty("CAST_UNIT_TYPE", ref cut); //ModAtr.Add(new AttSet(myPart.Material.MaterialString, // profile, lng, weight, vol)); //21/6/2016 в отладке Elm.Elements.Add(new Elm()); elements.Add(new Elm(guid, myPart.Material.MaterialString, mat_type, myPart.Profile.ProfileString, lng, weight, vol, price)); // !! if (ii % 500 == 0) // progress update every 500th items { if (progress.Canceled()) { // new Log("\n\n======= TSmatch pass model CANCEL!! ======= ii=" + ii); // TSD.Show() break; } progress.SetProgress(ii.ToString(), 100 * ii / totalCnt); } } } //while progress.Close(); Scale(elements); elements.Sort(); Log.exit(); return elements; } // Read