Javascript - SetProposalName function

Javascript - SetProposalName function

Matt__W
Advisor Advisor
1,025 Views
7 Replies
Message 1 of 8

Javascript - SetProposalName function

Matt__W
Advisor
Advisor

I've got some JS code (see below) that is bugging me (pun intended). I'm probably overlooking something stupid simple but... I'm trying to cycle throught the proposals and set each one at a time as the active proposal. I can't get the SetProposalName function to work. I'm looking at the SetProposalName function and I'm not 100% sure if that means set a new name for a proposal or set a proposal current based on a name. Can someone shed some light on this for me and point me in the right direction?

 

// Get the active document
var doc = app.ActiveDocument();

// Get all proposals in the model, cycle through them & print them to the debug panel
var varProps = doc.GetAllProposals("");
for (x in varProps) {
   print (varProps[x]);
}

Thanks!

 



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

0 Likes
Accepted solutions (1)
1,026 Views
7 Replies
Replies (7)
Message 2 of 8

elliott.rosenfeld
Autodesk
Autodesk

I think there's a piece missing here? From looking at your .js, it seems like you only end up printing the names of proposals to the debug window..For example, when you change a storyboard name, there's another step:

 

// Get the active document

var doc = app.ActiveDocument();

3

// Get current storyboard

var currentStoryboard = doc.Timeline.GetCurrentStoryboard();

6

7 // Change the name of a storyboard

currentStoryboard.Name = "My Storyboard with a new Name";

 

When I test out your code, the script executes, but there's still more to be done.

Here's what I see when I run your code (below). The script has executed the Get of ALL proposals.

JS.jpg

 

But, if I do some tweaks, I can then print AllProposals. You can see that the console printed out the names of the 3 proposals in my model (master, proposal1, and Proposal2). Interestingly, it looks like Proposal2 is printed out first, which is coincedentally also the active proposal.

moreJS.jpg

 

But if I change my JS a bit, I can instead print the name of the current, aka active proposal.

 

var doc = app.ActiveDocument();
var currentProposal = doc.GetActiveProposal();
print(currentProposal)activeJS.jpg

I know this doesn't completely answer your questions, but hopefully this helps! (Sorry, I'm not a JS expert, just guesstimating some of these things).

I think you may need to return doc.GetAllProposals as an array, and then somehow cycle through all Proposals, setting them active one at a time... if that is your intended result?

 

Thanks!

Elliott

 


Principal Specialist, Infrastructure
0 Likes
Message 3 of 8

Matt__W
Advisor
Advisor
I know my code isn't complete. I couldn't figure out how to get it to do what I wanted. I used the print function as a check to make sure I was on the right track with iterating through the proposals collection.

I'll take a look at what you did later. Maybe I can hack something to work.

Thanks


Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

0 Likes
Message 4 of 8

Matt__W
Advisor
Advisor

So I was messing around with my code and going through the JS documentation and I don't know how I missed them but there are ChangeProposal and ActiveProposal functions, both of which I can't figure out how to actually apply them. The follow code will run without any issues but nothing seems to happen. To give you a little background of my model I have two proposals: master and Test01. When I have Test01 active and run the code, the proposal doesn't change. I can't figure out how to commit the change and actually update the current proposal. Got any thoughts?

 

// Current proposal is 'Test01'

var doc = app.ActiveDocument(); doc.ChangeProposal = "master"; doc.ActiveProposal = "master";

 



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

0 Likes
Message 5 of 8

Matt__W
Advisor
Advisor

JS documentation says this about the ChangeProposal function.

 

IW_ChangeProposal.PNG

 

But it's not switching. Smiley Sad



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

0 Likes
Message 6 of 8

elliott.rosenfeld
Autodesk
Autodesk
Accepted solution

Took me a while to figure it out, but this seems to work:

 

var doc = app.ActiveDocument();
doc.ChangeProposal("master");

Principal Specialist, Infrastructure
Message 7 of 8

Matt__W
Advisor
Advisor

Thanks @elliott.rosenfeld!! I knew it had to be something stupid simple!



Matt Wunch
Revit Subject Matter Expert/sUAS Pilot

Twitter | LinkedIn

AU2017 - Code Blue Dr Revit - How to Resuscitate Corrupt Revit Models

Was this answer helpful? If so, please click the ACCEPT AS SOLUTION or the KUDO button.

0 Likes
Message 8 of 8

elliott.rosenfeld
Autodesk
Autodesk

No problem Matt, it was fun to mess around with some scripts. It does always come down to that, huh 🙂


Principal Specialist, Infrastructure
0 Likes