博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
判断链接文件偏移量创建空间。
阅读量:7294 次
发布时间:2019-06-30

本文共 2431 字,大约阅读时间需要 8 分钟。

start
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public 
class cmd : IExternalCommand
{
    
///
 
<summary>
    
///
 根据链接文件名称找到对应链接路径,模糊匹配,待改进
    
///
 
</summary>
    
///
 
<param name="listPath"></param>
    
///
 
<param name="strKey"></param>
    
///
 
<returns></returns>
    
private 
string GetPath(List<
string> listPath, 
string strKey)
    {
        
foreach (
string strPath 
in listPath)
        {
            
if (strPath.Contains(strKey))
                
return strPath;
        }
        
return 
"";
    }
    
public Result Execute(ExternalCommandData cmdData, 
ref 
string msg, ElementSet elements)
    {
        UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
        UIApplication uiApp = cmdData.Application;
        Document doc = uiDoc.Document;
        Selection selection = uiDoc.Selection;
        Transaction ts = 
new Transaction(doc, 
"
www
");
        ts.Start();
        FilteredElementCollector collector = 
new FilteredElementCollector(doc);
//
        collector.OfClass(
typeof(Instance)).OfCategory(BuiltInCategory.OST_RvtLinks);
//
RevitLinkType
        List<
string> listPath = GetLinkFilePaths(doc);
        
foreach (Element elDoc 
in collector)
        {
            Instance ins = elDoc 
as Instance;
            
if (ins != 
null)
            {
                Transform transForm = ins.GetTransform();
                
string strKey = elDoc.Name.Substring(
0, elDoc.Name.IndexOf(
"
.rvt
"));
//
找到链接文件名称
                Document docLink = uiApp.Application.OpenDocumentFile(GetPath(listPath, strKey));
                FilteredElementCollector collectorLink = 
new FilteredElementCollector(docLink);
                collectorLink.OfCategory(BuiltInCategory.OST_Rooms);
                
foreach (Element el 
in collectorLink)
                {
                    Room room = el 
as Room;
                    LocationPoint roomPoint = room.Location 
as LocationPoint;
                    UV uv = 
new UV();
                    
if (room.Location != 
null)
                    {
                        uv = 
new UV(roomPoint.Point.X + transForm.Origin.X, roomPoint.Point.Y + transForm.Origin.Y);
                    }
                    doc.Create.NewSpace(room.Level, uv);
                }
            }
        }
        ts.Commit();
        
return Result.Succeeded;
    }
    
///
 
<summary>
    
///
 取得链接文件路径
    
///
 
</summary>
    
///
 
<param name="doc"></param>
    
///
 
<returns></returns>
    
public List<
string> GetLinkFilePaths(Document doc)
    {
        List<
string> listPath = 
new List<
string>();
        
foreach (ElementId elId 
in ExternalFileUtils.GetAllExternalFileReferences(doc))
        {
            
if (doc.get_Element(elId).IsExternalFileReference())
            {
                ExternalFileReference fileRef = doc.get_Element(elId).GetExternalFileReference();
                
if (
"
RevitLink
" == fileRef.ExternalFileReferenceType.ToString())
                    listPath.Add(ModelPathUtils.ConvertModelPathToUserVisiblePath(fileRef.GetAbsolutePath()));
            }
        }
        
return listPath;
    }
}
url:

转载于:https://www.cnblogs.com/greatverve/p/revit-create-space.html

你可能感兴趣的文章
Windows Server 2012 网络负载均衡
查看>>
我的友情链接
查看>>
字符集与编码(四)——Unicode
查看>>
IT人士,你的知识需要管理。
查看>>
jQuery 图片滚动效果
查看>>
Composer 中国全量镜像(二)
查看>>
从range和xrange的性能对比到yield关键字(中)
查看>>
android安全问题(二) 程序锁
查看>>
我的友情链接
查看>>
UIButton拖动响应事件,距离问题
查看>>
Servlet3.1规范翻译 - 应用生命周期事件
查看>>
Private strand flush not complete
查看>>
LVS-DR配置
查看>>
我的友情链接
查看>>
Vivo FunTouch OS 手机系统内置铃声免费下载
查看>>
记:PyInstaller打包一个最简单的kivy应用
查看>>
Java线程之核心概念
查看>>
Python 爬取可用代理 IP
查看>>
Java:Comparable接口
查看>>
Python: 绝对导入 Absolute Imports
查看>>