/// <summary> /// Load the manufacturing features by their name to the study /// </summary> private void LoadMfgByName() { TxObjectList mfgsToLoad = new TxObjectList(); TxEmsCacheManager emsCacheManager = new TxEmsCacheManager(); QueryEmsCache(emsCacheManager, "wpMfgLibrary", "children", planningObject, null); TxObjectList mfgsInLibrary = planningObject.GetField("children") as TxObjectList; QueryEmsCache(emsCacheManager, "wpMfgLibrary", "name", null, mfgsInLibrary); foreach (ITxPlanningObject mfg in mfgsInLibrary) { string name = mfg.GetField("name") as string; if (MfgCollection.Contains(name)) { mfgsToLoad.Add(mfg); } } if (mfgsToLoad.Count > 0) { TxDocumentEx document = new TxDocumentEx(); document.LoadComplete(mfgsToLoad, true); TxMessageBox.Show($"{mfgsToLoad.Count} Mfgs loaded!", "Mfg import", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } else { TxMessageBox.Show("No wanted Mfgs found in library", "Mfg import", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }
/// <summary> /// Load the manufacturing features by their name to the study /// </summary> private void LoadMfgByName() { /* * Thanks to Siemens API Team for the support * https://community.plm.automation.siemens.com/t5/Tecnomatix-Developer-Forum/Tx13-0-Import-Mfg/m-p/519783#M1240 */ TxObjectList mfgsToLoad = new TxObjectList(); TxEmsCacheManager emsCacheManager = new TxEmsCacheManager(); QueryEmsCache(emsCacheManager, "wpMfgLibrary", "children", planningObject, null); TxObjectList mfgsInLibrary = planningObject.GetField("children") as TxObjectList; QueryEmsCache(emsCacheManager, "wpMfgLibrary", "name", null, mfgsInLibrary); foreach (ITxPlanningObject mfg in mfgsInLibrary) { string name = mfg.GetField("name") as string; if (MfgCollection.Contains(name)) { mfgsToLoad.Add(mfg); } } if (mfgsToLoad.Count > 0) { TxDocumentEx document = new TxDocumentEx(); document.LoadComplete(mfgsToLoad, true); TxMessageBox.Show($"{mfgsToLoad.Count} Mfgs loaded!", "Mfg import", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } else { TxMessageBox.Show("No wanted Mfgs found in library", "Mfg import", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }
public TxPlcLogicBehavior CreatNewLB(string name) { TxTypeFilter objF1 = new TxTypeFilter(typeof(TxCompoundResource)); TxObjectList objs = TxApplication.ActiveDocument.PhysicalRoot.GetAllDescendants(objF1); TxObjectList objs1 = new TxObjectList(); bool b = false; foreach (TxCompoundResource c in objs) { if (c.Name == "LB_Main") { b = true; objs1.Add(c); TxTypeFilter objF2 = new TxTypeFilter(typeof(TxComponent)); foreach (ITxObject obj in c.GetAllDescendants(objF2)) { if (obj.Name == "LB_" + name) { obj.Delete(); } } break; } } if (!b) { objs1.Add(TxApplication.ActiveDocument.PhysicalRoot.CreateCompoundResource(new TxCompoundResourceCreationData("LB_Main"))); } TxApplication.ActiveSelection.Clear(); TxApplication.ActiveSelection.AddItems(objs1); ITxObject m_logicResource; TxPlcLogicBehavior txPlcLogicBehavior; TxNewPartResourceParametersEx txNewPartResourceParametersEx = new TxNewPartResourceParametersEx(); txNewPartResourceParametersEx.Type = "PmToolPrototype"; txNewPartResourceParametersEx.TypeNiceName = "LB_" + name; TxApplication.CommandsManager.ExecuteCommand("ComponentOperations.NewResource", txNewPartResourceParametersEx); m_logicResource = txNewPartResourceParametersEx.CreatedObject; TxComponentEx.ConnectComponentToDatabase(m_logicResource); TxLogicResourceEx.ConnectLogicResource(m_logicResource); TxPlcLogicBehaviorCreationData creationData2 = new TxPlcLogicBehaviorCreationData(); TxComponent txComponent = m_logicResource as TxComponent; txPlcLogicBehavior = txComponent.CreateLogicBehavior(creationData2); TxLinearUnitEnumEx linearUnits = TxLinearUnitEnumEx.Milimeter; TxAngularUnitEnumEx angularUnits = TxAngularUnitEnumEx.Radian; TxUnitsOptions.TxLinearUnit linearUnit = TxApplication.Options.Units.LinearUnit; TxUnitsOptions.TxAngularUnit angularUnit = TxApplication.Options.Units.AngularUnit; switch (linearUnit) { case TxUnitsOptions.TxLinearUnit.Millimeter: linearUnits = TxLinearUnitEnumEx.Milimeter; break; case TxUnitsOptions.TxLinearUnit.Centimeter: linearUnits = TxLinearUnitEnumEx.Centimeter; break; case TxUnitsOptions.TxLinearUnit.Meter: linearUnits = TxLinearUnitEnumEx.Meter; break; case TxUnitsOptions.TxLinearUnit.Inch: linearUnits = TxLinearUnitEnumEx.Inch; break; case TxUnitsOptions.TxLinearUnit.Foot: linearUnits = TxLinearUnitEnumEx.Foot; break; } switch (angularUnit) { case TxUnitsOptions.TxAngularUnit.Degree: angularUnits = TxAngularUnitEnumEx.Degree; break; case TxUnitsOptions.TxAngularUnit.Radian: angularUnits = TxAngularUnitEnumEx.Radian; break; } TxLogicBehaviorEx.SetLogicBehaviorUnits(txPlcLogicBehavior, linearUnits, angularUnits); return(txPlcLogicBehavior); }