Hi
I'm trying to change parametervalues of the profile of a wallsweep programmatically (the user clicks on a wallsweep, the parameters of the profile are loaded into a form & the user can modify the parameters). Now to change multiple parametervalues of the profile at once I'm using a for loop enclosed in a transaction. The problem is that the transaction does not seem to commit and the for loop does not loop over all values.
I guess it's probably an issue with the transaction?
Thanks in advance ๐
public void Execute(UIApplication app)
{
string eID = this.savedelementid;//retrieving the unique id saved using another externaleventhandler
Element el = app.ActiveUIDocument.Application.ActiveUIDocument.Document.GetElement(eID); // retrieving the wallsweep element - (works fine)
WallSweep ws;
WallSweepInfo wsi;
List<Parameter> lp;
List<String> ls;
lp = this.SetParameter;// list of parameters of the wall sweep obtained using another externaleventhandler - (works fine)
ls = this.SetValue;// list of parameter values of the wall sweep obtained using another externaleventhandler - (works fine)
if (el is WallSweep)
{
ws = (WallSweep)el;
wsi = (WallSweepInfo)ws.GetWallSweepInfo();
Element wsprofile = app.ActiveUIDocument.Application.ActiveUIDocument.Document.GetElement(wsi.ProfileId); // retrieving the profile elmement of the wall sweep- (works fine)
TaskDialog.Show("melding", wsprofile.Name.ToString()); // prints out the correct name
using (Transaction transaction = new Transaction(app.ActiveUIDocument.Application.ActiveUIDocument.Document))
{
if (transaction.Start("change dimension") == TransactionStatus.Started)
{
for (int i = 0; i < lp.Count; i++)
{
MessageBox.Show(i.ToString()); // only prints out 0 and 1, while lp.Count = 20?
wsprofile.LookupParameter(lp[i].Definition.Name).SetValueString(ls[i]);
}; app.ActiveUIDocument.Application.ActiveUIDocument.Document.Regenerate();
transaction.Commit(); //does not commit the changes
};
}
}
}
}
Solved! Go to Solution.
Hi
I'm trying to change parametervalues of the profile of a wallsweep programmatically (the user clicks on a wallsweep, the parameters of the profile are loaded into a form & the user can modify the parameters). Now to change multiple parametervalues of the profile at once I'm using a for loop enclosed in a transaction. The problem is that the transaction does not seem to commit and the for loop does not loop over all values.
I guess it's probably an issue with the transaction?
Thanks in advance ๐
public void Execute(UIApplication app)
{
string eID = this.savedelementid;//retrieving the unique id saved using another externaleventhandler
Element el = app.ActiveUIDocument.Application.ActiveUIDocument.Document.GetElement(eID); // retrieving the wallsweep element - (works fine)
WallSweep ws;
WallSweepInfo wsi;
List<Parameter> lp;
List<String> ls;
lp = this.SetParameter;// list of parameters of the wall sweep obtained using another externaleventhandler - (works fine)
ls = this.SetValue;// list of parameter values of the wall sweep obtained using another externaleventhandler - (works fine)
if (el is WallSweep)
{
ws = (WallSweep)el;
wsi = (WallSweepInfo)ws.GetWallSweepInfo();
Element wsprofile = app.ActiveUIDocument.Application.ActiveUIDocument.Document.GetElement(wsi.ProfileId); // retrieving the profile elmement of the wall sweep- (works fine)
TaskDialog.Show("melding", wsprofile.Name.ToString()); // prints out the correct name
using (Transaction transaction = new Transaction(app.ActiveUIDocument.Application.ActiveUIDocument.Document))
{
if (transaction.Start("change dimension") == TransactionStatus.Started)
{
for (int i = 0; i < lp.Count; i++)
{
MessageBox.Show(i.ToString()); // only prints out 0 and 1, while lp.Count = 20?
wsprofile.LookupParameter(lp[i].Definition.Name).SetValueString(ls[i]);
}; app.ActiveUIDocument.Application.ActiveUIDocument.Document.Regenerate();
transaction.Commit(); //does not commit the changes
};
}
}
}
}
Solved! Go to Solution.
Solved by RPTHOMAS108. Go to Solution.
1) Are all of the parameter you are processing settable (.IsReadOnly = false)
2) Can they all be set with a string value, usually SetValueString would be related to parameters of storage type double.
3) Is this being executed from within a try/catch structure (do you get any exceptions relating to setting the parameters).
LookupParameter is not a good thing to use to find the right parameters. i.e. some built-in parameters are guilty of having duplicate names.
1) Are all of the parameter you are processing settable (.IsReadOnly = false)
2) Can they all be set with a string value, usually SetValueString would be related to parameters of storage type double.
3) Is this being executed from within a try/catch structure (do you get any exceptions relating to setting the parameters).
LookupParameter is not a good thing to use to find the right parameters. i.e. some built-in parameters are guilty of having duplicate names.
Yes, this was the issue. The try/catch gave the error "an object reference not set to an instance of an object" so not all parameters were modifiable. Thanks!
Yes, this was the issue. The try/catch gave the error "an object reference not set to an instance of an object" so not all parameters were modifiable. Thanks!
Can't find what you're looking for? Ask the community or share your knowledge.