<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://communities.bentley.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>13 - 如何通过视图访问imodel数据</title><link>https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/22113/13-imodel</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>13 - 如何通过视图访问imodel数据</title><link>https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/22113/13-imodel</link><pubDate>Tue, 23 Jun 2015 08:44:17 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:66a95447-7850-400f-8f12-5c8242fcb14c</guid><dc:creator>lijun.ma</dc:creator><comments>https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/22113/13-imodel#comments</comments><description>Current Revision posted to 技术资料库 by lijun.ma on 6/23/2015 8:44:17 AM&lt;br /&gt;
&lt;p&gt;可以通过视图view（由imodel视图创建工具生成，本质上是xml文件）快速遍历、查询imodel业务数据。&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;具体做法是：&lt;/p&gt;
&lt;p&gt;首先调用LoadView（）方法加载进view，&lt;/p&gt;
&lt;p&gt;再通过IModelView对象得到view所包含的table，&lt;/p&gt;
&lt;p&gt;最后通过table得到所需的数据行和列。&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;代码示例如下：&lt;/p&gt;
&lt;pre class="brush: applescript; fontsize: 100; first-line: 1; "&gt;IModel imodel = IModel.Open(@&amp;quot;D:\test.i.dgn&amp;quot;);
IModelView view = imodel.LoadView(@&amp;quot;D:\view.xml&amp;quot;);

string strInfo = &amp;quot;&amp;quot;;
List&amp;lt;string&amp;gt; tables = view.Tables;

for (int i = 0; i &amp;lt; tables.Count; i++)
{
strInfo += (&amp;quot;TableName = &amp;quot; + tables[i] + &amp;quot;\n&amp;quot;);
DataTable table = view[tables[i]];

foreach (DataColumn c in table.Columns)
{
strInfo += (c.ColumnName + &amp;quot;\t\t&amp;quot;);
}

strInfo += &amp;quot;\n&amp;quot;;

foreach (DataRow r in table.Rows)
{
foreach (DataColumn c in table.Columns)
{
strInfo += (r[c.ColumnName] + &amp;quot;\t\t&amp;quot;);
}
}

}

imodel.Close();
}&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: imodel view&lt;/div&gt;
</description></item><item><title>13 - 如何通过视图访问imodel数据</title><link>https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/22113/13-imodel/revision/1</link><pubDate>Tue, 23 Jun 2015 08:44:03 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:66a95447-7850-400f-8f12-5c8242fcb14c</guid><dc:creator>lijun.ma</dc:creator><comments>https://communities.bentley.com/communities/other_communities/chinafirst/w/chinawiki/22113/13-imodel#comments</comments><description>Revision 1 posted to 技术资料库 by lijun.ma on 6/23/2015 8:44:03 AM&lt;br /&gt;
&lt;p&gt;可以通过视图view（由imodel视图创建工具生成，本质上是xml文件）快速遍历、查询imodel业务数据。&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;具体做法是：&lt;/p&gt;
&lt;p&gt;首先调用LoadView（）方法加载进view，&lt;/p&gt;
&lt;p&gt;再通过IModelView对象得到view所包含的table，&lt;/p&gt;
&lt;p&gt;最后通过table得到所需的数据行和列。&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;代码示例如下：&lt;/p&gt;
&lt;pre class="brush: applescript; fontsize: 100; first-line: 1; "&gt;IModel imodel = IModel.Open(@&amp;quot;D:\test.i.dgn&amp;quot;);
IModelView view = imodel.LoadView(@&amp;quot;D:\view.xml&amp;quot;);

string strInfo = &amp;quot;&amp;quot;;
List&amp;lt;string&amp;gt; tables = view.Tables;

for (int i = 0; i &amp;lt; tables.Count; i++)
{
strInfo += (&amp;quot;TableName = &amp;quot; + tables[i] + &amp;quot;\n&amp;quot;);
DataTable table = view[tables[i]];

foreach (DataColumn c in table.Columns)
{
strInfo += (c.ColumnName + &amp;quot;\t\t&amp;quot;);
}

strInfo += &amp;quot;\n&amp;quot;;

foreach (DataRow r in table.Rows)
{
foreach (DataColumn c in table.Columns)
{
strInfo += (r[c.ColumnName] + &amp;quot;\t\t&amp;quot;);
}
}

}

imodel.Close();
}&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: imodel view&lt;/div&gt;
</description></item></channel></rss>