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: 

Set parameter

3 REPLIES 3
Reply
Message 1 of 4
markjvlampad
511 Views, 3 Replies

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

Set parameter

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.

3 REPLIES 3
Message 2 of 4
RPTHOMAS108
in reply to: markjvlampad

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

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.

Message 3 of 4
markjvlampad
in reply to: RPTHOMAS108

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

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?

Message 4 of 4
RPTHOMAS108
in reply to: markjvlampad

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

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.

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

Post to forums  

Autodesk Design & Make Report