Set parameter

Set parameter

markjvlampad
Advocate Advocate
609 Views
3 Replies
Message 1 of 4

Set parameter

markjvlampad
Advocate
Advocate

could anybody explain what are the difference between revit macro and revit api?

because I am playing around the codes,

 

String pName = "12asdf";

using (Transaction t = new Transaction(doc, "set"))
{
t.Start();
elem.LookupParameter("Comments").Set(pName);
TaskDialog.Show("result", pName);
t.Commit();
}

this code works perfectly in macro even the parameters are built in or shared.

 

however when I try to implement in Api, it doesn't work in Shared parameter.

 

thank you in advance.

0 Likes
610 Views
3 Replies
Replies (3)
Message 2 of 4

RPTHOMAS108
Mentor
Mentor

Regardless of macro vs api I think you'll get varied success with the LookupParameter function because it is looking for the first parameter it comes accross with matching name and there may be more than one such match. It is really a fall back for when a parameter neither has shared parameter GUID or is a built in parameter.

 

In the case of instance comments and type comments these are built-in parameters so you should instead be using either:

ALL_MODEL_INSTANCE_COMMENTS

ALL_MODEL_TYPE_COMMENTS

 

If you know it is a shared parameter you should be using it's shared parameter GUID.

0 Likes
Message 3 of 4

markjvlampad
Advocate
Advocate

i manage to set my shared parameter.

 

however I got another issue.

 

 

without the using (Transaction t = new Transaction(doc, "Set Share Parameter"))

my set() method is setting the parameter. but it won't last long.maybe clicking 5 times my modify command in Revit the parameter will disappear.

 

 

using (Transaction t = new Transaction(doc, "Set Share Parameter"))
{
t.Start();
//my code here.
t.Commit();
}

 

adding the transaction code above, my set() method is not setting any parameter.

 

anybody can help?

0 Likes
Message 4 of 4

RPTHOMAS108
Mentor
Mentor

At the top of the class check the transaction attribute, it should be:

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]

not

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Automatic)]

 

If you want to manually start transactions, this is now mandatory from 2018 onwards.

 

TransactionMode.Automatic was removed in the 2018 version of the API. If you used this in the past then the need for Transactions would be automatically detected and starting one manually would throw an exception. The TransactionMode.Automatic is very limiting anyway, not giving you finite control.

 

When you call Transaction.Start it will return a status (such as Started) you should ideally check for this before changing the document and definity before comitting. Sometime the application or document will not be in a state to start a transaction and this condition should be handled.

0 Likes