Hi!
Does anyone know if there is an equivalent ObjectOverrule for the PnId Database?
If an entity is copied I dont want certain field values to be copied.
I've tried an ObjectOverrule but I can't get the RowId at that point.
I also noticed that the field values are set as XData. I edited the XData in my ObjectOverrule but the values still gets copied.
Is there a setting at project level to control which fields not to copy?
Thanks!
Annse
ObjectOverrule should apply to P&ID entities like all other entities. I am not sure off hand the exact order of events between our cloning code and the overrules. I do know we react to begin/end clone events and in the end clone do a lot of work to create rows in the project database, establish relationships, and copy row data.
I don’t think the Xdata is used in all situations. I know we attach Xdata with the property data so that we can insert DWGs (e.g. wblock followed by insert / explode).
It seems you simply want to prevent some project database row data from being copied?
I believe the best way to do that is to use the DataLinksManager events.
static private bool bIsActive = true;
public static void dlm_DataLinkOperationOccurred(object sender, DataLinkEventArgs e)
{
if (e.Action == DataLinkAction.RowModified && bIsActive)
{
try
{
DataLinksManager dlm = PlantProject.ActiveProjectPart.DataLinksManager;
if (dlm.HasProperty(e.RowId, "SAPCode"))
{
StringCollection props = new StringCollection();
props.Add("Size");
props.Add("Spec");
StringCollection values = null;
values = dlm.GetProperties(e.RowId, props, true);
PpObjectIdArray ppoids = dlm.FindAcPpObjectIds(e.RowId);
StringCollection newprops = new StringCollection();
newprops.Add("SAPCode");
StringCollection newvals = new StringCollection();
newvals.Add(values[0] + values[1]);
bIsActive = false;
dlm.SetProperties(ppoids.First.Value, newprops, newvals);
}
}
catch
{
}
finally
{
bIsActive = true;
}
}
}
[CommandMethod("DEMOSTART", CommandFlags.Modal)]
public static void DemoStart()
{
DataLinksManager dlm = PlantProject.ActiveProjectPart.DataLinksManager;
dlm.DataLinkOperationOccurred +=new DataLinkEventHandler(dlm_DataLinkOperationOccurred);
}
[CommandMethod("DEMOEND", CommandFlags.Modal)]
public static void DemoEnd()
{
DataLinksManager dlm = PlantProject.ActiveProjectPart.DataLinksManager;
dlm.DataLinkOperationOccurred -= new DataLinkEventHandler(dlm_DataLinkOperationOccurred);
}
That is sample code that updates a SAPCode property every time a row in the project is modified. It would need to be changed to react to rows being added / modified and blank out necessary properties.