Error creating Shared Params
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there,
I am getting an error when creating Shared Parameters inside my document, giving me the following Exception:
The message is "Unable to make changes to the associated shared parameter file".
In the code, I read from an Excel File and create the params, checking if the groups and params exist to avoid trying to duplicate parameters or groups, as it should cause an exception to be thrown.
try
{
while (true)
{
string ParamName = (string)(hojaParametros.Cells[paramExcelRow, paramsHeader.ParameterColunm] as Excel.Range).Value2;
if (ParamName == null || ParamName == "")
{
break;
}
string Group = (string)(hojaParametros.Cells[paramExcelRow, paramsHeader.groupColunm] as Excel.Range).Value2;
string Type = (string)(hojaParametros.Cells[paramExcelRow, paramsHeader.typeColunm] as Excel.Range).Value2;
DefinitionGroups definitiongroups = definitionFile.Groups;
DefinitionGroup definitionGroup;
if (definitiongroups.get_Item(Group) != null)
{
definitionGroup = definitiongroups.get_Item(Group);
}
else
{
definitionGroup = definitiongroups.Create(Group);
}
if (definitionGroup.Definitions.get_Item(ParamName) == null)
{
ParameterType parameterType = GetParameterType(Type);
ExternalDefinitionCreationOptions externalDefinitionCreationOptions = new ExternalDefinitionCreationOptions(ParamName, parameterType);
definitionGroup.Definitions.Create(externalDefinitionCreationOptions);
}
paramExcelRow++;
}
}
catch (System.Exception exp)
{
message = exp.Message;
Libro.Close();
ExcelApp.Quit();
return Result.Failed;
}
To open the Shared Parameters File I am using the following function:
public DefinitionFile setAndOpenExternalSharedParamFile(Autodesk.Revit.ApplicationServices.Application application, string sharedParamFile)
{
application.SharedParametersFilename = sharedParamFile;
return application.OpenSharedParameterFile();
}
The funny thing is that I have tried the code step by step and the exception is not thrown and the shared parameters created, but if I try to play it, the exception is thrown.
I have already used this code in other add-ins and never gave me troubles, so I don't know what might be causing it.
Any help or advice would be really appreciated, maybe there is any consideration with the file I am not taking into account.
Best Regards,