<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Extensible By Design &#187; Extensible By Design</title>
	<atom:link href="http://extensiblecad.com/words/category/ms-office/feed/" rel="self" type="application/rss+xml" />
	<link>http://extensiblecad.com/words</link>
	<description>SolidWorks and PDMWorks Enterprise Development Blog</description>
	<lastBuildDate>Mon, 02 Feb 2009 09:02:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Finally An MS Office Addin For SolidWorks Enterprise PDM</title>
		<link>http://extensiblecad.com/words/2009/02/02/finally-an-ms-office-addin-for-solidworks-enterprise-pdm/</link>
		<comments>http://extensiblecad.com/words/2009/02/02/finally-an-ms-office-addin-for-solidworks-enterprise-pdm/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 09:00:38 +0000</pubDate>
		<dc:creator>Jeff Cope</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MS Office]]></category>
		<category><![CDATA[SolidWorks Enterprise PDM]]></category>

		<guid isPermaLink="false">http://extensiblecad.com/words/?p=159</guid>
		<description><![CDATA[Users have long enjoyed the ability to check their SolidWorks files into and out of the Enterprise PDM vault from directly inside of SolidWorks. This is because Enterprise PDM has something called the CAD Editor that is a SolidWorks Addin that runs directly inside of SolidWorks. Extensible CAD Technologies has developed an office editor to [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_162" class="wp-caption aligncenter" style="width: 310px"><a href="http://extensiblecad.com/words/wp-content/uploads/2009/02/bannerflash900x95-1.jpg"><img src="http://extensiblecad.com/words/wp-content/uploads/2009/02/bannerflash900x95-1-300x31.jpg" alt="Office2PDM addin for MS Office" title="bannerflash900x95-1" width="300" height="31" class="size-medium wp-image-162" /></a><p class="wp-caption-text">Office2PDM addin for MS Office</p></div>
<p>Users have long enjoyed the ability to check their SolidWorks files into and out of the Enterprise PDM vault from directly inside of SolidWorks.  This is because Enterprise PDM has something called the CAD Editor that is a SolidWorks Addin that runs directly inside of SolidWorks.</p>
<p>Extensible CAD Technologies has developed an office editor to enable users to work with their MS Word, Excel and Powerpoint files in exactly the same way.  Currently, users must close their MS Office files and then operate on them in Windows explorer.  </p>
<p>Although we haven&#8217;t released the application for sale just yet, we are very close.  In the meantime, we are offering a free beta version on our website to anyone who is willing to try it out and give us feedback.  You can download the beta version from here:  <a href='http://www.office2pdm.com/Try/tabid/55/Default.aspx' >Office2PDM Beta</a> </p>
<p>Note:  We still have a little work to do including the help file.  Also, after you save a new document you must hit the Refresh button.  This is a temporary workaround and will be resolved shortly.</p>
<p>Send all feedback to support@extensiblecad.com</p>
	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<small><p>&copy; Jeff Cope for <a href="http://extensiblecad.com/words">Extensible By Design</a>, 2009. |
	<a href="http://extensiblecad.com/words/2009/02/02/finally-an-ms-office-addin-for-solidworks-enterprise-pdm/">Permalink</a> |
	<a href="http://extensiblecad.com/words/2009/02/02/finally-an-ms-office-addin-for-solidworks-enterprise-pdm/#comments">2 comments</a> |
	Add to
	<a href="http://del.icio.us/post?url=http://extensiblecad.com/words/2009/02/02/finally-an-ms-office-addin-for-solidworks-enterprise-pdm/&amp;title=Finally An MS Office Addin For SolidWorks Enterprise PDM"><img src="http://yoursite.com/images/icons/delicious.gif" border="0"> del.icio.us</a>
	<a href="http://www.digg.com/submit"><img src="http://yoursite.com/images/digg.gif" border="0"> digg</a><br/>
	Who's linking ?
	<a href="http://www.technorati.com/search/http://extensiblecad.com/words/2009/02/02/finally-an-ms-office-addin-for-solidworks-enterprise-pdm/" title="Search on Technorati"><img src="http://yoursite.com/images/icons/technorati.gif" border="0">Technorati</a>
	<a href="http://www.blogpulse.com/search?query=http://extensiblecad.com/words/2009/02/02/finally-an-ms-office-addin-for-solidworks-enterprise-pdm/" title="Search on Blogpulse"><img src="http://yoursite.com/images/icons/blogpulse.gif" border="0">BlogPulse</a>
	<a href="http://google.com/blogsearch?q=http://extensiblecad.com/words/2009/02/02/finally-an-ms-office-addin-for-solidworks-enterprise-pdm/" title="Search on Google Blog Search"><img src="http://yoursite.com/images/icons/google.gif" border="0">Google</a><br/>
	Want more on these topics ? Browse the archive of posts filed under <a href="http://extensiblecad.com/words/category/net/" title="View all posts in .NET" rel="category tag">.NET</a>, <a href="http://extensiblecad.com/words/category/ms-office/" title="View all posts in MS Office" rel="category tag">MS Office</a>, <a href="http://extensiblecad.com/words/category/pdmplm/solidworks-enterprise-pdm-pdmplm/" title="View all posts in SolidWorks Enterprise PDM" rel="category tag">SolidWorks Enterprise PDM</a>.</small></p>
<p>Copyright 2007 <a href=http://extensiblecad.com/words>Extensible By Design.</a>  All rights reserved.</p>]]></content:encoded>
			<wfw:commentRss>http://extensiblecad.com/words/2009/02/02/finally-an-ms-office-addin-for-solidworks-enterprise-pdm/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Come See Us At SolidWorks World</title>
		<link>http://extensiblecad.com/words/2009/02/02/come-see-us-at-solidworks-world/</link>
		<comments>http://extensiblecad.com/words/2009/02/02/come-see-us-at-solidworks-world/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 08:49:21 +0000</pubDate>
		<dc:creator>Jeff Cope</dc:creator>
				<category><![CDATA[MS Office]]></category>
		<category><![CDATA[SolidWorks]]></category>
		<category><![CDATA[SolidWorks Enterprise PDM]]></category>

		<guid isPermaLink="false">http://extensiblecad.com/words/?p=157</guid>
		<description><![CDATA[Extensible CAD will be exhibiting in booth #2 at SolidWorks World this year.  We will be showing InspectionXpert for SolidWorks, InspectionXpert First-Article and Office2PDM.  InspectionXpert is software that automates the creation of first article inspection sheets from CAD drawings.  Office2PDM is an addin for MS Office that enables you to work with Enterprise PDM from [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://extensiblecad.com/words/wp-content/uploads/2007/10/jeffcopeteaser.jpg"><img class="size-medium wp-image-12 alignleft" title="Jeff Cope" src="http://extensiblecad.com/words/wp-content/uploads/2007/10/jeffcopeteaser.jpg" alt="" width="67" height="70" /></a>Extensible CAD will be exhibiting in booth #2 at SolidWorks World this year.  We will be showing InspectionXpert for SolidWorks, InspectionXpert First-Article and Office2PDM.  InspectionXpert is software that automates the creation of first article inspection sheets from CAD drawings.  Office2PDM is an addin for MS Office that enables you to work with Enterprise PDM from inside of Word, Powerpoint and Excel.</p>
<p>I will also be presenting personally on Enterprise PDM Customization on Monday at 1:30pm.  Unfortunately they scheduled me at the same time as Joy Garon&#8217;s What&#8217;s New In EPDM 2009 but that is just how it goes.  Stop by my session if you can and if not, then stop by our booth and say hello.</p>
	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<small><p>&copy; Jeff Cope for <a href="http://extensiblecad.com/words">Extensible By Design</a>, 2009. |
	<a href="http://extensiblecad.com/words/2009/02/02/come-see-us-at-solidworks-world/">Permalink</a> |
	<a href="http://extensiblecad.com/words/2009/02/02/come-see-us-at-solidworks-world/#comments">One comment</a> |
	Add to
	<a href="http://del.icio.us/post?url=http://extensiblecad.com/words/2009/02/02/come-see-us-at-solidworks-world/&amp;title=Come See Us At SolidWorks World"><img src="http://yoursite.com/images/icons/delicious.gif" border="0"> del.icio.us</a>
	<a href="http://www.digg.com/submit"><img src="http://yoursite.com/images/digg.gif" border="0"> digg</a><br/>
	Who's linking ?
	<a href="http://www.technorati.com/search/http://extensiblecad.com/words/2009/02/02/come-see-us-at-solidworks-world/" title="Search on Technorati"><img src="http://yoursite.com/images/icons/technorati.gif" border="0">Technorati</a>
	<a href="http://www.blogpulse.com/search?query=http://extensiblecad.com/words/2009/02/02/come-see-us-at-solidworks-world/" title="Search on Blogpulse"><img src="http://yoursite.com/images/icons/blogpulse.gif" border="0">BlogPulse</a>
	<a href="http://google.com/blogsearch?q=http://extensiblecad.com/words/2009/02/02/come-see-us-at-solidworks-world/" title="Search on Google Blog Search"><img src="http://yoursite.com/images/icons/google.gif" border="0">Google</a><br/>
	Want more on these topics ? Browse the archive of posts filed under <a href="http://extensiblecad.com/words/category/ms-office/" title="View all posts in MS Office" rel="category tag">MS Office</a>, <a href="http://extensiblecad.com/words/category/solidworks/" title="View all posts in SolidWorks" rel="category tag">SolidWorks</a>, <a href="http://extensiblecad.com/words/category/pdmplm/solidworks-enterprise-pdm-pdmplm/" title="View all posts in SolidWorks Enterprise PDM" rel="category tag">SolidWorks Enterprise PDM</a>.</small></p>
<p>Copyright 2007 <a href=http://extensiblecad.com/words>Extensible By Design.</a>  All rights reserved.</p>]]></content:encoded>
			<wfw:commentRss>http://extensiblecad.com/words/2009/02/02/come-see-us-at-solidworks-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GetObject( ) or CreateObject( )? Is there a difference? &#8211; Part III</title>
		<link>http://extensiblecad.com/words/2007/10/11/getobject-or-createobject-is-there-a-difference-part-iii/</link>
		<comments>http://extensiblecad.com/words/2007/10/11/getobject-or-createobject-is-there-a-difference-part-iii/#comments</comments>
		<pubDate>Thu, 11 Oct 2007 05:24:59 +0000</pubDate>
		<dc:creator>Jeff Cope</dc:creator>
				<category><![CDATA[CAD]]></category>
		<category><![CDATA[MS Office]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[SolidWorks]]></category>
		<category><![CDATA[SolidWorks API]]></category>

		<guid isPermaLink="false">http://extensiblecad.com/words/?p=17</guid>
		<description><![CDATA[At the end of my last post on this topic, I promised you that I would share a &#8220;dirty secret&#8221; so I guess I now have to come clean. FYI &#8211; &#8220;Dirty secret&#8221; may have been a bit strong but it sounded cool (at least to me). Anyways, there is a difference between how SolidWorks [...]]]></description>
			<content:encoded><![CDATA[<p>At the end of my last post on this topic, I promised you that I would share a &#8220;dirty secret&#8221; so I guess I now have to come clean.  FYI &#8211; &#8220;Dirty secret&#8221; may have been a bit strong but it sounded cool (at least to me).  Anyways, there is a difference between how SolidWorks handles CreateObject( ) and how MS Office products handle CreateObject( ).  This is something to be aware of when automating across applications.</p>
<p>What is the difference?  In a nutshell, calling CreateObject( ) on an MS Office application interface will always create a new instance of the application and then return a handle to that instance.  Calling CreateObject( )  on the SldWorks.Application interface will only create a new instance of SolidWorks if one isn&#8217;t already running.   This basically ensures that only one instance of SolidWorks at a time is ever automated by your Macro.  This is a <a href="http://en.wikipedia.org/wiki/Singleton_pattern" target="_blank" title="The Singleton Design Pattern">basic coding pattern called &#8220;the Singleton&#8221;</a> and it prevents untold suffering and countless tears.  SolidWorks is so kind to us and many of us didn&#8217;t even know it.</p>
<p>Below are two Macros <span id="more-17"></span>to illustrate the difference between SolidWorks and MS Office applications with regard to CreateObject( ).  The first is an Excel Macro that automates SolidWorks and the second is a SolidWorks Macro that automates Excel.  If you copy/paste the code, be sure you add references in each Macro project to the object library of the application you are automating.  If you don&#8217;t know what the heck I am talking about, then just download the complete files <a href="http://extensiblecad.com/words/wp-content/uploads/2007/10/createobjectxlvsswx.zip" title="CreateObjectXLvsSWX">from here. </a></p>
<ul>
<li>Excel Macro to automate SolidWorks:</li>
</ul>
<blockquote><p><font color="#009933">&#8216;Copyright 2007 by Extensible CAD Technologies, LLC &#8211; All rights reserved<br />
&#8216;Written 10/10/2007 by Jeff Cope<br />
&#8216;User assumes all risk for using the code below.</font></p>
<p>Sub AutomateSolidWorks()</p>
<p><font color="#009933">&#8216;Declare three handles to SolidWorks instances.</font><br />
<font color="#330099">Dim</font> swx1 <font color="#330099">As</font> SldWorks.SldWorks<br />
<font color="#330099">Dim</font> swx2 <font color="#330099">As</font> SldWorks.SldWorks<br />
<font color="#330099">Dim</font> swx3 <font color="#330099">As</font> SldWorks.SldWorks</p>
<p><font color="#009933">&#8216;Use CreateObject( ) for the first instance.  A new instance of SolidWorks IS NOT created.<br />
&#8216;Note:  As we showed previously, using GetObject( ) without a filepath argument here would<br />
&#8216;return an error since no instances of SolidWorks are available to attach to yet.</font><br />
<font color="#330099">Set</font> swx1 = CreateObject(&#8220;SldWorks.Application&#8221;)<br />
<font color="#009933">&#8216;Use CreateObject( ) for the first instance.  A new instance of SolidWorks IS NOT created.</font><br />
<font color="#330099">Set</font> swx2 = CreateObject(&#8220;SldWorks.Application&#8221;)<br />
<font color="#009933">&#8216;Use GetObject( ) for the first instance.  A new instance of SolidWorks IS NOT created.</font><br />
<font color="#330099">Set</font> swx3 = GetObject(, ”SldWorks.Application”)<br />
<font color="#009933">&#8216;At this point, we should only have one SolidWorks window open and one SolidWorks process running.<br />
&#8216;Add new parts using each of the three handles</font></p>
<p>swx1.NewPart<br />
swx2.NewPart<br />
swx3.NewPart<br />
<font color="#009933">&#8216;We should now have one SolidWorks window open with three new SolidWorks parts loaded.</font></p>
<p><font color="#009933"><font color="#330099">End Sub</font></font></p></blockquote>
<ul>
<li>SolidWorks Macro to automate Excel:</li>
</ul>
<blockquote><p><font color="#009933">&#8216;Copyright 2007 by Extensible CAD Technologies, LLC &#8211; All rights reserved<br />
&#8216;Written 10/10/2007 by Jeff Cope<br />
&#8216;User assumes all risk for using the code below.</font></p>
<p><font color="#009933">&#8216;Declare three instances of the Excel.Application interface</font><br />
<font color="#330099">Dim</font> xl1 <font color="#330099">As</font> Excel.Application<br />
<font color="#330099">Dim</font> xl2 <font color="#330099">As</font> Excel.Application<br />
<font color="#330099">Dim</font> xl3 <font color="#330099">As</font> Excel.Application</p>
<p><font color="#330099">Sub</font> main()</p>
<p><font color="#009933">&#8216;Use CreateObject( ) for the first instance.  A new instance of Excel is created.</font><br />
<font color="#330099">Set </font>xl1 = CreateObject(&#8220;Excel.Application&#8221;)<br />
<font color="#009933">&#8216;A new Workbook gets added to this instance</font><br />
xl1.Workbooks.Add<br />
<font color="#009933">&#8216;Make the instance visible so we can see what is happening</font><br />
xl1.Visible = True</p>
<p><font color="#009933">&#8216;Use CreateObject( )for the first instance.  A new instance of Excel is created.</font><br />
<font color="#330099">Set</font> xl2 = CreateObject(&#8220;Excel.Application&#8221;)<br />
<font color="#009933">&#8216;A new Workbook gets added to this instance</font><br />
xl2.Workbooks.Add<br />
<font color="#009933">&#8216;Make the instance visible so we can see what is happening</font><br />
xl2.Visible = True<br />
<font color="#009933">&#8216;At this point, we should be able to see two Excel windows running and each should have a</font><br />
<font color="#009933">&#8216;new Workbook added.</font></p>
<p><font color="#009933">&#8216;Use GetObject( ) for the first instance.  A new instance of Excel IS NOT created.  A handle<br />
&#8216;is simply returned to one of the existing instances (usually xl1).</font><br />
<font color="#330099">Set</font> xl3 = GetObject(, &#8220;Excel.Application&#8221;)<br />
<font color="#009933">&#8216;A new Workbook gets added to this instance</font><br />
xl3.Workbooks.Add<br />
<font color="#009933">&#8216;Make the instance visible so we can see what is happening</font><br />
xl3.Visible = True<br />
<font color="#009933">&#8216;At this point in the Macro&#8217;s execution, we should see two Excel windows (and two Excel processes)<br />
&#8216;running.  However, we have three handles to Excel instances so two of the handles are pointing<br />
&#8216;to the same Excel instance.</font></p>
<p><font color="#009933">&#8216;Release handles to COM objects</font><br />
<font color="#330099">Set</font> xl1 = Nothing<br />
<font color="#330099">Set</font> xl2 = Nothing<br />
<font color="#330099">Set</font> xl3 = Nothing</p>
<p><font color="#009933">&#8216;One of the Excel windows will have two Workbooks in it instead of one.  Note:  If you<br />
&#8216;want to know which one, then just leave one of the instances invisible.<br />
</font><font color="#330099">End Sub</font></p></blockquote>
	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<small><p>&copy; Jeff Cope for <a href="http://extensiblecad.com/words">Extensible By Design</a>, 2007. |
	<a href="http://extensiblecad.com/words/2007/10/11/getobject-or-createobject-is-there-a-difference-part-iii/">Permalink</a> |
	<a href="http://extensiblecad.com/words/2007/10/11/getobject-or-createobject-is-there-a-difference-part-iii/#comments">One comment</a> |
	Add to
	<a href="http://del.icio.us/post?url=http://extensiblecad.com/words/2007/10/11/getobject-or-createobject-is-there-a-difference-part-iii/&amp;title=GetObject( ) or CreateObject( )? Is there a difference? &#8211; Part III"><img src="http://yoursite.com/images/icons/delicious.gif" border="0"> del.icio.us</a>
	<a href="http://www.digg.com/submit"><img src="http://yoursite.com/images/digg.gif" border="0"> digg</a><br/>
	Who's linking ?
	<a href="http://www.technorati.com/search/http://extensiblecad.com/words/2007/10/11/getobject-or-createobject-is-there-a-difference-part-iii/" title="Search on Technorati"><img src="http://yoursite.com/images/icons/technorati.gif" border="0">Technorati</a>
	<a href="http://www.blogpulse.com/search?query=http://extensiblecad.com/words/2007/10/11/getobject-or-createobject-is-there-a-difference-part-iii/" title="Search on Blogpulse"><img src="http://yoursite.com/images/icons/blogpulse.gif" border="0">BlogPulse</a>
	<a href="http://google.com/blogsearch?q=http://extensiblecad.com/words/2007/10/11/getobject-or-createobject-is-there-a-difference-part-iii/" title="Search on Google Blog Search"><img src="http://yoursite.com/images/icons/google.gif" border="0">Google</a><br/>
	Want more on these topics ? Browse the archive of posts filed under <a href="http://extensiblecad.com/words/category/cad/" title="View all posts in CAD" rel="category tag">CAD</a>, <a href="http://extensiblecad.com/words/category/ms-office/" title="View all posts in MS Office" rel="category tag">MS Office</a>, <a href="http://extensiblecad.com/words/category/macros/" title="View all posts in Macros" rel="category tag">Macros</a>, <a href="http://extensiblecad.com/words/category/solidworks/" title="View all posts in SolidWorks" rel="category tag">SolidWorks</a>, <a href="http://extensiblecad.com/words/category/solidworks/solidworks-api/" title="View all posts in SolidWorks API" rel="category tag">SolidWorks API</a>.</small></p>
<p>Copyright 2007 <a href=http://extensiblecad.com/words>Extensible By Design.</a>  All rights reserved.</p>]]></content:encoded>
			<wfw:commentRss>http://extensiblecad.com/words/2007/10/11/getobject-or-createobject-is-there-a-difference-part-iii/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>GetObject( ) or CreateObject( )? Is there a difference? &#8211; Part II</title>
		<link>http://extensiblecad.com/words/2007/10/08/getobject-or-createobject-is-there-a-difference-part-ii/</link>
		<comments>http://extensiblecad.com/words/2007/10/08/getobject-or-createobject-is-there-a-difference-part-ii/#comments</comments>
		<pubDate>Mon, 08 Oct 2007 18:52:30 +0000</pubDate>
		<dc:creator>Jeff Cope</dc:creator>
				<category><![CDATA[CAD]]></category>
		<category><![CDATA[MS Office]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[SolidWorks]]></category>
		<category><![CDATA[SolidWorks API]]></category>

		<guid isPermaLink="false">http://extensiblecad.com/words/?p=13</guid>
		<description><![CDATA[Last time I explained how the SolidWorks application object behaves differently depending on whether it is instantiated via CreateObject( ) or GetObject( ). So now you are probably thinking, &#8220;That&#8217;s it? That was too easy.&#8221; Well, I don&#8217;t want to be one to disappoint so I will let you in on the rest of the [...]]]></description>
			<content:encoded><![CDATA[<p>Last time I explained how the SolidWorks application object behaves differently depending on whether it is instantiated via CreateObject( ) or GetObject( ). So now you are probably thinking, &#8220;That&#8217;s it? That was too easy.&#8221; Well, I don&#8217;t want to be one to disappoint so I will let you in on the rest of the story including a dirty little secret.</p>
<p>So what else is there? The GetObject( ) call has another trick up its sleeve that I didn&#8217;t discuss last time. Taking a look at its Intellisense signature provides a clue as to what this is.</p>
<p><img vspace="5" align="bottom" width="509" src="http://extensiblecad.com/words/wp-content/uploads/2007/10/intellisense.JPG" hspace="10" alt="GetObject signature" height="292" style="width: 509px; height: 292px" title="GetObject signature" /></p>
<p>In the method signature you actually see two parameters,<span id="more-13"></span> PathName and Class. We know the Class is &#8220;SldWorks.SldWorks&#8221; but what is this PathName and to where does this path lead? Well, it turns out that this is the path to a SolidWorks file and that GetObject is so cool that not only can it return a reference to a SolidWorks application interface (e.g. SldWorks.SldWorks), it can also return a reference to a SolidWorks file as well.</p>
<p>Below are some examples on how you can use GetObject( ).</p>
<ul>
<li>Example 1 &#8211; The first example is basically review from the last post.  This code will usually get you a handle to an already running session of SolidWorks (i.e. a handle to an instance of the SldWorks.SldWorks class)</li>
</ul>
<blockquote>
<blockquote><p><font color="#009933"><font color="#330099">Dim<font color="#009933"> </font><font color="#000000">swapp</font><font color="#009933"> </font><font color="#330099">As </font><font color="#009933">SldWorks.ModelDoc2</font></font><br />
</font><font color="#330099">Set<font color="#000000"> swapp = GetObject(, “SldWorks.Application”)</font></font></p></blockquote>
</blockquote>
<ul>
<li>Example 2 &#8211; Iff (if and only if) you have &#8220;SLDPRT&#8221; associated with SolidWorks on your machine, then the code below will usually get you a handle to a SolidWorks document (i.e. a handle to an instance of the ModelDoc2 class) that resides at the address of &#8220;C:\myFiles\myPart.SLDPRT.&#8221; Note: In this particular case, an instance of SolidWorks will be created even if one doesn&#8217;t already exist. This was glossed over last time.</li>
</ul>
<blockquote>
<blockquote><p><font color="#330099">Dim</font><font color="#009933"> </font><font color="#000000">swDoc</font><font color="#009933"> </font><font color="#330099">As </font><font color="#009933">SldWorks.SldWorks<br />
</font><font color="#330099">Set</font> swDoc = GetObject(&#8220;C:\MyFiles\myPart.SLDPRT&#8221;)</p></blockquote>
</blockquote>
<ul>
<li>Example 3 &#8211; The code below will usually get you a handle to a SolidWorks document (i.e. a handle to an instance of the ModelDoc2 class) that resides at the address of &#8220;C:\myFiles\myPart.SLDPRT.&#8221; This is irregardless of whether or not you have &#8220;SLDPRT&#8221; associated with SolidWorks on your machine. Again, in this particular case, an instance of SolidWorks will be created even if one doesn&#8217;t already exist.</li>
</ul>
<blockquote>
<blockquote><p><font color="#330099">Dim</font><font color="#009933"> </font><font color="#000000">swDoc</font><font color="#009933"> </font><font color="#330099">As </font><font color="#009933">SldWorks.SldWorks<br />
</font><font color="#330099">Set</font> swDoc = GetObject(&#8220;C:\MyFiles\myPart.SLDPRT&#8221;<font color="#330099"><font color="#000000">, _ “SldWorks.Application”</font></font>)</p></blockquote>
</blockquote>
<p>In a nutshell, GetObject can also be used to return a handle to a specific file.  To do this you simply include the path to the file as the first argument.  If you do this, then the second argument becomes optional unless you don&#8217;t have the particular file&#8217;s extension associated to the application in which you desire to open it.</p>
<p>&#8220;Ok Jeff. That&#8217;s pretty cool but what about that dirty little secret you promised us?&#8221;</p>
<p>We&#8217;ll have to save that for Part III and the final installment. I&#8217;ll give you a little hint, though. SolidWorks and Microsoft don&#8217;t make ALL of the same mistakes. Some but not ALL.</p>
	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<small><p>&copy; Jeff Cope for <a href="http://extensiblecad.com/words">Extensible By Design</a>, 2007. |
	<a href="http://extensiblecad.com/words/2007/10/08/getobject-or-createobject-is-there-a-difference-part-ii/">Permalink</a> |
	<a href="http://extensiblecad.com/words/2007/10/08/getobject-or-createobject-is-there-a-difference-part-ii/#comments">No comment</a> |
	Add to
	<a href="http://del.icio.us/post?url=http://extensiblecad.com/words/2007/10/08/getobject-or-createobject-is-there-a-difference-part-ii/&amp;title=GetObject( ) or CreateObject( )? Is there a difference? &#8211; Part II"><img src="http://yoursite.com/images/icons/delicious.gif" border="0"> del.icio.us</a>
	<a href="http://www.digg.com/submit"><img src="http://yoursite.com/images/digg.gif" border="0"> digg</a><br/>
	Who's linking ?
	<a href="http://www.technorati.com/search/http://extensiblecad.com/words/2007/10/08/getobject-or-createobject-is-there-a-difference-part-ii/" title="Search on Technorati"><img src="http://yoursite.com/images/icons/technorati.gif" border="0">Technorati</a>
	<a href="http://www.blogpulse.com/search?query=http://extensiblecad.com/words/2007/10/08/getobject-or-createobject-is-there-a-difference-part-ii/" title="Search on Blogpulse"><img src="http://yoursite.com/images/icons/blogpulse.gif" border="0">BlogPulse</a>
	<a href="http://google.com/blogsearch?q=http://extensiblecad.com/words/2007/10/08/getobject-or-createobject-is-there-a-difference-part-ii/" title="Search on Google Blog Search"><img src="http://yoursite.com/images/icons/google.gif" border="0">Google</a><br/>
	Want more on these topics ? Browse the archive of posts filed under <a href="http://extensiblecad.com/words/category/cad/" title="View all posts in CAD" rel="category tag">CAD</a>, <a href="http://extensiblecad.com/words/category/ms-office/" title="View all posts in MS Office" rel="category tag">MS Office</a>, <a href="http://extensiblecad.com/words/category/macros/" title="View all posts in Macros" rel="category tag">Macros</a>, <a href="http://extensiblecad.com/words/category/solidworks/" title="View all posts in SolidWorks" rel="category tag">SolidWorks</a>, <a href="http://extensiblecad.com/words/category/solidworks/solidworks-api/" title="View all posts in SolidWorks API" rel="category tag">SolidWorks API</a>.</small></p>
<p>Copyright 2007 <a href=http://extensiblecad.com/words>Extensible By Design.</a>  All rights reserved.</p>]]></content:encoded>
			<wfw:commentRss>http://extensiblecad.com/words/2007/10/08/getobject-or-createobject-is-there-a-difference-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GetObject( ) or CreateObject( )?  Is there a difference?   &#8211; Part I</title>
		<link>http://extensiblecad.com/words/2007/10/04/getobject-or-createobject-is-there-a-difference/</link>
		<comments>http://extensiblecad.com/words/2007/10/04/getobject-or-createobject-is-there-a-difference/#comments</comments>
		<pubDate>Fri, 05 Oct 2007 03:23:25 +0000</pubDate>
		<dc:creator>Jeff Cope</dc:creator>
				<category><![CDATA[CAD]]></category>
		<category><![CDATA[MS Office]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[SolidWorks]]></category>
		<category><![CDATA[SolidWorks API]]></category>

		<guid isPermaLink="false">http://extensiblecad.com/words/?p=8</guid>
		<description><![CDATA[Disclaimer: 99.9% of all the API programming I do these days is in .NET so for the times that I do answer a question incorrectly, 80% of the time it is a VBA (Visual Basic for Applications) question. Since most people start with VBA before they move on to .NET, however, I decided to cover [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Disclaimer:</strong> 99.9% of all the API programming I do these days is in .NET so for the times that I do answer a question incorrectly, 80% of the time it is a VBA (Visual Basic for Applications) question. Since most people start with VBA before they move on to .NET, however, I decided to cover this topic for VBA.</p>
<p><font color="#330099">Set </font>swApp = CreateObject(&#8220;SldWorks.Application&#8221;)</p>
<p>Almost all SolidWorks Macros start out with that same, famous line of code. In fact, whenever you record a Macro in SolidWorks, the SolidWorks Macro Recorder is kind enough to fill that line in for you. What does it really mean, though? And why do a few Macros begin instead with this line of code:</p>
<p><font color="#330099">Set</font> swApp = GetObject(,&#8221;SldWorks.Application&#8221;)</p>
<p><span id="more-8"></span>Is there a difference? If there were no difference, then this would be a very short article. You have probably guessed correctly that there is a difference. The GetObject( ) call will attach to an existing instance of <a href="http://www.solidworks.com/">SolidWorks</a> if one is running. If there is no instance of SolidWorks already running, then GetObject( ) will return an error. The CreateObject( ) call will also attach to an existing instance of SolidWorks if one is running. However, if there is no instance of SolidWorks already running, then CreateObject( ) will create one and attach to it. Because of this, most Macros contain the CreateObject( ) call as a way of hedging bets.</p>
<p>Why should I care? This behavior can be used to your advantage when you run into situations where you need to know if the application being called was running before you called it. You might need to know, for instance, whether or not to shut down Excel when your Macro is finished.Let&#8217;s say, for example, that a user who already has Excel up and running decides to run your Macro. If your Macro arbitrarily closes Excel when it is finished, then any unsaved changes to Workbooks will be lost. This could make you the target of nasty phone calls and maybe even litigation. One solution is to leave Excel running. This is not a desirable solution because of the resources that would be tied up by Excel (or any other application that you start up and leave running when finished). It is also a slight breach of programming etiquette.</p>
<p>How do I use this to my advantage? It is very simple.You start out by declaring an &#8216;alreadyRunning&#8217; flag (i.e. a Boolean variable) and then you make a call to GetObject ( ). If that call doesn&#8217;t throw an error, then you make sure that &#8216;alreadyRunning&#8217; is set to True and you procede with your Macro. If, however, the GetObject( ) call throws an error, then you make sure &#8216;alreadyRunning&#8217; is set to False and you make a subsequent call to CreateObject( ). From there, you proceed with your Macro and at the end of your Macro, you put a line of code in that will close Excel because alreadyRunning=False<span style="color: red"><span style="font-size: 7.5pt; color: black; line-height: 115%; font-family: 'Verdana','sans-serif'">. </span></span></p>
<p><span style="color: red"><span style="font-size: 7.5pt; color: black; line-height: 115%; font-family: 'Verdana','sans-serif'"></span><span style="color: black"></span></span><span style="color: red"></span>Below is sample code for an Excel Macro (i.e. written for and residing in Excel) that employs this method. In this example, however, it is SolidWorks itself that needs to be either closed or left running depending on its state at Macro execution time. Because of this, the &#8216;alreadyRunning&#8217; variable mentioned above is called &#8220;swxAlreadyOpen&#8221; for this specific application of the concept.You can <a href="http://www.extensiblecad.com/downloads/GetObjectVersusCreateObject.zip">download the files for this example from here</a>.The Macro below will:</p>
<ol>
<li>Run upon opening the Excel Workbook that contains it</li>
<li>Open the specified (i.e. hard-coded) model in SolidWorks</li>
<li>Query the model for some information</li>
<li>Write that information to the Excel Spreadsheet</li>
<li>Close the model</li>
<li>Close SolidWorks if it wasn&#8217;t running when the Workbook was opened</li>
</ol>
<p>Disclaimer: The provider of this Macro assumes no liability for this Macro and makes no warranties for the Macro. Use at your own risk.</p>
<p>Note: This Macro builds upon an earlier and simpler example which can be downloaded from <a href="http://trimechsolutions.com/techresources/Macros101_ConcentricMate.zip">here.</a></p>
<p>Excuses: The Macro could benefit from some other programming best practices but I intentionally kept it as simple as possible so as to not confuse the readers.</p>
<p>**************Begin Excel Macro*********************</p>
<p><font color="#330099">Option Explicit</font></p>
<p><font color="#330099">Private Sub</font> Workbook_Open()<br />
<font color="#009933">&#8216;This event handler is called every time the workbook is opened in Excel.</font></p>
<p><font color="#330099">Dim</font> swapp <font color="#330099">As </font>SldWorks.SldWorks<br />
<font color="#009933">&#8216;Booleans have a default value of false.</font><br />
<font color="#330099">Dim</font> swxAlreadyOpen <font color="#330099">As Boolean</font><br />
<font color="#009933">&#8216;If the call below errors out, then we know SolidWorks wasn&#8217;t running. Workbook_OpenErrorHandler will handle this case for us.</font><br />
<font color="#330099">On Error GoTo</font> Workbook_OpenErrorHandler<br />
<font color="#009933">&#8216;Try to get a handle to an already running session of SolidWorks.</font><br />
<font color="#330099">Set</font> swapp = GetObject(, &#8220;SldWorks.Application&#8221;)<br />
<font color="#009933">&#8216;SolidWorks was already running. We know this because we would not have hit this line if SW was not running – the ErrorHandler would have already redirected us.</font></p>
<p>swxAlreadyOpen <font color="#330099">= True</font><br />
<font color="#009933">&#8216;Make sure we have a handle to SolidWorks.</font><br />
<font color="#330099">If Not</font> swapp <font color="#330099">Is Nothing Then<br />
</font><font color="#330099">Call</font><br />
populateSpreadsheet(swapp, Not swxAlreadyOpen)<br />
<font color="#330099">Else</font><br />
<font color="#009933">&#8216;Put a msgbox here to warn the user that the macro couldn&#8217;t attach to SolidWorks.</font><br />
<font color="#330099">Exit Sub<br />
End If<br />
Exit Sub</font><br />
Workbook_OpenErrorHandler:<br />
<font color="#009933">&#8216;GetObject() call errored out so we know that SolidWorks isn&#8217;t running yet.<br />
&#8216;Create a new instance of SolidWorks.</font><br />
<font color="#330099">Set</font> swapp = CreateObject(&#8220;SldWorks.Application&#8221;)<br />
<font color="#330099">If Not</font> swapp <font color="#330099">Is Nothing Then</font><br />
<font color="#330099">Call</font> populateSpreadsheet(swapp, Not swxAlreadyOpen)<br />
<font color="#330099">End If</font></p>
<p><font color="#330099"><font color="#009933">&#8216;Release COM objects</font><br />
<font color="#330099">Set</font><font color="#000000"> swApp = Nothing<br />
</font></font><font size="+0"><br />
</font><font size="1" color="#330099">End Sub</font></p>
<p><font color="#330099">Sub</font> populateSpreadsheet(<font color="#330099">ByRef</font> swapp <font color="#330099">As</font> SldWorks.SldWorks, <font color="#330099">ByVal</font><br />
closeSolidWorksWhenFinished <font color="#330099">As Boolean</font>)</p>
<p><font color="#330099">Dim</font> swDoc <font color="#330099">As </font>SldWorks.ModelDoc2<br />
<font color="#330099">Dim</font> swPart <font color="#330099">As </font>SldWorks.PartDoc<br />
<font color="#330099">Dim</font> swModelExt <font color="#330099">As </font>SldWorks.ModelDocExtension<br />
<font color="#330099">Dim</font> xSheet <font color="#330099">As </font>Excel.Worksheet<br />
<font color="#330099">Dim</font> xBook <font color="#330099">As </font>Excel.Workbook<br />
<font color="#330099">Dim</font> strPartPath <font color="#330099">As</font> String<br />
<font color="#330099">Dim</font> nErrors <font color="#330099">As </font>Long<br />
<font color="#330099">Dim</font> nWarnings <font color="#330099">As</font> Long<br />
<font color="#330099">Dim</font> nStatus <font color="#330099">As </font>Long<br />
<font color="#330099">Dim</font> sheetIndex <font color="#330099">As</font> Integer<br />
<font color="#330099">Dim</font> vMassProps <font color="#330099">As</font> Variant<br />
<font color="#009933">&#8216;Note: The file &#8220;Upper Fence &#8211; RH.SLDPRT&#8221; must reside in the same folder as this spreadsheet.</font><br />
strPartPath = Excel.ActiveWorkbook.Path<br />
strPartPath = strPartPath &amp; &#8220;\Upper Fence &#8211; RH.SLDPRT&#8221;</p>
<p><font color="#330099">Set</font> swDoc = swapp.OpenDoc6(strPartPath, swDocPART, swOpenDocOptions_Silent Or SwConst.swOpenDocOptions_ReadOnly, &#8220;&#8221;, nErrors,<br />
nWarnings)<br />
<font color="#330099">Set</font> swPart = swDoc<br />
<font color="#009933">&#8216;Since PartDoc inherits from ModelDoc2, we can query PartDoc for ModelDoc2.Extension</font><br />
<font color="#330099">Set</font> swModelExt = swPart.Extension<br />
<font color="#009933">&#8216;Get mass properties from modeldocextension object</font><br />
vMassProps = swModelExt.GetMassProperties(1, nStatus)</p>
<p><font color="#009933">&#8216;Loop through worksheets</font><br />
<font color="#330099">For Each</font> xSheet <font color="#330099">In</font> Excel.ActiveWorkbook.Sheets<br />
<font color="#330099">If</font> xSheet.Name = &#8220;PartProps&#8221; <font color="#330099">Then</font><br />
<font color="#009933">&#8216;Since PartDoc inherits from ModelDoc2, we can query PartDoc for ModelDoc2.GetTitle</font><br />
xSheet.Cells(1, 2).Value = swPart.GetTitle<br />
<font color="#009933">&#8216;Since PartDoc inherits from ModelDoc2, we can query PartDoc for ModelDoc2.GetPathName</font><br />
xSheet.Cells(2, 2).Value = swPart.GetPathName</p>
<p><font color="#330099">If Not</font> IsEmpty(vMassProps) <font color="#330099">Then</font><br />
<font color="#009933">&#8216;Mass</font><br />
xSheet.Cells(3, 2).Value = vMassProps(5)<br />
<font color="#009933">&#8216;Area</font><br />
xSheet.Cells(4, 2).Value = vMassProps(4)<br />
<font color="#009933">&#8216;Volume</font><br />
xSheet.Cells(5, 2).Value = vMassProps(3)<br />
<font color="#330099">Else </font><font color="#009933">&#8216;vMassProps is empty so just overwrite old<br />
values with question marks</font><br />
<font color="#009933">&#8216;Mass</font><br />
xSheet.Cells(3, 2).Value = &#8220;?&#8221;<br />
<font color="#009933">&#8216;Area</font><br />
xSheet.Cells(4, 2).Value = &#8220;?&#8221;<br />
<font color="#009933">&#8216;Volume</font><br />
xSheet.Cells(5, 2).Value = &#8220;?&#8221;<br />
<font color="#330099">End If<br />
End If<br />
Next</font><br />
<font color="#009933">&#8216;Close SolidWorks if it wasn&#8217;t already running. Otherwise, just close the document being queried.</font><br />
<font color="#330099">If</font> closeSolidWorksWhenFinished <font color="#330099">Then</font><br />
swapp.CloseAllDocuments (True)<br />
swapp.ExitApp<br />
<font color="#330099">Else</font><br />
swapp.QuitDoc (swDoc.GetTitle)<br />
<font color="#330099">End If<br />
</font><br />
<font color="#009933">&#8216;Release COM objects</font><br />
<font color="#330099">Set</font> swPart = Nothing<br />
<font color="#330099">Set</font> swModelExt = Nothing<br />
<font color="#330099">Set</font> swDoc = Nothing<br />
<font color="#330099">End Sub</font></p>
<p>**************End Excel Macro*********************</p>
<p>Thanks to Wayne Tiffany who contributed to this article.</p>
	<p></p>
	<hr noshade style="margin:0;height:1px" />
	<small><p>&copy; Jeff Cope for <a href="http://extensiblecad.com/words">Extensible By Design</a>, 2007. |
	<a href="http://extensiblecad.com/words/2007/10/04/getobject-or-createobject-is-there-a-difference/">Permalink</a> |
	<a href="http://extensiblecad.com/words/2007/10/04/getobject-or-createobject-is-there-a-difference/#comments">3 comments</a> |
	Add to
	<a href="http://del.icio.us/post?url=http://extensiblecad.com/words/2007/10/04/getobject-or-createobject-is-there-a-difference/&amp;title=GetObject( ) or CreateObject( )?  Is there a difference?   &#8211; Part I"><img src="http://yoursite.com/images/icons/delicious.gif" border="0"> del.icio.us</a>
	<a href="http://www.digg.com/submit"><img src="http://yoursite.com/images/digg.gif" border="0"> digg</a><br/>
	Who's linking ?
	<a href="http://www.technorati.com/search/http://extensiblecad.com/words/2007/10/04/getobject-or-createobject-is-there-a-difference/" title="Search on Technorati"><img src="http://yoursite.com/images/icons/technorati.gif" border="0">Technorati</a>
	<a href="http://www.blogpulse.com/search?query=http://extensiblecad.com/words/2007/10/04/getobject-or-createobject-is-there-a-difference/" title="Search on Blogpulse"><img src="http://yoursite.com/images/icons/blogpulse.gif" border="0">BlogPulse</a>
	<a href="http://google.com/blogsearch?q=http://extensiblecad.com/words/2007/10/04/getobject-or-createobject-is-there-a-difference/" title="Search on Google Blog Search"><img src="http://yoursite.com/images/icons/google.gif" border="0">Google</a><br/>
	Want more on these topics ? Browse the archive of posts filed under <a href="http://extensiblecad.com/words/category/cad/" title="View all posts in CAD" rel="category tag">CAD</a>, <a href="http://extensiblecad.com/words/category/ms-office/" title="View all posts in MS Office" rel="category tag">MS Office</a>, <a href="http://extensiblecad.com/words/category/macros/" title="View all posts in Macros" rel="category tag">Macros</a>, <a href="http://extensiblecad.com/words/category/solidworks/" title="View all posts in SolidWorks" rel="category tag">SolidWorks</a>, <a href="http://extensiblecad.com/words/category/solidworks/solidworks-api/" title="View all posts in SolidWorks API" rel="category tag">SolidWorks API</a>.</small></p>
<p>Copyright 2007 <a href=http://extensiblecad.com/words>Extensible By Design.</a>  All rights reserved.</p>]]></content:encoded>
			<wfw:commentRss>http://extensiblecad.com/words/2007/10/04/getobject-or-createobject-is-there-a-difference/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
