EaBIM
标题:
Revit二次开发错误提示集锦
[打印本页]
作者:
萧闫子
时间:
2014-1-9 13:16
标题:
Revit二次开发错误提示集锦
根据异常提示,快速准确判断错误原因,找到错误位置,是开发的基本功。
一、事务(待定)
错误提示:
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;
}
}
但是在创建Revit对象比如Pipe的时候,这样的属性就会提示上面的错误,必须这样限制,使用手写Add-In文件。
[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;
}
}
NewPipe.addin
<?
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
>
这样便可以正常运行,创建Pipe
Automatic自动
Manual手动
作者:
月の月
时间:
2014-2-20 14:30
顶!!!!!!!!!!!!!!!!!!!!!!!!!
欢迎光临 EaBIM (https://eabim.net/)
Powered by Discuz! X3.2