EBDN - Community - Question & Answers

  1. Ramesh Doni
  2. C# Development
  3. Tuesday, 01 September 2020
below code i'm using to delete shape & item from sheet its not deleting

public void CheckDevicein_Sheet(Sheet sheetToLook)
{
Worksheet ws1 = sheetToLook.OpenWorksheet(ObjectKind.Device, new[] { AttributeId.Designation});

foreach (WorksheetRow row in ws1.Rows)
{

var symbol = row.ObjectItem.SourceAssociations.Where(x => x.Role == AssociationRole.NonElectricalSymbol && x.RelatedObject.Parent.Id == sheetToLook.Id);
if(symbol!=null)
{
if(row.ObjectItem.Name== "+B34.2";)// hardcode device name
{
DeleteSymbol(row.ObjectItem, sheetToLook);
row.ObjectItem.Delete(true);
break;
}
}

}

if (sheetToLook == null)
{
System.Windows.MessageBox.Show("Visio sheet with name " + sheetToLook + " could not found. ", "Cannot update sheet";);
return;
}
sheetToLook.Open(SheetOpenBehavior.AutoSave);

if (sheetToLook.IsReadOnly)
{
System.Windows.MessageBox.Show("Visio Sheet is read-only - license or user rights missing, generation aborted", "Cannot generate SLD";);
return;
}

sheetToLook.Close();
}

//Delete symbol using below code
public static void DeleteSymbol(ObjectItem symb, Sheet sheet)
{
ExecuteSheetOperationRecordData[] list = new ExecuteSheetOperationRecordData[3];
list[0].Qualifier = (int)ExecuteSheetOperationModes.OpExecSheetDeleteSymbol;
list[1].Qualifier = (int)ExecuteSheetOperationModes.ArgExecSheetFctSel;
list[1].Value = "1";
list[2].Qualifier = (int)ExecuteSheetOperationModes.ArgExecSheetRef2Symbol;
list[2].Value = symb.Id;
IList<ExecuteSheetOperationRecordData> l = list;
sheet.ExecuteSheetOperation(ref l);
}
You do not have permission to view the content of this accepted answer.