NetOfficeFw / NetOffice

🌌 Create add-ins and automation code for Microsoft Office applications.
MIT License
697 stars 143 forks source link

Visio cant edit Container Shapes #321

Closed taumoeps closed 3 years ago

taumoeps commented 3 years ago

Trying to set the fill and line color for a Visio Container shape, but error below.

Failed to proceed PropertySet on Visio.IVCell=>FormulaU.

However it will let me change the shape text and size. Any ideas? Ive tried remove the theme, used the default SDCONT_M.VSSX stencil as well as create my own stencil. Code below

            IVMaster mstShape = TADStencil.Masters.get_ItemU("Container");
            IVShape shpNew = visioPage.Drop(mstShape, xPos, yPos);
            shpNew.Text = tadModel.ModelName;
            shpNew.get_CellsSRC((short)VisSectionIndices.visSectionObject, (short)VisRowIndices.visRowXFormIn, (short)VisCellIndices.visXFormWidth).FormulaU = shapeWidth.ToString() + " mm";
            shpNew.get_CellsSRC((short)VisSectionIndices.visSectionObject, (short)VisRowIndices.visRowXFormIn, (short)VisCellIndices.visXFormHeight).Formula = 40.ToString() + " mm";
            shpNew.Cells("Char.Color").FormulaU = "RGB(70, 114, 196)";
            shpNew.Cells("LineColor").FormulaU = "RGB(242, 242, 242)";
            shpNew.Cells("FillForegnd").FormulaU = "RGB(242, 242, 242)";
            shpNew.Cells("FillForegndTrans").FormulaU = "0";
jozefizso commented 3 years ago

What does the exception say? There should be more details in the inner exceptions.

taumoeps commented 3 years ago

Below is the full error. It stops when hitting this line: shpNew.Cells("FillForegnd").FormulaU = "RGB(242, 242, 242)";

The weird thing is I can manually change the fill color in the shape style tab by clicking on the fill button It then updates the FillForegnd field to: =THEMEGUARD(MSOTINT(THEMEVAL("AccentColor"),-25))

Ive also tried using the THEMEGUARD value in the FormulaU cell and still get the same error

{"Message":"An error has occurred.","ExceptionMessage":"Failed to proceed PropertySet on Visio.IVCell=>FormulaU.","ExceptionType":"NetOffice.Exceptions.PropertySetCOMException","StackTrace":" at NetOffice.Invoker.PropertySet(ICOMObject comObject, String name, Object[] value)\r\n at NetOffice.CorePropertySetExtensions.ExecuteValuePropertySet[T](Core value, ICOMObject caller, String name, T newValue)\r\n at NetOffice.VisioApi.IVCell.set_FormulaU(String value)\r\n at T.A.D_DWO.Controllers.DWOController.DrawModel(List1 tadModelList, Int32 totalColumns, Application application, IVDocument document, IVPage visioPage, IVDocument visioStencil) in C:\\Users\\Steve\\Source\\Repos\\T.A.D-DWO\\T.A.D-DWO\\Controllers\\DWOController.cs:line 266\r\n at T.A.D_DWO.Controllers.DWOController.DrawDiagram2(TADLayerObj tadLayerObj, String fileName) in C:\\Users\\Steve\\Source\\Repos\\T.A.D-DWO\\T.A.D-DWO\\Controllers\\DWOController.cs:line 129\r\n at T.A.D_DWO.Controllers.DWOController.<DiagramApi3>d__1.MoveNext() in C:\\Users\\Steve\\Source\\Repos\\T.A.D-DWO\\T.A.D-DWO\\Controllers\\DWOController.cs:line 40\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__11.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Exception has been thrown by the target of an invocation.","ExceptionType":"System.Reflection.TargetInvocationException","StackTrace":" at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)\r\n at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)\r\n at NetOffice.Invoker.PropertySet(ICOMObject comObject, String name, Object[] value)","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"\n\nCell is guarded.","ExceptionType":"System.Runtime.InteropServices.COMException","StackTrace":null}}}

jozefizso commented 3 years ago

The inner exception is Cell is guarded.

https://visualsignals.typepad.co.uk/vislog/2018/11/formulau-and-formulaforceu-in-visio.html

You must use FormulaForceU to change the expression.