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

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

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:

转载地址:http://hluym.baihongyu.com/

你可能感兴趣的文章
数字签名和数字证书详解
查看>>
用来代替SQUID的软件VARNISH
查看>>
每天学一点Scala之 伴生类和伴生对象
查看>>
http反向代理调度算法追朔
查看>>
做门户网站 个人站长的新好出路
查看>>
sql中exists,not exists的用法
查看>>
CentOS6.5更改ssh端口问题
查看>>
11g默认审计选项
查看>>
Where Did That New Exchange 2010 Mailbox Go?
查看>>
CentOS 7 yum安装Zabbix
查看>>
Bash编程入门
查看>>
神器:REST测试工具[wiztools.org restclient]客户端Jar依赖Java安装环境
查看>>
生成keystore是报错拒绝访问(已测试)
查看>>
从一道题浅说 JavaScript 的事件循环
查看>>
每天进步一点点——Linux文件锁编程flock
查看>>
sqlserver锁机制详解(sqlserver查看锁)
查看>>
[公告]欢迎您加入WF技术研究团队
查看>>
5.10. Web Tools
查看>>
将Eclipse代码导入到Android Studio的两种方式
查看>>
ASP.Net4.0中新增23项功能
查看>>