Message 1 of 3
Update insulation thickness, insulation type and service via .NET API using PnPTable P3dLineGroup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I'm trying to update 3 specific properties via the .NET API for Plant 3D 2025. However, I'm having some problems, when executing my method that updates the lineGroupId with the new properties for the first time in the file, it works very well, the problem is that , if I close the file after running, and open it again and try to run it again or even trace a pipe using "RoutePipe", it gives an error when adding the objects related to the Pipe.
One of the most common errors I saw: Cannot create a part record in the project database.
Can anyone identify what my error is in this method below?
private static void ApplyPipeSettingsToAllObjects(ObjectId pipeId, Dictionary<string, string> pipeSettings, DataLinksManager dlm, Database db, Editor ed)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
if (pipeId != ObjectId.Null)
{
if (pipeId.IsErased)
{
return;
}
Pipe pipe = tr.GetObject(pipeId, OpenMode.ForRead) as Pipe;
PipeInlineAsset pipeInlineAsset = tr.GetObject(pipeId, OpenMode.ForRead) as PipeInlineAsset;
if (pipe == null && pipeInlineAsset == null)
{
return;
}
if (pipe != null || pipeInlineAsset != null)
{
try
{
int rowId = dlm.FindAcPpRowId(pipeId);
if (rowId == -1)
{
ed.WriteMessage("\nrowId inválido. Não foi possível associar o pipe ao grupo.");
return;
}
PnPDatabase db1 = dlm.GetPnPDatabase();
PnPTable tbl = db1.Tables["P3dLineGroup"];
PnPRowIdArray lineGroupId = dlm.GetRelatedRowIds("P3dLineGroupPartRelationship", "Part", rowId, "LineGroup");
if (lineGroupId == null || lineGroupId.Count == 0)
{
ed.WriteMessage("\nNenhum grupo de linha relacionado encontrado.");
return;
}
int lineGroupRowId = lineGroupId.First.Value;
if (modifiedLineGroupIds.Contains(lineGroupRowId))
{
return;
}
string sStatement = "PnPID=" + lineGroupRowId;
PnPRow[] rows = tbl.Select(sStatement);
if (rows.Length > 0)
{
foreach (PnPRow Row in rows)
{
string newInsulationThickness = pipeSettings.ContainsKey("Isolamento") ? pipeSettings["Isolamento"] : string.Empty;
string newInsulationType = pipeSettings.ContainsKey("TipIsolamento") ? pipeSettings["TipIsolamento"] : string.Empty;
string newService = pipeSettings.ContainsKey("Service") ? pipeSettings["Service"] : string.Empty;
bool rowChanged = false;
try
{
Row.BeginEdit();
if (Row["InsulationThickness"] != null && !string.IsNullOrEmpty(newInsulationThickness) && Row["InsulationThickness"] != newInsulationThickness)
{
Row.SetPropertyValue("InsulationThickness", newInsulationThickness);
rowChanged = true;
}
if (Row["InsulationType"] != null && !string.IsNullOrEmpty(newInsulationType) && Row["InsulationType"] != newInsulationType)
{
Row.SetPropertyValue("InsulationType", newInsulationType);
rowChanged = true;
}
if (Row["Service"] != null && !string.IsNullOrEmpty(newService) && Row["Service"] != newService)
{
Row.SetPropertyValue("Service", newService);
rowChanged = true;
}
}
catch (System.Exception ex)
{
MessageBox.Show($"Erro ao tentar atualizar InsulationThickness, InsulationType e Service.\nErro: {ex}", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (rowChanged)
{
Row.EndEdit();
}
else
{
Row.CancelEdit();
}
}
}
try
{
dlm.AcceptChanges();
}
catch (System.Exception ex)
{
ed.WriteMessage($"\nErro ao aplicar mudanças no DataLinksManager: {ex.Message}\n");
}
if (!modifiedLineGroupIds.Contains(lineGroupRowId))
{
modifiedLineGroupIds.Add(lineGroupRowId);
}
}
else
{
ed.WriteMessage("\nNenhuma linha encontrada na tabela P3dLineGroup.");
}
}
catch (System.Exception ex)
{
MessageBox.Show($"Erro ao tentar atualizar InsulationThickness e InsulationType: {ex}", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
tr.Commit();
}
catch (System.Exception ex)
{
tr.Abort();
MessageBox.Show($"Ocorreu um erro inesperado ao tentar setar as propriedades para o objeto Pipe.\nErro: {ex}", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}