Schnell mal per API Artikel mit Funktionsschablone erzeugen war meine Aufgabe…
Naja nicht so einfach:
public static MDPart CreateOrUpdateWithFunctionTemplate(Function function) { // Need to lock project var project = function.Project; project.SmartLock(); function.SmartLock(); // Init var partsDatabase = new MDPartsManagement().OpenDatabase(); var articleReference = function.ArticleReferences.First(); articleReference.SmartLock(); var partNr = articleReference.PartNr; var partVariant = articleReference.VariantNr; MDPart part = partsDatabase.GetPart(partNr, partVariant); // Create new part if (part == null) { // LockingVector is needed because of locking exception from EPLAN action (no catch possible) LockingVector lockingVector = new LockingVector(); int stateId = lockingVector.PauseManualLock(); new CommandLineInterpreter().Execute("XPameCreateType"); lockingVector.ResumeManualLock(stateId); partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part part = partsDatabase.GetPart(partNr, partVariant); } else { // Rename part string suffix = "_temp"; string partNrTemp = part.PartNr + suffix; try { articleReference.PartNr = partNrTemp; articleReference.StoreToObject(); // Quiet create temp part var application = new EplApplication(); var quiteMode = application.QuietMode; application.QuietMode = EplApplication.QuietModes.ShowNoDialogs; new CommandLineInterpreter().Execute("XPameCreateType"); application.QuietMode = quiteMode; } finally { // Rename back articleReference.PartNr = partNr; articleReference.StoreToObject(); } // Copy FunctionTemplate partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part MDPart partDuplicate = partsDatabase.GetPart(partNrTemp, partVariant); foreach (var partFunctionTemplatePosition in part.FunctionTemplatePositions) { part.RemoveFunctionTemplatePosition(partFunctionTemplatePosition); } foreach (var partDuplicateFunctionTemplatePosition in partDuplicate.FunctionTemplatePositions) { part.AddFunctionTemplatePosition(partDuplicateFunctionTemplatePosition); } partsDatabase.RemovePart(partDuplicate); // Check if article is in project var existingArticle = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNrTemp) && obj.VariantNr.Equals(partVariant) ); if (existingArticle != null) { existingArticle.SmartLock(); existingArticle.Remove(); } } // Load data var article = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant) ); if (article != null) { article.SmartLock(); article.LoadFromMasterdata(); } return part; }
Es darf nur ein Artikel hinterlegt sein, sonst schlägt die Action XPameCreateType fehl. Ist nicht schön, aber die Funktionsschablone von Hand zu erstellen ist mir zu heikel. Denn da kommt ja oftmals was neues dazu :^)
The names in the API are not chosen very well sometimes… Have a look at this table. Here you can type the field name in the GUI and in the column API-Define you can see the property.
I think you searching for FUNCTEMPLATE_CONNPT_CROSSSECTION
Thank you~!
but, What I am looking for is “Connection dimension # 20374.” in the “MasterData”….
Because I have to modify the database myself…
Is there any way to access it directly other than “Function Class”?
Thank you for your precious time.
Thats a problem of 2.7… EPLAN created this field in the UI, but its not accessable via API. This would be solved with version 2.8.
Hallo Johann, wie könnte man dieses auf mehrere Teile anwenden? Also z.B. ganze Seite markieren und dann diese Funktion in einer Schleife laufen lassen… So als Beispiel…
Ja das geht. Einfach die Methode in der Schleife der Funktionen der Seite aufrufen :)