一、事务(待定)
错误提示:
Autodesk.Revit.Exceptions.InvalidOperationException:A sub-transaction can only be active inside an open Transaction.
错误原因:
为了方便使用Add-In-Manager调试,把命令统一写成如下格式:
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class HelloWorld : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
MessageBox.Show( " Hello World " );
return Result.Succeeded;
}
}
[Regeneration(RegenerationOption.Manual)]
public class HelloWorld : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
MessageBox.Show( " Hello World " );
return Result.Succeeded;
}
}
[Transaction(TransactionMode.Automatic)]
[Regeneration(RegenerationOption.Manual)]
[Journaling(JournalingMode.NoCommandData)]
public class NewPipeCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
CreateNewPipe(doc);
return Result.Succeeded;
}
public Pipe CreateNewPipe(Document document)
{
FilteredElementCollector collector = new FilteredElementCollector(document);
collector.OfClass( typeof (PipeType));
PipeType pipeType = collector.FirstElement() as PipeType;
Pipe pipe = null ;
if ( null != pipeType)
{
// create pipe between 2 points
XYZ p1 = new XYZ( 0 , 0 , 0 );
XYZ p2 = new XYZ( 10 , 0 , 0 );
pipe = document.Create.NewPipe(p1, p2, pipeType);
}
return pipe;
}
}
[Regeneration(RegenerationOption.Manual)]
[Journaling(JournalingMode.NoCommandData)]
public class NewPipeCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
CreateNewPipe(doc);
return Result.Succeeded;
}
public Pipe CreateNewPipe(Document document)
{
FilteredElementCollector collector = new FilteredElementCollector(document);
collector.OfClass( typeof (PipeType));
PipeType pipeType = collector.FirstElement() as PipeType;
Pipe pipe = null ;
if ( null != pipeType)
{
// create pipe between 2 points
XYZ p1 = new XYZ( 0 , 0 , 0 );
XYZ p2 = new XYZ( 10 , 0 , 0 );
pipe = document.Create.NewPipe(p1, p2, pipeType);
}
return pipe;
}
}
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
< RevitAddIns >
< AddIn Type = " Command " >
< Assembly > F:\RevitCodes\RevitCodes\bin\Debug\RevitCodes.dll </ Assembly >
< ClientId > 738dfa84 - e739 - 48c9 - 892c - 4a397f08b49f </ ClientId >
< FullClassName > RevitCodes.NewPipeCommand </ FullClassName >
< Text > NewPipe </ Text >
< Description > "" </ Description >
< VisibilityMode > AlwaysVisible </ VisibilityMode >
</ AddIn >
</ RevitAddIns >
< RevitAddIns >
< AddIn Type = " Command " >
< Assembly > F:\RevitCodes\RevitCodes\bin\Debug\RevitCodes.dll </ Assembly >
< ClientId > 738dfa84 - e739 - 48c9 - 892c - 4a397f08b49f </ ClientId >
< FullClassName > RevitCodes.NewPipeCommand </ FullClassName >
< Text > NewPipe </ Text >
< Description > "" </ Description >
< VisibilityMode > AlwaysVisible </ VisibilityMode >
</ AddIn >
</ RevitAddIns >
Automatic自动
Manual手动