How to use OpenSharedParameterFile Method?

How to use OpenSharedParameterFile Method?

Anonymous
Not applicable
3,214 Views
9 Replies
Message 1 of 10

How to use OpenSharedParameterFile Method?

Anonymous
Not applicable

I spent whole afternoon trying to figure out how to use OpenSharedParameterFile Method...It seems easy, but when I debug the code, it always give me

 

"Error in readParamDatabase", it's internal exception..anybody know how to solve that?Smiley Sad

 

Really drive me crazy!

 

Thanks for any reply..T T

 

Here is my code:

 

 

string fileName = @"C:\Users\Administrator\Desktop\revit\w1\try\" + datefromuser + ".txt";
FileStream fs = File.Create(fileName);

 

commandData.Application.Application.SharedParametersFilename = fileName;

try
{
SharedParameterFile = commandData.Application.Application.OpenSharedParameterFile();
}
catch (Autodesk.Revit.Exceptions.ApplicationException) { }

 

DefinitionGroup sharedParameterGroup = SharedParameterFile.Groups.Create("RevitParameters");

 

I want to create a new shared paramter file and try to add some shared parameter..

0 Likes
3,215 Views
9 Replies
Replies (9)
Message 2 of 10

ollikat
Collaborator
Collaborator

Hi

 

Could it be that file stream that is returned has "locked" the file for it self. At least File.Create documentation says this:

 

"The FileStream object created by this method has a default FileShare value of None; no other process or code can access the created file until the original file handle is closed."

 

Hope this helps.

0 Likes
Message 3 of 10

Anonymous
Not applicable

Thanks for the answer, Finally I find the problem...it's because my shared parameter file is empty....T T..spend me so much time....

Message 4 of 10

1368026189
Enthusiast
Enthusiast

Hello  cjl0411

         you still active here? I got the same question for a different reason, would you please give me your email and  help me out? thanks a lot!

         shrl007@163.com

Message 5 of 10

1368026189
Enthusiast
Enthusiast

@Jeremy Tammik

It works well sometime but sometime it doesn't work!

app.OpenSharedParameterFile() get a null as return!

 

 

Error in readParamDatabase 

Message 6 of 10

rita.aguiar
Advocate
Advocate

@1368026189  @Anonymous  @ollikat 

Hi,

 

I have a similar issue.

 

Does anyone know what could be causing this?

The Revit document already has a Shared Parameter file. I just wanted to use its parameters so I was trying to open it with the OpenSharedParameterFile method.

Many thanks.

ShareParameter file 2.png

 

 

0 Likes
Message 7 of 10

rita.aguiar
Advocate
Advocate

The thing is, app is null because it is defined in the first method, while the open shared parameter file is in the second method:ShareParameter file 3.png

 

0 Likes
Message 8 of 10

ollikat
Collaborator
Collaborator

So...seems to me that you have managed to figure out issues in your code. Or is there still something?

Seems to me, that you are new to C#. I would guess that you will face many similar issues, and probably the problem will not be the Revit API, but the programming environment in general. For those issues google & stackoverflow is your best friend. Detailed instructions to not Revit API specific issues aren't necessary provided here.

Message 9 of 10

rita.aguiar
Advocate
Advocate

thanks @ollikat , I didn't realize at first it was a C# programming question. Do you have any suggestions on what keywords to search for on google?

0 Likes
Message 10 of 10

ilgnv88
Participant
Participant

It may be too late, but if anyone has a similar problem, please pay attention to the encoding used for the shared parameter file

0 Likes