Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DocumentSavingAs event. Get NEW filename in handler....

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
doni49
586 Views, 9 Replies

DocumentSavingAs event. Get NEW filename in handler....

I have an addin that gets the filename and updates a ProjectInformation Parameter. When the user does a Save As (basically giving it a new name), I need to get the NEW filename and update the parameter before the save happens. If I do it as part of the DocumentSavingAs event, then the doc has already been saved which means when the user tries to close the file, Revit is going to prompt to save the file. That would lead to confusion.

The question is "does the doc.pathname property contain the new filename or is it still the OLD filename until the save actually happens?"



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

9 REPLIES 9
Message 2 of 10
jeremytammik
in reply to: doni49

Dear Doni49,

 

Thank you for your query.

 

You statement sounds a bit weird to me.

 

You say "If I do it as part of the DocumentSavingAs event, then the doc has already been saved..."

 

The documentation on the Application.DocumentSavingAs and Application.DocumentSavedAs events states the opposite.

 

Subscribe to the DocumentSavingAs event to be notified when Revit is just about to save the document with a new file name.

 

Subscribe to the DocumentSavedAs event to be notified immediately after Revit has finished saving document with a new file name.

 

The DocumentSavingAsEventArgs event argument provides the DocumentSavingAsEventArgs.PathName property specifying the target path to which the document is to be saved.

 

That sounds like exactly what you are asking for.

 

Am I confused?

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 10
doni49
in reply to: doni49

That was a typo. I originally tried using DocumentSavedAs. But then realized that changing the Project Information parameter at that point would cause the user to b enrolled to save even if they closed the file right then.

I've tried using DocumentSavingAs and doc.PathName still has the same name as before the save as.


Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 4 of 10
jeremytammik
in reply to: doni49

Hi Don,

 

Can you please provide a reproducible sample for us to research and verify the solution on?

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 10
doni49
in reply to: jeremytammik

I will gather up the files tonight when I get home.

 

So are you saying that within the DocumentSavingAs eventhandler, the doc.PathName property SHOULD have the new filename as opposed to the old one?



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 6 of 10
doni49
in reply to: doni49


@doni49 wrote:
That was a typo. I originally tried using DocumentSavedAs. But then realized that changing the Project Information parameter at that point would cause the user to b enrolled to save even if they closed the file right then.

I've tried using DocumentSavingAs and doc.PathName still has the same name as before the save as.
The bold portion above SHOULD read user to be prompted to save.  I don't know what I DID type that caused autocorrect (on my phone) to put what it did.
 


Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 7 of 10
arnostlobel
in reply to: doni49

Don, It looks like you have figured it all out already, so I may be restating the obvious: 

 

  1. Indeed, you need to use the DocumenSaving event, which is raced before a document is saved (as).
  2. You need to use the PathName property of the DocumentSavingAsEventArgs class, of which instance is given to your event handler. It looks like you have been using the PathName property of the Document class instead, which is, naturally, still set to old path, since the document has not been saved yet at the moment of DocumentSavignAs event.

Good luck

Arnošt Löbel
Message 8 of 10
doni49
in reply to: arnostlobel

I had hoped the new filename was among the event's arguments but I didn't see it listed.  I'll look again when I get home tonight.



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 9 of 10
arnostlobel
in reply to: doni49

Yes it does have it indeed. These are the properties and methods available on the argument class:

Cancellable : Indicates whether an event may be cancelled by an event delegate.
Document : The document associated with the event.
IsSavingAsMasterFile : Indicates whether the document is to be saved as master file.
PathName : Target path to which the document is to be saved.
IsCancelled : Indicates whether the event is being cancelled.
Cancel : If the event is cancellable, users may call the Cancel() method to cancel it.
Arnošt Löbel
Message 10 of 10
doni49
in reply to: arnostlobel

Thanks for the assistance.

 

You called it.  I was trying to use doc.PathName.  I switched to using e.Pathname (e is the event argument).  It's working well now.

 

In case anyone wants a copy, I've attached the source code.  This has been tested in 2014.

 

Our standard titlte block includes space for the filename -- but without the drive/directory -- and as been well documented, Revit OOTB doesn't allow for this automatically (we had to manually update a Project Information parameter) and I wanted to automate this task.

 

I WAS going to attach it but the website won't allow me.  I've also posted the same message over on RevitForum.org and the source code IS attached there.

 

http://www.revitforum.org/third-party-add-ins-api-r-d/20859-onsaveas-event-get-new-filename-update-p...

 

 



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community