<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
    <title>Mod the Machine</title>
    
    <link rel="alternate" type="text/html" href="http://modthemachine.typepad.com/my_weblog/" />
    <id>tag:typepad.com,2003:weblog-1713640</id>
    <updated>2013-05-20T12:09:41-07:00</updated>
    <subtitle>Discussing Autodesk Inventor's Application Programming Interface (API)</subtitle>
    <generator uri="http://www.typepad.com/">TypePad</generator>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/modthemachine" /><feedburner:info uri="modthemachine" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
        <title>2013 Inventor API Survey</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/0ni74E_T808/2013-inventor-api-survey.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/05/2013-inventor-api-survey.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc688340192aa21c51b970d</id>
        <published>2013-05-20T12:09:41-07:00</published>
        <updated>2013-05-20T12:09:41-07:00</updated>
        <summary>It’s time again for the annual API survey. Please help us help you by taking a few minutes and filling out the survey. Everyone is welcome to respond. Your answers help us to determine what to work on in upcoming...</summary>
        <author>
            <name>Wayne Brill</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Announcements" />
        <category scheme="http://www.sixapart.com/ns/types#category" term="Wayne" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834019102597258970c-pi"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTMLe8d8f5" border="0" alt="SNAGHTMLe8d8f5" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834019102597263970c-pi" width="479" height="168" /></a></p>  <p>It’s time again for the annual API survey. <u>Please</u> help us help you by taking a few minutes and filling out the survey. Everyone is welcome to respond. Your answers help us to determine what to work on in upcoming releases of Inventor and help us to justify resources to work on API enhancements. The more responses we get the more we know people care about the API and the more accurate the results will be so we can work on the areas that will best benefit the majority of those using the API.</p>  <p>In question 5 you have a virtual $100 to spend on different API enhancements. Here’s the link to the survey and thank you for taking the time to respond.</p> <a href="https://www.surveymonkey.com/s/Autodesk-Inventor-API-Wishlist-Survey-2013" target="_blank">Click here to take survey</a>   <br />  <p>Note: The survey is ending on the 16th of June.</p>  <p>See this <a href="http://modthemachine.typepad.com/my_weblog/2012/07/inventor-api-wishlist-2012-survey-results.html" target="_blank">post</a> to see the results from the 2012 survey.</p>  <p>-Wayne</p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/05/2013-inventor-api-survey.html</feedburner:origLink></entry>
    <entry>
        <title>Inventor 2014 new API for sketch creation</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/Oth6ATUJwOM/inventor-2014-new-api-for-sketch-creation.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/05/inventor-2014-new-api-for-sketch-creation.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc688340191022e3731970c</id>
        <published>2013-05-15T15:41:08-07:00</published>
        <updated>2013-05-15T15:45:20-07:00</updated>
        <summary>There are four new API enhancements for sketches. Three of them create sketch curves that could be created from the UI in previous releases. One of the enhancements is new in the UI too. Slots In the 2014 release you...</summary>
        <author>
            <name>Wayne Brill</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Wayne" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>There are four new API enhancements for sketches. Three of them create sketch curves that could be created from the UI in previous releases. One of the enhancements is new in the UI too.</p>
<p><strong>Slots</strong></p>
<p>In the 2014 release you can now easily create slots. </p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc688340191022e36eb970c-pi"><img alt="image" border="0" height="181" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc688340191022e3713970c-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="402" /></a> </p>
<p>Creating slots in the API is accomplished by calling one of these Add methods that are on several different sketch objects:</p>
<p><em>AddArcSlotByCenterPointArc      <br />AddArcSlotByThreePointArc       <br />AddStraightSlotByCenterToCenter       <br />AddStraightSlotByOverall</em></p>
<p>Here is the signature for <em>AddArcSlotByCenterPointArc:</em></p>
<p><em>Sketch.AddArcSlotByCenterPointArc( CenterPoint As Object, StartPoint As Object, SweepAngle As Double, Width As Double )</em></p>
<p><strong>Equation curves</strong></p>
<p>Inventor 2013 added the ability to create sketch curves using equations. Now you can create curves using equations with the API. The SketchEquationCurve object represents an equation curve within a sketch. Different sketch objects have a SketchEquationCurves collection and you use the Add method to create a SketchEquationCurve. If you have not used equation curves before I would suggest looking at the Inventor help file to see how to create these from the UI. Once you understand how these curves are created in the user interface the arguments in the SketchEquationCurves.Add method will be easier to understand. Here is the signature :</p>
<p><em>SketchEquationCurves.Add( EquationType As CurveEquationTypeEnum, CoordinateSystemType As CoordinateSystemTypeEnum, XValueOrRadius As String, YValueOrTheta As String, MinValue As Variant, MaxValue As Variant )      <br /></em></p>
<p><strong>Intersection Curves</strong> </p>
<p>This is another API enhancement that is catching up to the UI. The IntersectionCurve object represents the results of creating an intersection between different types of geometry. The Sketch3d and Sketch3dProxy now have an IntersectionCurves collection. You use the Add method to create an IntersectionCurve.  Here is the signature:</p>
<p><em>IntersectionCurves.Add( EntityOne As Object, EntityTwo As Object )</em></p>
<p><strong>Control point splines</strong></p>
<p>Inventor 2013 introduced the ability to create splines using control points. The 2014 API can now create this type of spline. Both 2D and 3D sketch objects have a SketchControlPointSplines collection. (SketchControlPointSplines3D) Use the Add method to create these splines. Here is the signature:</p>
<p><em>SketchControlPointSplines.Add( ControlPoints As ObjectCollection )</em></p>
<p><strong>C# example:</strong></p>
<p>Below is one of the functions from this C# project which was translated from the VBA example in the help file. The c# project also has a CreateSlots() function that creates sketch curves by calling the four different methods for creating slots.</p>
<p> 
<span class="asset  asset-generic at-xid-6a00e553fcbfc6883401901c384154970b"><a href="http://modthemachine.typepad.com/files/inventor_2014_sketch_examples.zip">Download Inventor_2014_Sketch_Examples</a></span></p>
<p>SketchCurves does the following: </p>
<p>1. Creates a sketch and adds a SketchControlPointSpline</p>
<p>2. Creates another sketch and adds a SketchEquationCurve</p>
<p>3. Creates a Sketch3D and adds a SketchControlPointSpline3D</p>
<p>4. Adds a SketchEquationCurve3D to the Sketch3D</p>
<p>5. Adds a surface feature using a profile created using the SketchControlPointSpline from sketch. (step 1)</p>
<p>6. Adds a surface feature using a profile created using the SketchEquationCurve from sketch2. (step 2)</p>
<p>7. Creates another Sketch3D named interSketch, This sketch uses IntersectionCurves.Add</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc6883401901c3835fe970b-pi"><img alt="image" border="0" height="358" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017eeb359e02970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" width="465" /></a></p>
<p>After running the code a new part is created with the geometry</p>
<p> </p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">void</span> SketchCurves()</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;">    <span style="color: green;">// Create a new part.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">PartDocument</span> partDoc = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">PartDocument</span>)ThisApplication.Documents.Add</p>
<p style="margin: 0px;">             (<span style="color: #2b91af;">DocumentTypeEnum</span>.kPartDocumentObject, </p>
<p style="margin: 0px;">       ThisApplication.FileManager.GetTemplateFile</p>
<p style="margin: 0px;">             (<span style="color: #2b91af;">DocumentTypeEnum</span>.kPartDocumentObject));</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: #2b91af;">PartComponentDefinition</span> partDef = </p>
<p style="margin: 0px;">(<span style="color: #2b91af;">PartComponentDefinition</span>)partDoc.ComponentDefinition;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create a 2D sketch on the X-Y plane.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">PlanarSketch</span> sketch1 = </p>
<p style="margin: 0px;">                (<span style="color: #2b91af;">PlanarSketch</span>)partDef.Sketches.Add</p>
<p style="margin: 0px;">                             (partDef.WorkPlanes[3]);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: #2b91af;">TransientGeometry</span> tg = </p>
<p style="margin: 0px;">(<span style="color: #2b91af;">TransientGeometry</span>)ThisApplication.TransientGeometry;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create a spline based on control points.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">ObjectCollection</span> pnts = </p>
<p style="margin: 0px;">    (<span style="color: #2b91af;">ObjectCollection</span>)ThisApplication.</p>
<p style="margin: 0px;">        TransientObjects.CreateObjectCollection();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint2d(2, 0));</p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint2d(4, 1));</p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint2d(4, 2));</p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint2d(6, 3));</p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint2d(8, 1));</p>
<p style="margin: 0px;">    <span style="color: #2b91af;">SketchControlPointSpline</span> controlPointSpline = </p>
<p style="margin: 0px;">                 (<span style="color: #2b91af;">SketchControlPointSpline</span>)sketch1.</p>
<p style="margin: 0px;">               SketchControlPointSplines.Add(pnts);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create a 2D sketch on the Y-Z plane.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">PlanarSketch</span> sketch2 = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">PlanarSketch</span>)partDef.Sketches.Add</p>
<p style="margin: 0px;">                         (partDef.WorkPlanes[1]);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create a spline based on an equation.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">SketchEquationCurve</span> equationCurve = </p>
<p style="margin: 0px;">(<span style="color: #2b91af;">SketchEquationCurve</span>)sketch2.SketchEquationCurves.</p>
<p style="margin: 0px;">            Add(<span style="color: #2b91af;">CurveEquationTypeEnum</span>.kParametric, </p>
<p style="margin: 0px;">              <span style="color: #2b91af;">CoordinateSystemTypeEnum</span>.kCartesian, </p>
<p style="margin: 0px;">             <span style="color: #a31515;">".001*t * cos(t)"</span>, <span style="color: #a31515;">".001*t * sin(t)"</span>,</p>
<p style="margin: 0px;">                                     0.1, 360 * 3);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create a 3D sketch.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">Sketch3D</span> sketch3 = </p>
<p style="margin: 0px;">            (<span style="color: #2b91af;">Sketch3D</span>)partDef.Sketches3D.Add();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create a 3D spline based on control points.</span></p>
<p style="margin: 0px;">    pnts = ThisApplication.TransientObjects.</p>
<p style="margin: 0px;">                         CreateObjectCollection();</p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint(10, 0, 0));</p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint(12, 1, 3));</p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint(12, 2, -5));</p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint(14, 3, 2));</p>
<p style="margin: 0px;">    pnts.Add(tg.CreatePoint(16, 1, -3));</p>
<p style="margin: 0px;"> <span style="color: #2b91af;">SketchControlPointSpline3D</span> controlPointSpline2 = </p>
<p style="margin: 0px;">             (<span style="color: #2b91af;">SketchControlPointSpline3D</span>)sketch3.</p>
<p style="margin: 0px;">           SketchControlPointSplines3D.Add(pnts);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create a 3D spline based on an equation.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">SketchEquationCurve3D</span> equationCurve2 = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">SketchEquationCurve3D</span>)sketch3.</p>
<p style="margin: 0px;">           SketchEquationCurves3D.Add</p>
<p style="margin: 0px;">           (<span style="color: #2b91af;">CoordinateSystemTypeEnum</span>.kCartesian,</p>
<p style="margin: 0px;">       <span style="color: #a31515;">".001*t * cos(t) + 8"</span>, <span style="color: #a31515;">".001*t * sin(t)"</span>, </p>
<p style="margin: 0px;">                         <span style="color: #a31515;">"0.002*t"</span>, 0, 360 * 3);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    ThisApplication.ActiveView.Fit();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Extrude the 2d curves.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">Profile</span> prof = <span style="color: blue;">default</span>(<span style="color: #2b91af;">Profile</span>);</p>
<p style="margin: 0px;">    prof = sketch1.Profiles.AddForSurface</p>
<p style="margin: 0px;">                        (controlPointSpline);</p>
<p style="margin: 0px;">    <span style="color: #2b91af;">ExtrudeDefinition</span> extrudeDef = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">ExtrudeDefinition</span>)partDef.Features.</p>
<p style="margin: 0px;">        ExtrudeFeatures.CreateExtrudeDefinition</p>
<p style="margin: 0px;">(prof, <span style="color: #2b91af;">PartFeatureOperationEnum</span>.kSurfaceOperation);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    extrudeDef.SetDistanceExtent(6, </p>
<p style="margin: 0px;">                  <span style="color: #2b91af;">PartFeatureExtentDirectionEnum</span>.</p>
<p style="margin: 0px;">                        kSymmetricExtentDirection);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: #2b91af;">ExtrudeFeature</span> extrude1 = </p>
<p style="margin: 0px;">                     (<span style="color: #2b91af;">ExtrudeFeature</span>)partDef.</p>
<p style="margin: 0px;">          Features.ExtrudeFeatures.Add(extrudeDef);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Change the work surface to </span></p>
<p style="margin: 0px;">    <span style="color: green;">// not be transparent.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">WorkSurface</span> surf = <span style="color: blue;">default</span>(<span style="color: #2b91af;">WorkSurface</span>);</p>
<p style="margin: 0px;">    surf = extrude1.SurfaceBodies[1].Parent;</p>
<p style="margin: 0px;">    surf.Translucent = <span style="color: blue;">false</span>;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    prof = sketch2.Profiles.</p>
<p style="margin: 0px;">                   AddForSurface(equationCurve);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    extrudeDef = partDef.Features.ExtrudeFeatures.</p>
<p style="margin: 0px;">        CreateExtrudeDefinition</p>
<p style="margin: 0px;">(prof, <span style="color: #2b91af;">PartFeatureOperationEnum</span>.kSurfaceOperation);</p>
<p style="margin: 0px;">    extrudeDef.SetDistanceExtent(9, </p>
<p style="margin: 0px;">        <span style="color: #2b91af;">PartFeatureExtentDirectionEnum</span>.</p>
<p style="margin: 0px;">                          kPositiveExtentDirection);</p>
<p style="margin: 0px;">    <span style="color: #2b91af;">ExtrudeFeature</span> extrude2 = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">ExtrudeFeature</span>)partDef.Features.</p>
<p style="margin: 0px;">                    ExtrudeFeatures.Add(extrudeDef);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create a new sketch and an </span></p>
<p style="margin: 0px;">    <span style="color: green;">//intersection curve.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">Sketch3D</span> interSketch = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">Sketch3D</span>)partDef.Sketches3D.Add();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    interSketch.IntersectionCurves.Add</p>
<p style="margin: 0px;">              (extrude1.SurfaceBodies[1], </p>
<p style="margin: 0px;">                  extrude2.SurfaceBodies[1]);</p>
<p style="margin: 0px;">}</p>
</div>
<p>-Wayne</p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/05/inventor-2014-new-api-for-sketch-creation.html</feedburner:origLink></entry>
    <entry>
        <title>Inventor 2014 API for the new Joint feature</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/BA3Nm0pF8jc/inventor-2014-api-for-the-new-joint-feature.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/04/inventor-2014-api-for-the-new-joint-feature.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc68834017d42c0bdfe970c</id>
        <published>2013-04-12T18:16:05-07:00</published>
        <updated>2013-04-13T10:47:23-07:00</updated>
        <summary>One focus of the 2014 release is “Ease of use”. An example of this is the new Joint command that will definitely make it easier to make relationships between parts in an assembly. This command is on the Assemble tab...</summary>
        <author>
            <name>Wayne Brill</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Assemblies" />
        <category scheme="http://www.sixapart.com/ns/types#category" term="Wayne" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>One focus of the 2014 release is “Ease of use”. An example of this is the new Joint command that will definitely make it easier to make relationships between parts in an assembly. This command is on the Assemble tab next to Constrain. </p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017eea34f1b6970d-pi"><img alt="image" border="0" height="107" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017eea34f1c7970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="452" /></a></p>
<p>When you run this command new graphic feedback shows you where the joints could be added before you add the joint. </p>
<p><strong>API Support for Joints</strong></p>
<p>The API also supports Joints. Here are several of the new classes, new method and an enum related to Joints.</p>
<p><em>AssemblyJoint, </em><em>AssemblyJointDefinition</em></p>
<p><em>AssemblyComponentDefinition.Joints</em> (collection)</p>
<p><em>AssemblyJointTypeEnum, <em>CreateAssemblyJointDefinition</em></em></p>
<p>You use an <em>AssemblyJointDefinition</em> as input to create a joint. To create this use the <em>CreateAssemblyJointDefinition</em> method of the Joints collection. (Property of the <em>AssemblyComponentDefinition)</em> This method takes a Joint Type and two <em>GeometryIntent</em> objects. If you have used the API to create drawing annotations you will be familiar with<em> GeometryIntent objects.</em> To create the joint use the Add method of the Joints collection. </p>
<p>Below are the functions from this <a href="http://modthemachine.typepad.com/Inventor_2014_Joints_Example.zip" target="_blank">C# example</a> that create a joint. (zip includes the ipt) This example was converted to C# from the VBA example in the help file. After you run the example you will see a new assembly with two components that share a joint. </p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3891a6ca970b-pi"><img alt="image" border="0" height="274" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d42c0bdeb970c-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="414" /></a></p>
<p>I dragged the part (rotated) to show the joint.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017eea34f1e2970d-pi"><img alt="image" border="0" height="271" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017eea34f1ee970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="412" /></a></p>
<p><strong>C# functions:</strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">void</span> AssemblyJoint()</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;">    <span style="color: green;">// Create a new assembly document.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">AssemblyDocument</span> asmDoc =</p>
<p style="margin: 0px;">(<span style="color: #2b91af;">AssemblyDocument</span>)ThisApplication.Documents.Add </p>
<p style="margin: 0px;">      (<span style="color: #2b91af;">DocumentTypeEnum</span>.kAssemblyDocumentObject, </p>
<p style="margin: 0px;">     ThisApplication.FileManager.GetTemplateFile</p>
<p style="margin: 0px;">    (<span style="color: #2b91af;">DocumentTypeEnum</span>.kAssemblyDocumentObject));</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: #2b91af;">AssemblyComponentDefinition</span> asmDef = </p>
<p style="margin: 0px;">                     asmDoc.ComponentDefinition;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: #2b91af;">Matrix</span> trans = </p>
<p style="margin: 0px;">ThisApplication.TransientGeometry.CreateMatrix();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Place an occurrence into the assembly.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">ComponentOccurrence</span> occ1 = </p>
<p style="margin: 0px;">        asmDef.Occurrences.Add</p>
<p style="margin: 0px;">(<span style="color: #a31515;">"C:\\Inventor2014APISamples\\SamplePart.ipt"</span>,</p>
<p style="margin: 0px;">                                         trans);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Place a second occurrence with the matrix </span></p>
<p style="margin: 0px;">    <span style="color: green;">//adjusted so it fits correctly with the </span></p>
<p style="margin: 0px;">    <span style="color: green;">//first occurrence.</span></p>
<p style="margin: 0px;">    trans.Cell[1, 4] = 6 * 2.54;</p>
<p style="margin: 0px;">    <span style="color: #2b91af;">ComponentOccurrence</span> occ2 = </p>
<p style="margin: 0px;">        asmDef.Occurrences.Add</p>
<p style="margin: 0px;">(<span style="color: #a31515;">"C:\\Inventor2014APISamples\\SamplePart.ipt"</span>, </p>
<p style="margin: 0px;">                                         trans);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Get Face 1 from occ1 and </span></p>
<p style="margin: 0px;">    <span style="color: green;">// create a FaceProxy.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">Face</span> face1 = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">Face</span>)GetNamedEntity(occ1, <span style="color: #a31515;">"Face1"</span>);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Get Face 2 from occ2 and </span></p>
<p style="margin: 0px;">    <span style="color: green;">// create a FaceProxy.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">Face</span> face2 = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">Face</span>)GetNamedEntity(occ2, <span style="color: #a31515;">"Face2"</span>);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Get Edge 1 from occ2 and  </span></p>
<p style="margin: 0px;">    <span style="color: green;">// create an EdgeProxy.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">Edge</span> Edge1 = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">Edge</span>)GetNamedEntity(occ2, <span style="color: #a31515;">"Edge1"</span>);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Get Edge 3 from occ1 and </span></p>
<p style="margin: 0px;">    <span style="color: green;">// create an EdgeProxy.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">Edge</span> Edge3 = </p>
<p style="margin: 0px;">        (<span style="color: #2b91af;">Edge</span>)GetNamedEntity(occ1, <span style="color: #a31515;">"Edge3"</span>);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create an intent to the </span></p>
<p style="margin: 0px;">    <span style="color: green;">// center of Edge1.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">GeometryIntent</span> edge1Intent = </p>
<p style="margin: 0px;">        asmDef.CreateGeometryIntent</p>
<p style="margin: 0px;">    (Edge1, <span style="color: #2b91af;">PointIntentEnum</span>.kMidPointIntent);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create an intent to the center of Edge3.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">GeometryIntent</span> edge3Intent = </p>
<p style="margin: 0px;">        asmDef.CreateGeometryIntent</p>
<p style="margin: 0px;">        (Edge3, <span style="color: #2b91af;">PointIntentEnum</span>.kMidPointIntent);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create two intents to define </span></p>
<p style="margin: 0px;">    <span style="color: green;">// the geometry for the joint.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">GeometryIntent</span> intentOne = </p>
<p style="margin: 0px;">        asmDef.CreateGeometryIntent</p>
<p style="margin: 0px;">                        (face2, edge1Intent);</p>
<p style="margin: 0px;">    <span style="color: #2b91af;">GeometryIntent</span> intentTwo = </p>
<p style="margin: 0px;">        asmDef.CreateGeometryIntent</p>
<p style="margin: 0px;">                        (face1, edge3Intent);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Create a rotation joint between the two parts.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">AssemblyJointDefinition</span> jointDef = </p>
<p style="margin: 0px;">       asmDef.Joints.CreateAssemblyJointDefinition</p>
<p style="margin: 0px;">       (<span style="color: #2b91af;">AssemblyJointTypeEnum</span>.kRotationalJointType, </p>
<p style="margin: 0px;">                             intentOne, intentTwo);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    jointDef.FlipAlignmentDirection = <span style="color: blue;">false</span>;</p>
<p style="margin: 0px;">    jointDef.FlipOriginDirection = <span style="color: blue;">true</span>;</p>
<p style="margin: 0px;">    <span style="color: #2b91af;">AssemblyJoint</span> joint = </p>
<p style="margin: 0px;">                   asmDef.Joints.Add(jointDef);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Make the joint visible.</span></p>
<p style="margin: 0px;">    joint.Visible = <span style="color: blue;">true</span>;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">// Drive the joint to animate it.</span></p>
<p style="margin: 0px;">    joint.DriveSettings.StartValue = <span style="color: #a31515;">"0 deg"</span>;</p>
<p style="margin: 0px;">    joint.DriveSettings.EndValue = <span style="color: #a31515;">"180 deg"</span>;</p>
<p style="margin: 0px;">    joint.DriveSettings.GoToStart();</p>
<p style="margin: 0px;">    joint.DriveSettings.PlayForward();</p>
<p style="margin: 0px;">    joint.DriveSettings.PlayReverse();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">}</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: green;">// This finds the entity associated with </span></p>
<p style="margin: 0px;"><span style="color: green;">// an iMate of a specified name.  This</span></p>
<p style="margin: 0px;"><span style="color: green;">// allows iMates to be used as a generic </span></p>
<p style="margin: 0px;"><span style="color: green;">// naming mechansim.</span></p>
<p style="margin: 0px;"><span style="color: blue;">private</span> <span style="color: blue;">object</span> GetNamedEntity</p>
<p style="margin: 0px;">    (<span style="color: #2b91af;">ComponentOccurrence</span> Occurrence, <span style="color: blue;">string</span> Name)</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px;">        <span style="color: green;">// Look for the iMate that has the </span></p>
<p style="margin: 0px;">        <span style="color: green;">// specified name in the referenced file.</span></p>
<p style="margin: 0px;">        <span style="color: #2b91af;">PartComponentDefinition</span> partDef = </p>
<p style="margin: 0px;">   (<span style="color: #2b91af;">PartComponentDefinition</span>)Occurrence.Definition;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">object</span> resultEntity = <span style="color: blue;">null</span>;</p>
<p style="margin: 0px;">        resultEntity = <span style="color: blue;">null</span>;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">foreach</span> (<span style="color: #2b91af;">iMateDefinition</span> iMate </p>
<p style="margin: 0px;">                    <span style="color: blue;">in</span> partDef.iMateDefinitions) </p>
<p style="margin: 0px;">        {</p>
<p style="margin: 0px;">            <span style="color: green;">// Check to see if this iMate has </span></p>
<p style="margin: 0px;">            <span style="color: green;">// the correct name</span></p>
<p style="margin: 0px;">            <span style="color: blue;">if</span> (iMate.Name.ToUpper() == </p>
<p style="margin: 0px;">                                Name.ToUpper()) </p>
<p style="margin: 0px;">            {</p>
<p style="margin: 0px;">             <span style="color: green;">// Get the geometry associated </span></p>
<p style="margin: 0px;">             <span style="color: green;">// with the iMate. Using InvokeMember</span></p>
<p style="margin: 0px;">             <span style="color: green;">// because the iMateDefinition is the</span></p>
<p style="margin: 0px;">             <span style="color: green;">// base class and does not have an </span></p>
<p style="margin: 0px;">             <span style="color: green;">// Entity property</span></p>
<p style="margin: 0px;">              <span style="color: blue;">object</span> entity = <span style="color: blue;">null</span>;</p>
<p style="margin: 0px;">              entity = iMate.GetType().InvokeMember</p>
<p style="margin: 0px;">                           (<span style="color: #a31515;">"Entity"</span>,</p>
<p style="margin: 0px;">                            <span style="color: #2b91af;">BindingFlags</span>.GetProperty,</p>
<p style="margin: 0px;">                            <span style="color: blue;">null</span>, iMate, <span style="color: blue;">null</span>);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">                <span style="color: green;">// Create a proxy.</span></p>
<p style="margin: 0px;">                Occurrence.CreateGeometryProxy</p>
<p style="margin: 0px;">                    (entity, <span style="color: blue;">out</span> resultEntity);</p>
<p style="margin: 0px;">                <span style="color: blue;">break</span>; </p>
<p style="margin: 0px;">            }</p>
<p style="margin: 0px;">        }</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: green;">// Return the found entity, or Nothing  </span></p>
<p style="margin: 0px;">        <span style="color: green;">// if a match wasn't found.</span></p>
<p style="margin: 0px;">        <span style="color: blue;">return</span> resultEntity;</p>
<p style="margin: 0px;">}</p>
</div>
<p>-Wayne</p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/04/inventor-2014-api-for-the-new-joint-feature.html</feedburner:origLink></entry>
    <entry>
        <title>Control feature creation based on user defined boundary</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/tB-PiT3fvqE/control-feature-creation-based-on-user-defined-boundary.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/03/control-feature-creation-based-on-user-defined-boundary.html" thr:count="1" thr:updated="2013-03-31T02:20:11-07:00" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc68834017ee9d6d038970d</id>
        <published>2013-03-29T15:25:59-07:00</published>
        <updated>2013-03-29T15:25:59-07:00</updated>
        <summary>Thanks to DevTech engineer Vladimir Ananyev for providing this post and great example. Recently we were asked if the Inventor API could help by suppressing elements of holes in a rectangular pattern which are not completely inside a user-defined boundary....</summary>
        <author>
            <name>Wayne Brill</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="iLogic" />
        <category scheme="http://www.sixapart.com/ns/types#category" term="Parts" />
        <category scheme="http://www.sixapart.com/ns/types#category" term="Wayne" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p><em>Thanks to DevTech engineer Vladimir Ananyev for providing this post and great example.</em> </p>  <p>Recently we were asked if the Inventor API could help by suppressing elements of holes in a rectangular pattern which are not completely inside a user-defined boundary.</p>  <p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9d6d017970d-pi"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d4262bede970c-pi" width="488" height="145" /></a>     <br /></p>  <p>The algorithm needs to suppress holes that have centers located outside the boundary at a distance greater than the hole radius from the boundary. The boundary could be complex geometry and the most difficult problem was to determine if the hole was completely inside or outside the boundary. This problem was solved by using Inventor API objects involved in the creation of profiles for solid geometry.</p>  <p>In the screenshots below you see a sketch and the extrusion that is created using the profile created with the AddForSolid() method.</p>  <div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt">   <p style="margin: 0px"> <span style="color: blue">Dim</span> oProfile <span style="color: blue">As</span> <span style="color: #2b91af">Profile</span> _</p>    <p style="margin: 0px">    = oSketch.Profiles.AddForSolid(<span style="color: blue">True</span>)</p> </div>  <p>The result is shown in Fig. 2.</p>  <p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3833a603970b-pi"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d4262bee8970c-pi" width="474" height="172" /></a></p>  <p>If a circular profile path crosses the ellipse (boundary) or is located completely outside then it adds material to the solid body. Otherwise it subtracts material.</p>  <p>Figures 3 and 4 show that this rule works for profile paths of any other geometry as well.</p>  <p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3833a616970b-pi"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d4262bef0970c-pi" width="488" height="169" /></a></p>  <p>   <br />This powerful built-in topology analyzer of the AddForSolid method you can be used to easily identify pattern elements that are completely inside the specified boundary. (Fortunately there are not any restrictions on the geometry of the profile paths). </p>  <p>To demonstrate this approach I used an iLogic rule. (Any language that can access the Inventor API could have been used too). In figure 5 you see the full rectangular pattern. After the rule is run, the holes outside of the boundary are suppressed. (figure 6) </p>  <p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3833a62c970b-pi"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d4262bf00970c-pi" width="475" height="226" /></a></p>  <p><strong>The steps are as follows. </strong><strong>     <br /></strong>1. The Main function projects the boundary geometry from the planar sketch “Boundary” and all the elements of the holes pattern into the created on-the-fly transient planar sketch. (For simplicity the rule works with the first rectangular pattern in its parent part document).  <br /></p>  <p>2. It then calls the <em>AddForSolid</em> method to create a profile object based on the combined projected geometry in the transient sketch.  <br /></p>  <p>3.  The rule analyses every profile path in the profile object. If the path represents a projected hole’s pattern element and its property <em>AddsMaterial</em> returns True, then the corresponding pattern element is suppressed. The search for <em>FeaturePatternElem</em>ent is based on the reference to the projected sketch circle is performed by the function <em>GetEltByGreenCircle</em>.</p>  <p><strong>Note</strong>:  The parent hole feature cannot be suppressed otherwise all the pattern will be suppressed as well, that is why our code ignores the parent feature.</p>  <p>An Inventor part file with the iLogic rule can be downloaded <a href="http://modthemachine.typepad.com/Pattern.ipt" target="_blank">here</a>. </p>  <p><strong>Here are the two iLogic rules</strong>: </p>  <div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt">   <p style="margin: 0px"><span style="color: blue">Sub</span> Main()</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oDoc <span style="color: blue">As</span> <span style="color: #2b91af">PartDocument</span> =</p>    <p style="margin: 0px">      <span style="color: blue">TryCast</span>(ThisDoc.Document, <span style="color: #2b91af">PartDocument</span>)</p>    <p style="margin: 0px">    <span style="color: blue">If</span> oDoc <span style="color: blue">Is</span> <span style="color: blue">Nothing</span> <span style="color: blue">Then</span></p>    <p style="margin: 0px">        <span style="color: #2b91af">MessageBox</span>.Show _</p>    <p style="margin: 0px">     (<span style="color: #a31515">"This rule works with part documents only."</span>,</p>    <p style="margin: 0px">         <span style="color: #a31515">"iLogic Rule"</span>, _</p>    <p style="margin: 0px">          <span style="color: #2b91af">MessageBoxButtons</span>.OK,</p>    <p style="margin: 0px">       <span style="color: #2b91af">MessageBoxIcon</span>.Warning)</p>    <p style="margin: 0px">        <span style="color: blue">Exit Sub</span></p>    <p style="margin: 0px">    <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oDef <span style="color: blue">As</span> <span style="color: #2b91af">PartComponentDefinition</span> =</p>    <p style="margin: 0px">                             oDoc.ComponentDefinition</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: green">'this rule works with only one rect. pattern only</span></p>    <p style="margin: 0px">    <span style="color: green">'provided directly by item number</span></p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oPattern <span style="color: blue">As</span> <span style="color: #2b91af">RectangularPatternFeature</span> =</p>    <p style="margin: 0px">     oDef.Features.RectangularPatternFeatures.Item(1)</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: green">'restore all pattern elements in order to </span></p>    <p style="margin: 0px">    <span style="color: green">'get access to their faces</span></p>    <p style="margin: 0px">    <span style="color: blue">For</span> <span style="color: blue">Each</span> oElt <span style="color: blue">As</span> <span style="color: #2b91af">FeaturePatternElement</span> _</p>    <p style="margin: 0px">                         <span style="color: blue">In</span> oPattern.PatternElements</p>    <p style="margin: 0px">        <span style="color: blue">If</span> oElt.Suppressed <span style="color: blue">Then</span></p>    <p style="margin: 0px">            oElt.Suppressed = <span style="color: blue">False</span></p>    <p style="margin: 0px">        <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">    <span style="color: blue">Next</span></p>    <p style="margin: 0px">    oDoc.Update()</p>    <p style="margin: 0px">    ThisApplication.ActiveView.Update()</p>    <p style="margin: 0px">    Beep()</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oBoundarySketch <span style="color: blue">As</span> <span style="color: #2b91af">PlanarSketch</span> =</p>    <p style="margin: 0px">                    oDef.Sketches.Item(<span style="color: #a31515">"Boundary"</span>)</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: green">'temporary sketch for profile</span></p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oSketch <span style="color: blue">As</span> <span style="color: #2b91af">PlanarSketch</span> =</p>    <p style="margin: 0px">     oDef.Sketches.Add _</p>    <p style="margin: 0px">               (oBoundarySketch.PlanarEntity, <span style="color: blue">False</span>)</p>    <p style="margin: 0px">    oSketch.Visible = <span style="color: blue">False</span></p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: green">'project boundary</span></p>    <p style="margin: 0px">    <span style="color: blue">For</span> <span style="color: blue">Each</span> oE <span style="color: blue">As</span> <span style="color: #2b91af">SketchEntity</span> _</p>    <p style="margin: 0px">                  <span style="color: blue">In</span> oBoundarySketch.SketchEntities</p>    <p style="margin: 0px">        <span style="color: blue">Call</span> oSketch.AddByProjectingEntity(oE)</p>    <p style="margin: 0px">    <span style="color: blue">Next</span></p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: green">'project parent hole</span></p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oHole <span style="color: blue">As</span> <span style="color: #2b91af">HoleFeature</span> =</p>    <p style="margin: 0px">         <span style="color: blue">TryCast</span>(oPattern.ParentFeatures.Item(1), </p>    <p style="margin: 0px">                                     <span style="color: #2b91af">HoleFeature</span>)</p>    <p style="margin: 0px">    <span style="color: blue">If</span> oHole <span style="color: blue">Is</span> <span style="color: blue">Nothing</span> <span style="color: blue">Then</span></p>    <p style="margin: 0px">        <span style="color: #2b91af">MessageBox</span>.Show _</p>    <p style="margin: 0px">(<span style="color: #a31515">"This rule works with hole feature pattern only."</span>,</p>    <p style="margin: 0px">          <span style="color: #a31515">"iLogic Rule"</span>, _</p>    <p style="margin: 0px">       <span style="color: #2b91af">MessageBoxButtons</span>.OK, <span style="color: #2b91af">MessageBoxIcon</span>.Warning)</p>    <p style="margin: 0px">        <span style="color: blue">Exit Sub</span></p>    <p style="margin: 0px">    <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oEdge <span style="color: blue">As</span> <span style="color: #2b91af">Edge</span> =</p>    <p style="margin: 0px">             oHole.SideFaces.Item(1).Edges.Item(1)</p>    <p style="margin: 0px">    <span style="color: blue">Call</span> oSketch.AddByProjectingEntity(oEdge)</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: green">'project holes pattern</span></p>    <p style="margin: 0px">    <span style="color: blue">For</span> <span style="color: blue">Each</span> oElt <span style="color: blue">As</span> <span style="color: #2b91af">FeaturePatternElement</span> _</p>    <p style="margin: 0px">                        <span style="color: blue">In</span> oPattern.PatternElements</p>    <p style="margin: 0px">        <span style="color: blue">If</span> oElt.Faces.Count &gt; 0 <span style="color: blue">Then</span></p>    <p style="margin: 0px">            oEdge = oElt.Faces.Item(1).Edges.Item(1)</p>    <p style="margin: 0px">            <span style="color: blue">Call</span> oSketch.AddByProjectingEntity(oEdge)</p>    <p style="margin: 0px">        <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">    <span style="color: blue">Next</span></p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: green">' Create a profile.</span></p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oProfile <span style="color: blue">As</span> <span style="color: #2b91af">Profile</span> =</p>    <p style="margin: 0px">                oSketch.Profiles.AddForSolid(<span style="color: blue">True</span>)</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: blue">For</span> <span style="color: blue">Each</span> oPath <span style="color: blue">As</span> <span style="color: #2b91af">ProfilePath</span> <span style="color: blue">In</span> oProfile</p>    <p style="margin: 0px">        <span style="color: blue">If</span> oPath.Count = 1 <span style="color: blue">Then</span></p>    <p style="margin: 0px">            <span style="color: blue">Dim</span> oPE <span style="color: blue">As</span> <span style="color: #2b91af">ProfileEntity</span> = oPath.Item(1)</p>    <p style="margin: 0px">            <span style="color: blue">If</span> oPE.CurveType =</p>    <p style="margin: 0px">                <span style="color: #2b91af">Curve2dTypeEnum</span>.kCircleCurve2d <span style="color: blue">Then</span></p>    <p style="margin: 0px">                <span style="color: blue">Dim</span> oSkE <span style="color: blue">As</span> <span style="color: #2b91af">SketchEntity</span> =</p>    <p style="margin: 0px">                                   oPE.SketchEntity</p>    <p style="margin: 0px">                <span style="color: blue">Dim</span> oGreenCircle <span style="color: blue">As</span> <span style="color: #2b91af">SketchCircle</span> =</p>    <p style="margin: 0px">                         <span style="color: blue">CType</span>(oSkE, <span style="color: #2b91af">SketchCircle</span>)</p>    <p style="margin: 0px">                <span style="color: blue">Dim</span> oFPE <span style="color: blue">As</span> <span style="color: #2b91af">FeaturePatternElement</span> =</p>    <p style="margin: 0px">                   GetEltByGreenCircle(oGreenCircle)</p>    <p style="margin: 0px">                <span style="color: blue">If</span> oFPE <span style="color: blue">IsNot</span> <span style="color: blue">Nothing</span> <span style="color: blue">Then</span></p>    <p style="margin: 0px">                    <span style="color: blue">If</span> oPath.AddsMaterial = <span style="color: blue">True</span> <span style="color: blue">Then</span></p>    <p style="margin: 0px">                        <span style="color: green">'should be suppressed</span></p>    <p style="margin: 0px">                        oFPE.Suppressed = <span style="color: blue">True</span></p>    <p style="margin: 0px">                    <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">                <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">            <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">        <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">    <span style="color: blue">Next</span></p>    <p style="margin: 0px">    <span style="color: green">'delete temporary sketch</span></p>    <p style="margin: 0px">    oSketch.Delete()</p>    <p style="margin: 0px">    oDoc.Update()</p>    <p style="margin: 0px">    Beep()</p>    <p style="margin: 0px"><span style="color: blue">End</span> <span style="color: blue">Sub</span></p>    <p style="margin: 0px"> </p>    <p style="margin: 0px"> </p>    <p style="margin: 0px"><span style="color: blue">Function</span> GetEltByGreenCircle( _</p>    <p style="margin: 0px">  <span style="color: blue">ByRef</span> oGreenCircle <span style="color: blue">As</span> <span style="color: #2b91af">SketchCircle</span>) _</p>    <p style="margin: 0px">                      <span style="color: blue">As</span> <span style="color: #2b91af">FeaturePatternElement</span></p>    <p style="margin: 0px">    <span style="color: green">'returns FPE corresponding to the </span></p>    <p style="margin: 0px">    <span style="color: green">'given SketchCircle object</span></p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: blue">If</span> oGreenCircle <span style="color: blue">Is</span> <span style="color: blue">Nothing</span> <span style="color: blue">Then</span> <span style="color: blue">Return</span> <span style="color: blue">Nothing</span></p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oEdge <span style="color: blue">As</span> <span style="color: #2b91af">Edge</span></p>    <p style="margin: 0px">    <span style="color: blue">Try</span></p>    <p style="margin: 0px">        oEdge = <span style="color: blue">CType</span>(oGreenCircle. _</p>    <p style="margin: 0px">         ReferencedEntity, <span style="color: #2b91af">Edges</span>).Item(1)</p>    <p style="margin: 0px">    <span style="color: blue">Catch</span> ex <span style="color: blue">As</span> <span style="color: #2b91af">Exception</span></p>    <p style="margin: 0px">        <span style="color: blue">Return</span> <span style="color: blue">Nothing</span></p>    <p style="margin: 0px">    <span style="color: blue">End</span> <span style="color: blue">Try</span></p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oFace <span style="color: blue">As</span> <span style="color: #2b91af">Face</span></p>    <p style="margin: 0px">    <span style="color: blue">If</span> oEdge.Faces.Item(1).SurfaceType =</p>    <p style="margin: 0px">             <span style="color: #2b91af">SurfaceTypeEnum</span>.kCylinderSurface <span style="color: blue">Then</span></p>    <p style="margin: 0px">        oFace = oEdge.Faces.Item(1)</p>    <p style="margin: 0px">    <span style="color: blue">Else</span></p>    <p style="margin: 0px">        oFace = oEdge.Faces.Item(2)</p>    <p style="margin: 0px">    <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: blue">If</span> oFace.CreatedByFeature.Type =</p>    <p style="margin: 0px">              <span style="color: #2b91af">ObjectTypeEnum</span>.kHoleFeatureObject <span style="color: blue">Then</span></p>    <p style="margin: 0px">        <span style="color: blue">Return</span> <span style="color: blue">Nothing</span></p>    <p style="margin: 0px">    <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> lKey <span style="color: blue">As</span> <span style="color: blue">Long</span> = oFace.TransientKey</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: blue">Dim</span> oPattern <span style="color: blue">As</span> <span style="color: #2b91af">RectangularPatternFeature</span> _</p>    <p style="margin: 0px">            = <span style="color: blue">CType</span>(oFace.CreatedByFeature,  _</p>    <p style="margin: 0px">                <span style="color: #2b91af">RectangularPatternFeature</span>)</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: blue">For</span> <span style="color: blue">Each</span> oElt <span style="color: blue">As</span> <span style="color: #2b91af">FeaturePatternElement</span></p>    <p style="margin: 0px">                        <span style="color: blue">In</span> oPattern.PatternElements</p>    <p style="margin: 0px">        <span style="color: blue">If</span> oElt.Faces.Count &gt; 0 <span style="color: blue">Then</span></p>    <p style="margin: 0px">            <span style="color: blue">If</span> lKey = oElt.Faces.Item(1). _</p>    <p style="margin: 0px">                                  TransientKey <span style="color: blue">Then</span></p>    <p style="margin: 0px">                <span style="color: blue">Return</span> oElt</p>    <p style="margin: 0px">            <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">        <span style="color: blue">End</span> <span style="color: blue">If</span></p>    <p style="margin: 0px">    <span style="color: blue">Next</span></p>    <p style="margin: 0px">    <span style="color: blue">Return</span> <span style="color: blue">Nothing</span></p>    <p style="margin: 0px"><span style="color: blue">End</span> <span style="color: blue">Function</span> <span style="color: green">'GetEltByGreenCircle</span></p>    <p style="margin: 0px"> </p> </div>  <p>(Thanks! to Vladimir)</p>  <p>-Wayne</p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/03/control-feature-creation-based-on-user-defined-boundary.html</feedburner:origLink></entry>
    <entry>
        <title>Inventor 2014 API Enhancements</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/2pf1mKCdE5g/inventor-2014-api-enhancements.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/03/inventor-2014-api-enhancements.html" thr:count="2" thr:updated="2013-04-08T11:14:40-07:00" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc68834017ee9c9d233970d</id>
        <published>2013-03-27T13:55:04-07:00</published>
        <updated>2013-03-27T13:56:29-07:00</updated>
        <summary>Inventor 2014 was officially released yesterday. Here’s a quick overview of the API enhancements for this release. I’ll go into more detail of some of them in later posts. Support for dimension styles. The API previously had minimal support for...</summary>
        <author>
            <name>Brian Ekins</name>
        </author>
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>Inventor 2014 was officially released yesterday.  Here’s a quick overview of the API enhancements for this release.  I’ll go into more detail of some of them in later posts.</p>  <ul>   <li>Support for dimension styles.  The API previously had minimal support for all of the settings associated with a dimension style.  This was also one of the highest requested enhancements from the yearly API survey.  With Inventor 2014 all of the settings are now available from the API, with the exception of those on the “Notes and Leaders” tab. The notes and leaders settings are quite a bit more complicated and will need to wait until later.     <br />      <br /><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3826a690970b-pi"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Inventor2014DimStyles" border="0" alt="Inventor2014DimStyles" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3826a69a970b-pi" width="400" height="212" /></a>      <br /></li>    <li>API support for the new types of sketch curves.  Inventor 2013 introduced two new curve types; control point and equation curves in both 2D and 3D sketches.  There is now full API support for both types in both 2D and 3D sketches.     <br />      <br /><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9c9d1dd970d-pi"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Inventor2014Curves" border="0" alt="Inventor2014Curves" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9c9d1e2970d-pi" width="400" height="370" /></a>      <br /></li>    <li>API support for 3D intersection curves.  Inventor has supported the ability to create an intersection curve between two surfaces for a long time.  This capability is now also supported through the API.     <br />      <br /><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3826a4e2970b-pi"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Inventor2014IntersectionCurve" border="0" alt="Inventor2014IntersectionCurve" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3826a4ea970b-pi" width="400" height="382" /></a>      <br /></li>    <li>Inventor 2014 introduces some new sketch command for drawing slots.  There are also API methods that provide the equivalent capability to the commands.     <br /><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9c9d1f7970d-pi"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Inventor2014Slots" border="0" alt="Inventor2014Slots" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3826a4fa970b-pi" width="400" height="212" /></a>      <br /></li>    <li>Inventor 2014 introduces a new feature that can significantly improve performance for very large assemblies called assembly <em>Express Mode.</em> There is full API support for this.      <br /></li>    <li>Another new feature in Inventor 2014 is assembly joints. Joints are a more user-friendly type of constraint. An assembly can use both the traditional constraints and joints to define the relationships between parts.  There is full API support for joints.     <br />      <br /><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3826a504970b-pi"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Inventor2014Joints" border="0" alt="Inventor2014Joints" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9c9d20a970d-pi" width="400" height="328" /></a>      <br /></li>    <li>Inventor and the API now support creating work points at the centers of spheres.     <br /></li>    <li>The API supports a new enhancement to the boundary patch feature where the weight, or smoothness, can be controlled for each selected edge.     <br />      <br /><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d4255c67f970c-pi"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Inventor2014BoundaryPatch" border="0" alt="Inventor2014BoundaryPatch" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9c9d215970d-pi" width="400" height="228" /></a>      <br /></li>    <li>The API now supports the ability to <em>imprint</em> solids. This takes two bodies as input and creates two new bodies where the faces on the new bodies have been split where any of the faces were overlapping between the bodies.  This is important for analysis applications to control where nodes on their mesh are created.      <br /></li>    <li>The API now fully supports consistent materials.  Consistent materials was introduced with Inventor 2013.  There wasn’t time to do the equivalent API work at the time but there was some work done so the Material and RenderStyle objects would work with consistent materials.  This works ok but has some issues because the old Material and RenderStyle objects are not a one-for-one match to the new consistent material functionality.  With Inventor 2014 new API functionality has been introduced that fully supports consistent materials.     <br />      <br /><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9c9d221970d-pi"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Inventor2014CM" border="0" alt="Inventor2014CM" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9c9d22d970d-pi" width="400" height="377" /></a>      <br /></li>    <li> There is now API support for Pack &amp; Go.     <br /></li>    <li>A few updates were made to the BIM exchange API in reaction to some enhancements made in the product.     <br /></li>    <li>Inventor now supports VBA 7.  VBA 7 is able to run natively on both 32 and 64-bit Windows.  The previous VBA only supported 32-bit Windows, so this is great news for those running 64-bit Windows.  With earlier version of Inventor on a 64-bit system, in order to support VBA at all, Inventor would spawn a separate 32-bit process that would host VBA. This is no longer required and as a result there is no longer any delay when accessing VBA and your macros will also run much faster.  As a side benefit, the scroll button now scrolls the code window.</li> </ul>  <p>-Brian</p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/03/inventor-2014-api-enhancements.html</feedburner:origLink></entry>
    <entry>
        <title>DevTech Team Meeting in San Rafael CA</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/H0hEN_PShvc/devtech-team-meeting-in-san-rafael-ca.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/03/devtech-team-meeting-in-san-rafael-ca.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc68834017ee9818f1e970d</id>
        <published>2013-03-18T13:52:42-07:00</published>
        <updated>2013-03-18T13:52:42-07:00</updated>
        <summary>I work for an organization at Autodesk named Developer Technical services. (We support the Autodesk Developer Network). This last week the DevTech Americas team had a meeting at one of the Autodesk offices in San Rafael California. (Colleagues from Europe...</summary>
        <author>
            <name>Wayne Brill</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Wayne" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>I work for an organization at Autodesk named Developer Technical services. (We support the Autodesk Developer Network). This last week the DevTech Americas team had a meeting at one of the Autodesk offices in San Rafael California. (Colleagues from Europe and the Media and Entertainment team where there too.) We had one and a half days of presentations. Some of the presentations centered around what we have been doing lately to learn cloud and mobile. My favorite presentation was by Philippe Leefsma on HTML 5. Philippe had many examples of what you can do using this technology. (I really liked the one on voice recognition) He has made several posts recently on the Cloud &amp; Mobile DevBlog such as this one: </p>  <p><a href="http://adndevblog.typepad.com/cloud_and_mobile/2013/01/first-try-at-windows-8-programming-with-javascript-html5.html" target="_blank">First try at Windows 8 programming with JavaScript &amp; HTML5</a></p>  <p>I thought the presentation by Gopinath Taget on what he has been doing to learn cloud security was also very interesting. He talks about this on the Cloud &amp; Mobile DevBlog as well:</p>  <p><a href="http://adndevblog.typepad.com/cloud_and_mobile/2013/03/cloud-security-securing-with-ssl-using-fiddler.html" target="_blank">Cloud Security: Securing with SSL – Using Fiddler</a></p>  <p>The other presentations were great too. My short presentation was on my experiences getting up to speed on Python. </p>  <p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c37de82c8970b-pi"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c37de8321970b-pi" width="465" height="302" /></a></p>  <blockquote>   <p>     Jim Quanci leading one of the presentations</p> </blockquote>  <p><strong>Fun and Interesting</strong></p>  <p>Monday night we had a DevTech grand prix. (electric Go-Carts) We all tried our best to get to the winners circle but in the end Fenton Webb’s experience with high speed maneuvers allowed him to take the top prize.</p>  <p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d420db287970c-pi"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9818e50970d-pi" width="441" height="337" /></a> </p>  <blockquote>   <p>                      The race is on</p> </blockquote>  <p>Tuesday afternoon we were fortunate to get a tour of the <a href="http://www.calacademy.org/academy/building/sustainable_design/" target="_blank">California Academy of Sciences</a> building in San Francisco. The building is a great example of how the design of the building effects energy usage. </p>  <p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c37de846a970b-pi"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee9818f0f970d-pi" width="448" height="337" /></a></p>  <p>This is the roof of the museum. The top is six inches of dirt and all of the plants are native to California. The windows open depending on the heat inside. </p>  <p> </p>  <p>Team meetings like this are one reason I appreciate working for Autodesk. </p>  <p>-Wayne  </p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/03/devtech-team-meeting-in-san-rafael-ca.html</feedburner:origLink></entry>
    <entry>
        <title>Inventor API Training  Lesson 12</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/n0IrntnooUc/inventor-api-training-lesson-12.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/03/inventor-api-training-lesson-12.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc68834017d418db117970c</id>
        <published>2013-03-06T17:51:49-08:00</published>
        <updated>2013-03-06T17:56:40-08:00</updated>
        <summary>Here is section twelve of the Inventor API training where you see how Apprentice is used to access Inventor Data without having to use Inventor. You also learn about the Inventor viewer control. This is the fourth post with the...</summary>
        <author>
            <name>Wayne Brill</name>
        </author>
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>Here is section twelve of the Inventor API training where you see how Apprentice is used to access Inventor Data without having to use Inventor. You also learn about the Inventor viewer control. This is the fourth post with the Inventor API training material. (<a href="http://modthemachine.typepad.com/my_weblog/2013/02/inventor-api-training-lesson-1.html">Section one is here</a>). </p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c375e7135970b-pi"><img alt="image" border="0" height="292" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c375e715a970b-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="391" /></a></p>
<p>Here is the agenda for this section. Be sure to see the Lab instructions at the end of this section. (completed samples in VB.NET and C# are available)</p>
<p><em>Apprentice Definition      <br />Apprentice Functionalities       <br />Apprentice Guidelines       <br />Apprentice vs. Inventor: Differences       <br />Saving Files with Apprentice</em></p>
<p><em>Inventor View Control</em></p>
<p><strong>Apprentice Definition</strong></p>
<p>This diagram shows where the API for Apprentice fits in . You use a stand alone client application, reference the Inventor API and use the apprentice classes to access Inventor data.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee90187c2970d-pi"><img alt="image" border="0" height="297" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c375e717b970b-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="392" /></a></p>
<p>Apprentice provides a subset of the Inventor API and is  <br />free as it is installed as part of <a href="http://usa.autodesk.com/adsk/servlet/pc/item?siteID=123112&amp;id=18585712" target="_blank">Inventor View</a>. A simple way to think of Apprentice is that it's a smaller version of Autodesk Inventor that does not have a user interface. Because there is not a user interface the only way to access its functionality is by using its API. Apprentice can be very efficient for certain applications because it's smaller than the complete Autodesk Inventor application and because it runs in the same process as your application.     <br /><strong /></p>
<p><strong>Apprentice Functionalities</strong></p>
<p>Apprentice provides <em>read-only</em> access to the following:</p>
<blockquote>
<p>Assembly structure      <br />B-Rep       <br />Drawing sheets and views (limited access)       <br />iParts       <br />iAssemblies       <br />BOM</p>
</blockquote>
<p>Apprentice provides <em>read / write</em> access to the following:</p>
<blockquote>
<p>iProperties      <br />attributes       <br />file references</p>
<p> </p>
</blockquote>
<p><strong>Apprentice – Guidelines</strong></p>
<p>Apprentice should NOT be used in-process with Inventor such as in an Add-In or through Inventor’s VBA. (If the Add-In is an exe type then it is ok).</p>
<p>In past releases a type library specifically for Apprentice was delivered with both Autodesk Inventor and Apprentice. This type library contained the limited set of objects supported only by Apprentice. Now the Autodesk Inventor type library contains all of the Apprentice functionality and is used to access Apprentice. (You add a reference to Inventor.Interop for an Apprentice project). A version of the old Apprentice type library is still supplied for legacy reasons, but this will likely be discontinued in future releases. </p>
<p><strong>Apprentice vs. Inventor: differences</strong></p>
<p>Apprentice is instantiated using a “new ApprenticeServerComponent”. (Instantiating Inventor would be done using something like CreateObject)  </p>
<p>The ApprenticeServerComponent supports a few methods and properties that are unique to Apprentice. </p>
<blockquote>
<p>Open and Close methods, which are used to open and close documents within Apprentice</p>
</blockquote>
<blockquote>
<p>DisplayAffinity, which is used to optimize the behavior of Apprentice for viewer applications </p>
<p>MinimizeFileSize, which compresses files by removing versions</p>
<p>FileSaveAs, used to save files</p>
</blockquote>
<p>The document objects used within Apprentice are different from the document objects used in Autodesk Inventor. (Apprentice does not have a Documents collection) In Inventor there are the PartDocument, AssemblyDocument, DrawingDocument, and PresentationDocument objects. In Apprentice, the <em>ApprenticeServerDocument</em> object represents the part, assembly, and presentation documents and the <em>ApprenticeServerDrawingDocument </em>represents the drawing document.</p>
<p>Note: Apprentice cannot save a file from a previous version. You would need to migrate the file prior to saving it with Apprentice. (To migrate a file, open it with Inventor, save it and close it).</p>
<p><strong><em>VB.NET Example that uses Apprentice to open an ipt file</em></strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Private</span> <span style="color: blue;">Sub</span> ApprenticeSample()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Create Apprentice.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oApprentice <span style="color: blue;">As</span> <span style="color: #2b91af;">ApprenticeServerComponent</span></p>
<p style="margin: 0px;">    oApprentice = <span style="color: blue;">New</span> <span style="color: #2b91af;">ApprenticeServerComponent</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Open a document.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oDoc <span style="color: blue;">As</span> <span style="color: #2b91af;">ApprenticeServerDocument</span></p>
<p style="margin: 0px;">    oDoc = oApprentice.Open(<span style="color: #a31515;">"C:\Temp\Part1.ipt"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    MsgBox(<span style="color: #a31515;">"Opened: "</span> &amp; oDoc.DisplayName)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong>Saving Files with Apprentice</strong></p>
<p>Use <em>FlushToFile</em> if the code is only modifying iProperties. This is   more efficient because the document is not written back.</p>
<p><strong><em>VB.NET Example that uses FlushToFile after changing iProps</em></strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Private</span> <span style="color: blue;">Sub</span> SetProperty(<span style="color: blue;">ByVal</span> author <span style="color: blue;">As</span> <span style="color: blue;">String</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oApprenticeDoc <span style="color: blue;">As</span> <span style="color: #2b91af;">ApprenticeServerDocument</span></p>
<p style="margin: 0px;">    oApprenticeDoc = mApprenticeServer.Open _</p>
<p style="margin: 0px;">                       (<span style="color: #a31515;">"c:\Temp\MyPart.ipt"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">'Get "Inventor Summary Information" PropertySet</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oPropertySet <span style="color: blue;">As</span> <span style="color: #2b91af;">PropertySet</span></p>
<p style="margin: 0px;">    oPropertySet = oApprenticeDoc.PropertySets _</p>
<p style="margin: 0px;">     (<span style="color: #a31515;">"{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">'Get Author property</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oProperty <span style="color: blue;">As</span> Inventor.<span style="color: #2b91af;">Property</span> =</p>
<p style="margin: 0px;">                       oPropertySet.Item(<span style="color: #a31515;">"Author"</span>)</p>
<p style="margin: 0px;">    oProperty.Value = author</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    oApprenticeDoc.PropertySets.FlushToFile()</p>
<p style="margin: 0px;">    oApprenticeDoc.Close()</p>
<p style="margin: 0px;"><span style="color: #0000ff;">End Sub</span></p>
</div>
<p><strong>VB.NET Example that uses the FileSaveAs to make a copy</strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> saveToNewFile()</p>
<p style="margin: 0px;">    <span style="color: green;">' Create an instance of Apprentice.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> apprentice <span style="color: blue;">As</span> <span style="color: blue;">New</span>  _</p>
<p style="margin: 0px;">    Inventor.<span style="color: #2b91af;">ApprenticeServerComponent</span>()</p>
<p style="margin: 0px;">    <span style="color: green;">' Open a part</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> appDoc <span style="color: blue;">As</span>  _</p>
<p style="margin: 0px;">    Inventor.<span style="color: #2b91af;">ApprenticeServerDocument</span> _</p>
<p style="margin: 0px;">      = apprentice.Open _</p>
<p style="margin: 0px;">                  (<span style="color: #a31515;">"C:\Temp\Part1.ipt"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Save the file to a new name</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> myFileSaveAs <span style="color: blue;">As</span> <span style="color: #2b91af;">FileSaveAs</span> =</p>
<p style="margin: 0px;">                  apprentice.FileSaveAs</p>
<p style="margin: 0px;">    myFileSaveAs.AddFileToSave _</p>
<p style="margin: 0px;">    (appDoc, <span style="color: #a31515;">"C:\Temp\Part1_update.ipt"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    myFileSaveAs.ExecuteSaveCopyAs()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    appDoc.Close()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><em>Transient Camera</em></p>
<p>You can create image files by getting the camera from the <em>TransientObjects</em> of the <em>ApprenticeServerComponent </em>CreateCamera method. </p>
<p><strong>VB.NET example that opens a part and creates a jpg file</strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> saveMyImage()</p>
<p style="margin: 0px;">    <span style="color: green;">' Create an instance of Apprentice.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> apprentice <span style="color: blue;">As</span> <span style="color: blue;">New</span>  _</p>
<p style="margin: 0px;">    Inventor.<span style="color: #2b91af;">ApprenticeServerComponent</span>()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Open the specified file.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> appDoc <span style="color: blue;">As</span>  _</p>
<p style="margin: 0px;">    Inventor.<span style="color: #2b91af;">ApprenticeServerDocument</span> _</p>
<p style="margin: 0px;">      = apprentice.Open(<span style="color: #a31515;">"C:\Temp\Part1.ipt"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Create a camera.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> cam <span style="color: blue;">As</span> Inventor.<span style="color: #2b91af;">Camera</span> =</p>
<p style="margin: 0px;">  apprentice.TransientObjects.CreateCamera</p>
<p style="margin: 0px;">    <span style="color: green;">' Associate the camera with the part's</span></p>
<p style="margin: 0px;">    <span style="color: green;">' component definition.</span></p>
<p style="margin: 0px;">    cam.SceneObject =</p>
<p style="margin: 0px;">                appDoc.ComponentDefinition</p>
<p style="margin: 0px;">    <span style="color: green;">' Set the camera to the desired </span></p>
<p style="margin: 0px;">    <span style="color: green;">' orientation and position.</span></p>
<p style="margin: 0px;">    cam.ViewOrientationType =</p>
<p style="margin: 0px;">        Inventor.<span style="color: #2b91af;">ViewOrientationTypeEnum</span>.</p>
<p style="margin: 0px;">               kIsoTopRightViewOrientation</p>
<p style="margin: 0px;">    cam.Fit()</p>
<p style="margin: 0px;">    cam.ApplyWithoutTransition()</p>
<p style="margin: 0px;">    <span style="color: green;">'cam.Apply()</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oTOs <span style="color: blue;">As</span> <span style="color: #2b91af;">TransientObjects</span></p>
<p style="margin: 0px;">    oTOs = apprentice.TransientObjects</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oTopColor <span style="color: blue;">As</span> <span style="color: #2b91af;">Color</span></p>
<p style="margin: 0px;">    oTopColor =</p>
<p style="margin: 0px;">        oTOs.CreateColor(255, 0, 0)</p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oBottomColor <span style="color: blue;">As</span> <span style="color: #2b91af;">Color</span></p>
<p style="margin: 0px;">    oBottomColor =</p>
<p style="margin: 0px;">        oTOs.CreateColor(255, 255, 255)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Create an jpg file</span></p>
<p style="margin: 0px;">    cam.SaveAsBitmap(<span style="color: #a31515;">"C:\Temp\Part1.jpg"</span>,</p>
<p style="margin: 0px;">        800, 600, oTopColor, oBottomColor)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong>Inventor View Control</strong></p>
<p>You can use a control that is installed with Inventor View to view Inventor files in your own application. The control is named InventorViewCtrl.ocx. To add it to your project in Visual Studio right click on the Toolbox and select “Choose  Items…” On the COM Components tab select it. Once it is in the Toolbox select it and place it on your form. <a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee90187e5970d-pi"><img alt="image" border="0" height="201" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee90187fc970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="463" /></a></p>
<p> </p>
<p>Note: To work with Inventor View control of 2013 use .NET framework 3.5    </p>
<p>Before Inventor 2012, InventorViewCtrl.ocx was registered automatically with product. Starting from 2012, the registry-free was introduced. So plug-in developers have to link the corresponding manifest files to their application if they want to use the OCX.</p>
<p>Two options:    <br />1. Use mt.exe to generate manifest file by yourself and link the manifest file to your application.     <br />2. Use old style. But you have to register InventorViewCtrl.ocx manually by running “Regsvr32 InventorViewCtrl.ocx”.</p>
<p>See the post here for more information about this:</p>
<p><a href="http://adndevblog.typepad.com/manufacturing/2012/05/inventor-view-control-is-not-registered-on-inventor-2012.html" title="http://adndevblog.typepad.com/manufacturing/2012/05/inventor-view-control-is-not-registered-on-inventor-2012.html">http://adndevblog.typepad.com/manufacturing/2012/05/inventor-view-control-is-not-registered-on-inventor-2012.html</a></p>
<p><strong>Lab work with Apprentice API</strong></p>
<p>Create a Windows Forms application that has two buttons a label and a TextBox. When one of the buttons is clicked, provide the user with a way to select a part file (ipt). Once the file is selected create a jpg from the file. When the other button is selected open a file and update the Author iProperty with the value in the TextBox.  </p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d418db0e9970c-pi"><img alt="image" border="0" height="304" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c375e71c5970b-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" width="299" /></a></p>
<p><strong>Lab – use the view control</strong></p>
<p>Create a Windows Forms application that has the viewer control and a button. When the user clicks the button display the file in the viewer control.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee901881f970d-pi"><img alt="image" border="0" height="310" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d418db106970c-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" width="306" /></a></p>
<p>Here are examples of the completed Labs. (VB.NET and C#) The zip also contains the ppt we use for the training.  </p>
<p> 
<span class="asset  asset-generic at-xid-6a00e553fcbfc68834017ee9018cb5970d"><a href="http://modthemachine.typepad.com/files/inventor_training_module_12_samples.zip">Download Inventor_Training_Module_12_Samples</a></span></p>
<p>-Wayne</p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/03/inventor-api-training-lesson-12.html</feedburner:origLink></entry>
    <entry>
        <title>Inventor API Training  Lesson 2</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/6LfabDE7lgI/inventor-api-training-lesson-2.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/02/inventor-api-training-lesson-2.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc68834017d41470c08970c</id>
        <published>2013-02-25T14:56:53-08:00</published>
        <updated>2013-02-25T15:02:04-08:00</updated>
        <summary>Here is section two of the Inventor API training where you see how the API is used to create and access Inventor documents. This section also covers iProperties, working with units, and parameters. This is the third post with the...</summary>
        <author>
            <name>Wayne Brill</name>
        </author>
        <category scheme="http://www.sixapart.com/ns/types#category" term="Beginning API" />
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>Here is section two of the Inventor API training where you see how the API is used to create and access Inventor documents. This section also covers iProperties, working with units, and parameters. This is the third post with the Inventor API training material. (<a href="http://modthemachine.typepad.com/my_weblog/2013/02/inventor-api-training-lesson-1.html">Section one is here</a>).  </p>
<p><strong>Common Document Functionalities</strong></p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470ae6970c-pi"><img alt="image" border="0" height="287" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf03f970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="383" /></a></p>
<p>Here is the agenda for this section. Be sure to see the Lab instructions at the end of this section. (completed samples in VB.NET and C# are available)    </p>
<p><em>Document Types      <br />Working with Documents       <br />Document Settings       <br />iProperties       <br />Units of Measure       <br />Parameters       <br /></em></p>
<p><strong>Document Types</strong></p>
<p>Inventor has unique document types for different types of data. </p>
Part Documents (*.ipt)   <br />Assembly Documents (*.iam)   <br />Drawing Documents (*.idw)   <br />Presentation Documents (*.ipn)
<p>The API represents each document type using a different type of object for each type of document.    </p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cf21970b-pi"><img alt="image" border="0" height="277" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf04c970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="315" /></a></p>
<p> </p>
<p><strong><em>Accessing Documents</em></strong></p>
<em>Documents.Add()</em>   <br />
<p>To create a new document use the Add method of the Documents collection. This method takes a <em>DocumentTypeEnum</em> which determines which type of document to create. (first argument) You can have a file that you can use as a template. To use that file, you provide a string that is a path to the file. (second argument). The third argument of the Add method is a boolean that determines if the file is opened visible or not. The GetTemplateFile method of the FileManager object allows you to use the default template and change settings for the file that is being created. (You can use this for the second argument of the Add method) </p>
<em>Documents.Open()</em>   <br />
<p>The Open method of the documents collection will open existing documents. The first argument is a string with the file path of the document and the second is a boolean that controls the visibility. </p>
<em>Documents.Item()</em>   <br />
<p>You use the Item property to access currently open documents. The ActiveDocument property of the Application will get you the current document.  </p>
<p><strong><em>Opening and Creating Documents VB.NET examples</em></strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: green;">'Opens an existing document.assume part1.ipt exists</span></p>
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> OpenDoc()</p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oDoc <span style="color: blue;">As</span> <span style="color: #2b91af;">Document</span></p>
<p style="margin: 0px;">    oDoc = _InvApplication.Documents.Open _</p>
<p style="margin: 0px;">                             (<span style="color: #a31515;">"C:\Temp\Part1.ipt"</span>)</p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: green;">'Creates a new document using a specified template.</span></p>
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> CreateDoc()</p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oDoc <span style="color: blue;">As</span> <span style="color: #2b91af;">PartDocument</span></p>
<p style="margin: 0px;">    oDoc = _InvApplication.Documents.Add _</p>
<p style="margin: 0px;">          (<span style="color: #2b91af;">DocumentTypeEnum</span>.kPartDocumentObject, _</p>
<p style="margin: 0px;">     _InvApplication.FileManager.GetTemplateFile _</p>
<p style="margin: 0px;">   (<span style="color: #2b91af;">DocumentTypeEnum</span>.kPartDocumentObject), <span style="color: blue;">True</span>)</p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: green;">'Creates a new document using internally </span></p>
<p style="margin: 0px;"><span style="color: green;">'defined template. (Can be done in the UI by </span></p>
<p style="margin: 0px;"><span style="color: green;">'using Ctrl-Shift when creating new document.)</span></p>
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> CreateDoc2()</p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oDoc <span style="color: blue;">As</span> <span style="color: #2b91af;">PartDocument</span></p>
<p style="margin: 0px;">    oDoc = _InvApplication.Documents.Add _</p>
<p style="margin: 0px;">(<span style="color: #2b91af;">DocumentTypeEnum</span>.kPartDocumentObject, , <span style="color: blue;">True</span>)</p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong><em> </em></strong></p>
<p><strong><em>Saving Documents</em></strong></p>
<p>The first time a new document is saved you should use the SaveAs method with the SaveCopyAs flag set to False.</p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"> <span style="color: blue;">Dim</span> oDoc <span style="color: blue;">As</span> <span style="color: #2b91af;">PartDocument</span></p>
<p style="margin: 0px;">    oDoc = _InvApplication.Documents.Add _</p>
<p style="margin: 0px;">          (<span style="color: #2b91af;">DocumentTypeEnum</span>.kPartDocumentObject)</p>
<p style="margin: 0px;">    oDoc.SaveAs(<span style="color: #a31515;">"C:\Temp\SaveTest.ipt"</span>, <span style="color: blue;"><strong>False</strong></span>)</p>
</div>
<p>For documents that have been saved to disk you can use the Save method or the SaveAs with the SaveCopyAs flag set to True to create a copy. An error will occur if the file name parameter is the same as the open document. (keep in mind that the method will overwrite existing files).</p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;">    oDoc.Save()</p>
<p style="margin: 0px;">    oDoc.SaveAs(<span style="color: #a31515;">"C:\Temp\SaveTest2.ipt"</span>, <span style="color: blue;"><strong>True</strong></span>)</p>
</div>
<p>You can use the <em>FileSaveCounter</em> property of the document to determine if the document has been saved. </p>
<p><strong><em>Closing Documents</em></strong></p>
<p>To close a document call the Close method. You can use the SkipSave parameter to close it without saving.</p>
<p><em>Document.Close([SkipSave As Boolean = False])</em></p>
<p>Using the SkipSave argument you can bypass the dialog asking to save the changes and force the document to close without saving.  This is useful in cases where you use a file as a template by opening the file, modifying it in some way, and using SaveCopyAs to save it as a new file. Using this you can close the original without saving and without forcing the user to interact with a dialog.</p>
<p>The API has a way to close all documents. Using this method will not save any changes to documents.</p>
<p><em>Documents.CloseAll([UnreferencedOnly As Boolean = False])</em></p>
<p><strong><em>Document Settings</em></strong></p>
<p>Document settings are exposed from various objects obtained from the document.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf056970d-pi"><img alt="image" border="0" height="296" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf062970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="412" /></a></p>
<p>In this excerpt from the object model diagram you can see the objects that will allow you to get and update document settings.  Notice that these objects are accessed by using properties of the document.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cf3a970b-pi"><img alt="image" border="0" height="92" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cf4a970b-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="470" /></a></p>
<p><strong>iProperties</strong></p>
<p><strong><em>iProperties in the User Interface</em></strong></p>
<p>iProperties are used to associate information with a document. There are a predefined set of properties are available through the iProperties dialog. End-users can create additional properties using the “Custom” tab of the iProperties dialog. These properties are supported by both Inventor and Apprentice.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf06c970d-pi"><img alt="image" border="0" height="324" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cf58970b-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="319" /></a></p>
<p><strong><em>iProperties – Property Sets</em></strong></p>
<p>The PropertySets object acts as the container for all of the properties. </p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cf5f970b-pi"><img alt="image" border="0" height="320" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cf69970b-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="335" /></a></p>
<p>The PropertySets object provides access to the individual PropertySet objects using the Item property.</p>
<p><strong><em>iProperties – Property Set</em></strong></p>
<p>The PropertySet object contains a group of properties.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cf72970b-pi"><img alt="image" border="0" height="358" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf07f970d-pi" style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="199" /></a></p>
<p>Most PropertySet objects roughly correspond to the tabs in the iProperties dialog. PropertySet objects are identified by the following:    <br />InternalName (consistent)     <br />Name (consistent)     <br />DisplayName (may change)</p>
<p><strong><em>iProperties - Property</em></strong></p>
<p>Properties are named values and they are identified by:    <br />ID (consistent)     <br />Name (consistent)     <br />DisplayName (may change)</p>
<p><strong><em>Property values</em> </strong></p>
<p>Property values are stored internally as Variants. The following types are supported: Integer, Long, Double, String, Date, and Boolean. (With the exception of the thumbnail image which is IPictureDisp.)</p>
<p>PropId’s are defined in the various property related enums.</p>
<p><strong><em> </em></strong></p>
<p><strong><em>iProperty Names</em></strong>     <br /><span style="color: #0000ff;">Name</span> and <span style="color: #ffc000;">Internal Name</span> of Inventor defined property sets:</p>
<blockquote>
<p><span style="color: #0000ff;">Inventor Summary Information</span></p>
</blockquote>
<p><span style="color: #ffc000;">{F29F85E0-4FF9-1068-AB91-08002B27B3D9}</span></p>
<blockquote>
<p><span style="color: #0000ff;">Inventor Document Summary Information</span> </p>
</blockquote>
<p><span style="color: #ffc000;">{D5CDD502-2E9C-101B-9397-08002B2CF9AE}</span></p>
<blockquote>
<p><span style="color: #0000ff;">Design Tracking Properties</span></p>
</blockquote>
<p><span style="color: #ffc000;">{32853F0F-3444-11D1-9E93-0060B03C1CA6}</span></p>
<blockquote>
<p><span style="color: #0000ff;">Inventor User Defined Properties</span></p>
</blockquote>
<p><span style="color: #ffc000;">{D5CDD505-2E9C-101B-9397-08002B2CF9AE}</span></p>
<p>InternalNames can be found using the Object Browser and in SDK\Include\PropFMTIDs.h</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470b52970c-pi"><img alt="image" border="0" height="316" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf098970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="402" /></a></p>
<p><strong>VB.NET Example of changing an iProperty</strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: green;">' Access "Design Tracking Properties" </span></p>
<p style="margin: 0px;"><span style="color: green;">' "Designer" and change its value</span></p>
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> iPropAccess()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oDoc <span style="color: blue;">As</span> <span style="color: #2b91af;">Document</span></p>
<p style="margin: 0px;">    oDoc = _InvApplication.ActiveDocument</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Access a particular property set.  </span></p>
<p style="margin: 0px;">    <span style="color: green;">' Design tracking property set.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oDTProps <span style="color: blue;">As</span> <span style="color: #2b91af;">PropertySet</span></p>
<p style="margin: 0px;">    oDTProps = oDoc.PropertySets.Item _</p>
<p style="margin: 0px;">(<span style="color: #a31515;">"{32853F0F-3444-11d1-9E93-0060B03C1CA6}"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Access the same property set using</span></p>
<p style="margin: 0px;">    <span style="color: green;">' the display name or name. </span></p>
<p style="margin: 0px;">    <span style="color: green;">' DisplayName is not dependable </span></p>
<p style="margin: 0px;">    <span style="color: green;">' because it can be localized, so </span></p>
<p style="margin: 0px;">    <span style="color: green;">'the internal name or name is preferred.</span></p>
<p style="margin: 0px;">    oDTProps = oDoc.PropertySets.Item _</p>
<p style="margin: 0px;">             (<span style="color: #a31515;">"Design Tracking Properties"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Get a specific property, in this case</span></p>
<p style="margin: 0px;">    <span style="color: green;">' the designer property.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oDesignerProp <span style="color: blue;">As</span> Inventor.<span style="color: #2b91af;">Property</span></p>
<p style="margin: 0px;">    oDesignerProp = oDTProps.ItemByPropId( _</p>
<p style="margin: 0px;"> <span style="color: #2b91af;">PropertiesForDesignTrackingPropertiesEnum</span> _</p>
<p style="margin: 0px;">         .kDesignerDesignTrackingProperties)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' You can also use the name or display name</span></p>
<p style="margin: 0px;">    <span style="color: green;">' the display name has the problem that </span></p>
<p style="margin: 0px;">    <span style="color: green;">' it can be changed.</span></p>
<p style="margin: 0px;">    oDesignerProp = oDTProps.Item(<span style="color: #a31515;">"Designer"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Show the display name and value.</span></p>
<p style="margin: 0px;">    <span style="color: #2b91af;">Debug</span>.Print(oDesignerProp.DisplayName _</p>
<p style="margin: 0px;">                &amp; <span style="color: #a31515;">" = "</span> &amp; oDesignerProp.Value)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Change the designer name.</span></p>
<p style="margin: 0px;">    oDesignerProp.Value = <span style="color: #a31515;">"Bill &amp; Ted"</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong><em>iProperties - Creation</em></strong></p>
<p>To create new property set use the Add method of the PropertySets collection. (Name and InternalName must be unique with respect to other property sets in the document).</p>
<p><em>PropertySets.Add(Name As String, [InternalName]) As PropertySet      <br /></em></p>
<p>To create and add new properties to the PropertySet use the Add method. Keep in mind that properties cannot be added to the predefined sets, except for the custom property set. Also the  <br />name and PropId must be unique with respect to other properties in the property set. The value type can be most Variant types except arrays and objects.</p>
<p><em>PropertySet.Add(PropValue, [Name], [PropId]) As Property      <br /></em></p>
<p>Note: PropertySets and Properties can be created as hidden by using a name that begins with an underscore.  These will not be returned by indexing through a collection.  They can only be retrieved by asking for them by name.    </p>
<p><strong>Units of Measure</strong></p>
<p>When you use Inventor manually there is a setting that controls the units that are used. When using the API numbers are always in the same internal units and your code needs to convert between units to get the correct behavior. (unless the document settings are using the same internal units). </p>
<p>All Inventor documents use these internal units.    <br />Length: Centimeters     <br />Angle: Radians     <br />Time: Second     <br />Mass: Kilogram</p>
<p>The units specified by the end-user in the Document Settings dialog are used to convert internal units to/from the units the end-user wants to use.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf0a8970d-pi"><img alt="image" border="0" height="294" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470b6a970c-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="390" /></a></p>
<p><strong><em>UnitsOfMeasure object</em></strong> </p>
<p>The<em> UnitsOfMeasure</em> object allows you to work with different units. It provides utilities to help with unit handling, primarily the conversion between strings and values. If you are working with numbers you will most likely need to use UnitsOfMeasure to get the results you expect.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cf98970b-pi"><img alt="image" border="0" height="74" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470b73970c-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="359" /></a></p>
<p> </p>
<p>A unique UnitsOfMeasure object can be obtained from each document. The UnitsOfMeasure object obtained from a document can be used for unit conversion and also provides a way to control unit settings for the document. The UnitsOfMeasure obtained from the Application object can be used for unit conversion.</p>
<p><strong><em>Units of Measure - Unit Types        <br /></em></strong>Whenever a unit type is specified within the API, it can be defined in two different ways:</p>
<p>1. As a value from UnitsTypeEnum with a specific unit type such as:</p>
<p><em>kInchLengthUnits, kMillimeterLengthUnits, kDegreeAngleUnits</em>. </p>
<p>The current default type specified by the end-user: <em>kDefaultDisplayLengthUnits, kDefaultDisplayAngleUnits</em>.     <br />The internal base units: kDatabaseLengthUnits, kDatabaseAngleUnits.</p>
<p>2. As a string, i.e. “in”, “mm mm mm”, “m ^ 3”, “m /(s s)”</p>
<p><strong><em>Units of Measure – Internal Units</em></strong></p>
<p>Internally, Inventor uses a consistent set of units regardless of what the user has specified as the document default and the precision is always double-precision floating point, </p>
<p>Internal units used by Inventor for the various types of units</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf0c2970d-pi"><img alt="image" border="0" height="221" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470b7c970c-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="309" /></a></p>
<p><strong><em>VB.NET - UnitsOfMeasure to get valid input from the user</em></strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Private</span> m_oUOM <span style="color: blue;">As</span> <span style="color: #2b91af;">UnitsOfMeasure</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">Private</span> <span style="color: blue;">Sub</span> UserForm_Initialize()</p>
<p style="margin: 0px;">    <span style="color: green;">' get the UnitsOfMeasure of the</span></p>
<p style="margin: 0px;">    <span style="color: green;">' current document</span></p>
<p style="margin: 0px;">    m_oUOM = _InvApplication.</p>
<p style="margin: 0px;">        ActiveDocument.UnitsOfMeasure</p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">Private</span> <span style="color: blue;">Sub</span> TextBox1_Change()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Check if the input string defines </span></p>
<p style="margin: 0px;">    <span style="color: green;">'a valid length.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">If</span> <span style="color: blue;">Not</span> m_oUOM.IsExpressionValid _</p>
<p style="margin: 0px;">        (TextBox1.Text, _</p>
<p style="margin: 0px;"><span style="color: #2b91af;">   UnitsTypeEnum</span>.kDefaultDisplayLengthUnits) <span style="color: blue;">Then</span></p>
<p style="margin: 0px;">        <span style="color: green;">' The string is not valid so change</span></p>
<p style="margin: 0px;">        <span style="color: green;">' the text color to red.</span></p>
<p style="margin: 0px;">        TextBox1.ForeColor =</p>
<p style="margin: 0px;">                   Drawing.<span style="color: #2b91af;">Color</span>.Red</p>
<p style="margin: 0px;">    <span style="color: blue;">Else</span></p>
<p style="margin: 0px;">        <span style="color: green;">' The string is  valid so change </span></p>
<p style="margin: 0px;">        <span style="color: green;">'the text color to the default color.</span></p>
<p style="margin: 0px;">        TextBox1.ForeColor =</p>
<p style="margin: 0px;">                      Drawing.<span style="color: #2b91af;">Color</span>.Black</p>
<p style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">If</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong>VB.NET – UnitsOfMeasure - Using user Input</strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"> <span style="color: green;">' Get the real value of the input string.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> dValue <span style="color: blue;">As</span> <span style="color: blue;">Double</span></p>
<p style="margin: 0px;">    dValue = m_oUOM.GetValueFromExpression _</p>
<p style="margin: 0px;">                           (txtInput.Text, _</p>
<p style="margin: 0px;">   <span style="color: #2b91af;">UnitsTypeEnum</span>.kDefaultDisplayLengthUnits)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Compare the value with the length of </span></p>
<p style="margin: 0px;">    <span style="color: green;">' a sketch line.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">If</span> System.<span style="color: #2b91af;">Math</span>.Abs)</p>
<p style="margin: 0px;">(oSketchLine.Length - dValue)_ &lt; 0.00001 <span style="color: blue;">Then</span></p>
<p style="margin: 0px;">        MsgBox _</p>
<p style="margin: 0px;">         (<span style="color: #a31515;">"Line is equal to the input value"</span>)</p>
<p style="margin: 0px;">    <span style="color: blue;">Else</span></p>
<p style="margin: 0px;">        MsgBox _</p>
<p style="margin: 0px;">     (<span style="color: #a31515;">"Line is not equal to the input value"</span>)</p>
<p style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">If</span></p>
</div>
<p><strong>VB.NET UnitsOfMeasure - Displaying Values</strong></p>
<p>In this example a double (centimeters) is passed into a function  that gets the value of the double in the units that are current and returns it as a string.</p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Private</span> <span style="color: blue;">Sub</span> TestLength()</p>
<p style="margin: 0px;">    ShowLength(6.5)</p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">Private</span> <span style="color: blue;">Sub</span> ShowLength(<span style="color: blue;">ByVal</span> dLength <span style="color: blue;">As</span> <span style="color: blue;">Double</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Get the string representation of the length.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> strLength <span style="color: blue;">As</span> <span style="color: blue;">String</span></p>
<p style="margin: 0px;">    strLength = m_oUOM.GetStringFromValue _</p>
<p style="margin: 0px;">                                (dLength, _</p>
<p style="margin: 0px;">   <span style="color: #2b91af;">UnitsTypeEnum</span>.kDefaultDisplayLengthUnits)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    MsgBox(<span style="color: #a31515;">"The Length is: "</span> &amp; strLength)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong> </strong></p>
<p><strong>Parameters</strong></p>
<p><strong><em>Component Definition</em></strong></p>
<p>The Component definition will be discussed in following lessons. However we need to introduce it here because parameters are obtained form properties of the component definition. This excerpt from the Object Model diagram shows the property that will allow you to get the Component Definition of a document. (Drawings don’t have a ComponentDefinition).</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf0ce970d-pi"><img alt="image" border="0" height="150" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf0da970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="485" /></a></p>
<p><strong><em>Parameters - In the User Interface</em></strong></p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cfb6970b-pi"><img alt="image" border="0" height="322" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470b9b970c-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="469" /></a></p>
<p><strong><em>Parameters – In the API</em></strong></p>
<p>Notice how the Parameters collection is obtained from a PartComponentDefinition or AssemblyComponentDefinition</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cfc7970b-pi"><img alt="image" border="0" height="77" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cfcc970b-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="466" /></a></p>
<p>In this VB.NET code snippet the Parameters are accessed.</p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"> <span style="color: green;">' Get the Parameters collection object. </span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oParameters <span style="color: blue;">As</span> <span style="color: #2b91af;">Parameters</span> = _</p>
<p style="margin: 0px;">    _InvApplication.ActiveDocument.</p>
<p style="margin: 0px;">            ComponentDefinition.Parameters</p>
</div>
<p><strong><em>Parameters – UI vs. API</em></strong></p>
<p>On the left in this picture you can see settings from the parameters dialog. The text on the right shows how a similar setting would be made using the API.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf110970d-pi"><img alt="image" border="0" height="320" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf121970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="497" /></a></p>
<p><strong><em>VB.NET - Parameters - Setting Values</em></strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> SetParameter()</p>
<p style="margin: 0px;">    <span style="color: green;">' Get the Parameters object. Assumes </span></p>
<p style="margin: 0px;">    <span style="color: green;">'a part or assembly document is active.</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oParameters <span style="color: blue;">As</span> <span style="color: #2b91af;">Parameters</span></p>
<p style="margin: 0px;">    oParameters = _InvApplication.</p>
<p style="margin: 0px;">   ActiveDocument.ComponentDefinition.Parameters</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Get the parameter named "Length".</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oLengthParam <span style="color: blue;">As</span> <span style="color: #2b91af;">Parameter</span></p>
<p style="margin: 0px;">    oLengthParam = oParameters.Item _</p>
<p style="margin: 0px;">                              (<span style="color: #a31515;">"Length"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Change the equation of the parameter.</span></p>
<p style="margin: 0px;">    oLengthParam.Expression = <span style="color: #a31515;">"3.5 in"</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">' Update the document.</span></p>
<p style="margin: 0px;">    _InvApplication.ActiveDocument.Update()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong><em>Parameters – Units</em></strong></p>
<p>The Unit property can be set using either a String or a value from <em>UnitsTypeEnum</em>. This enum is an API equivalent to the pre-defined unit types displayed in the Unit Type dialog. </p>
<p>Setting the unit type using a String is the same as defining a unit in the Unit Type dialog and allows you to define custom unit types by combining known unit types.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cfe3970b-pi"><img alt="image" border="0" height="444" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470bc5970c-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="398" /></a>     </p>
<p><strong><em>Parameters – Values</em></strong></p>
<p>Unlike in the user-interface, the API allows you to directly set the value of a parameter. The Value property sets the actual value of the parameter and will overwrite any existing equation.</p>
<p><span style="color: #ff0000;"><span style="color: #000000;"><strong>Note</strong>: <em>In API, Parameter values are always defined using internal units.</em></span><em> <span style="color: #000000;">(use UnitsOfMeasure to convert)</span>         <br /></em></span>Length – Centimeters     <br />Angle – Radians  <br />π radians = 180 degrees     <br />π = Atn(1) * 4 </p>
<p><strong><em>Parameters - Tolerances</em></strong>     <br />Tolerances can be defined for Model parameters. The Tolerance object exposes functionalities of the Tolerance dialog.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470bcd970c-pi"><img alt="image" border="0" height="60" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470bd3970c-pi" style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="127" /></a></p>
<p>The SetToDefault, SetToDeviation, SetToLimits, etc… methods of the Parameter object allow you to define the parameter’s tolerance.    <br />    Call oParam.Tolerance.SetToDeviation("0.125 in", “-0.0625 in")     <br />    Call oParam.Tolerance.SetToDeviation(2.54 / 8, -2.54 / 16)</p>
<p>The ModelValueType property sets which tolerance to use when computing the model value.The Precision property sets the number of decimal places to display.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470bde970c-pi"><img alt="image" border="0" height="319" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470be6970c-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="293" /></a></p>
<p>The SetAllToMax, SetAllToMedian, SetAllToMin, SetAllToNominal methods of the Parameters object provides the equivalent of the Parameter dialog’s “Reset Tolerance”.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41470bee970c-pi"><img alt="image" border="0" height="85" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717cfff970b-pi" style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="187" /></a></p>
<p><strong><em>Parameters – Parameter Types</em></strong></p>
<p>The Parameters collection returns all Parameter objects regardless of the type. The ModelParameters, ParameterTables, ReferenceParameters, and UserParameters objects provide access to specific types of parameters.</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c3717d005970b-pi"><img alt="image" border="0" height="429" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf143970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="236" /></a>     </p>
<p><strong><em>Parameters – Parameter Creation</em></strong></p>
<p>Parameters are created by using methods on the collection for the specific type of parameter you want to create. In the user-interface you can only create user parameters.  All other types are indirectly created as a result of other actions. In the API you can directly create user, model, and reference parameters. TableParameters are created by importing an Excel worksheet. Parameters are created using either the AddByExpression or AddByValue methods</p>
<p><strong><em>VB.NET - Creating Parameters</em></strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"> <span style="color: green;">' add user parameters</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oUserParams <span style="color: blue;">As</span> <span style="color: #2b91af;">UserParameters</span></p>
<p style="margin: 0px;">    oUserParams = oCompDef.Parameters.</p>
<p style="margin: 0px;">                        UserParameters</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oParam <span style="color: blue;">As</span> <span style="color: #2b91af;">Parameter</span></p>
<p style="margin: 0px;">    oParam = oUserParams.AddByExpression _</p>
<p style="margin: 0px;">        (<span style="color: #a31515;">"NewParam1"</span>, <span style="color: #a31515;">"3"</span>, _</p>
<p style="margin: 0px;">           <span style="color: #2b91af;">UnitsTypeEnum</span>.kInchLengthUnits)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    oParam = oUserParams.AddByExpression _</p>
<p style="margin: 0px;">                  (<span style="color: #a31515;">"NewParam1"</span>, <span style="color: #a31515;">"3"</span>, <span style="color: #a31515;">"in"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    oParam = oUserParams.AddByExpression _</p>
<p style="margin: 0px;">                      (<span style="color: #a31515;">"NewParam2"</span>, <span style="color: #a31515;">"3"</span>, _</p>
<p style="margin: 0px;"> <span style="color: #2b91af;">UnitsTypeEnum</span>.kDefaultDisplayLengthUnits)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    oParam = oUserParams.AddByExpression _</p>
<p style="margin: 0px;">                   (<span style="color: #a31515;">"NewParam2"</span>, <span style="color: #a31515;">"3 in"</span>, _</p>
<p style="margin: 0px;"> <span style="color: #2b91af;">UnitsTypeEnum</span>.kDefaultDisplayLengthUnits)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    oParam = oUserParams.AddByValue _</p>
<p style="margin: 0px;">            (<span style="color: #a31515;">"NewParam3"</span>, 3 * 2.54, _</p>
<p style="margin: 0px;"> <span style="color: #2b91af;">UnitsTypeEnum</span>.kDefaultDisplayLengthUnits)</p>
</div>
<p><strong><em>Parameters – API Only Functionality</em></strong></p>
<p>Creation of Model and Reference parameters.    <br />Delete unused Model and Referenced Parameters.     <br />DisabledActionTypes – Prohibit deletion of user parameters.     <br />Dependents, DrivenBy – Provides dependency information between parameters.     <br />Creation of custom parameter groups.     <br />Change the type of a parameter.  </p>
<blockquote>
<p>Model to Reference      <br />Reference to Model       <br />User to Model       <br />User to Reference</p>
</blockquote>
<p><strong> </strong></p>
<p><strong>Lab: iProperties</strong>     </p>
<p>Write a .Net program that performs the following steps:    <br />1. Create a new part document.     <br />2. Edit the value of the author property to contain your name.     <br />3. Create a new custom (user-defined) property </p>
<p>4. Save the document </p>
<p>5. Close the document.</p>
<p><strong>Lab: Parameters and UOM</strong>     <br />1. Interactively create a simple part that contains a parameter named “Length” to control the size of the part.</p>
<p>2. Create a .Net program that contains a dialog that looks similar to this:</p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf14b970d-pi"><img alt="image" border="0" height="128" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee8baf156970d-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="331" /></a></p>
<p>3. The end-user should have created a parameter named “Length” which is a numeric. By this code, he is able to enter any valid expression.  The text field should provide feedback when an invalid expression has been defined. </p>
<p>4. When the “Update” button is pressed the entered value should be assigned to the parameter    </p>
<p>Here are examples of the completed Labs. (VB.NET and C#) It also contains the ppt we use for the training and another project with some sample code.</p>
<p> 
<span class="asset  asset-generic at-xid-6a00e553fcbfc68834017c3717d58e970b"><a href="http://modthemachine.typepad.com/files/inventor_training_module_02_samples.zip">Download Inventor_Training_Module_02_Samples</a></span></p>
<p>-Wayne</p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/02/inventor-api-training-lesson-2.html</feedburner:origLink></entry>
    <entry>
        <title>Inventor API Training  Lesson 11</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/pZJst57YdY4/inventor-api-training-lesson-11.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/02/inventor-api-training-lesson-11.html" thr:count="1" thr:updated="2013-02-19T23:01:18-08:00" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc68834017c36f4d4ee970b</id>
        <published>2013-02-18T10:47:49-08:00</published>
        <updated>2013-02-18T10:51:38-08:00</updated>
        <summary>Here is section eleven of the Inventor API training. In this section we cover how to use the API to print and translate files. There are 21 sections to this training and we decided that they did not need to...</summary>
        <author>
            <name>Wayne Brill</name>
        </author>
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>Here is section eleven of the Inventor API training. In this section we cover how to use the API to print and translate files. There are  21 sections to this training and we decided that they did not need to be posted in order. (<a href="http://modthemachine.typepad.com/my_weblog/2013/02/inventor-api-training-lesson-1.html" target="_blank">Section one is here</a>). I am going to alternate posts between sections 1-10 and 10-21. </p>
<p><strong>Printing and Translating Files</strong></p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d412423de970c-pi"><img alt="image" border="0" height="260" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c36f4d4cc970b-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="344" /></a></p>
<p>Here is the agenda for this section. Be sure to see the Lab instructions at the end of this section. (completed sample is available) </p>
<p><em>PrintManager Object      <br />DrawingPrintManager       <br />Printing Example       <br />File Translation       <br />Accessing Translators Options       <br />DataIO Object</em></p>
<p><strong>PrintManager Object</strong></p>
<p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017ee897fce6970d-pi"><img alt="image" border="0" height="327" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c36f4d4e0970b-pi" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" width="441" /></a></p>
<p>The PrintManager object can be accessed from the different types of documents such as an part or assembly. Also Drawings and Apprentice support special print managers that provide additional printing capabilities.These PrintManager objects provide that same settings that are available in the Print command dialogs in the user interface.</p>
<p><strong>PrintManager - Main Properties      <br /></strong>Here are the main properties and methods of the PrintManager object. </p>
<p><em>NumberOfCopies</em>: Default value to 1     <br /><em>PaperHeight / PaperWidth</em>: Sets the paper dimensions. This property is only used when the PaperSize property is set to kPaperSizeCustom     <br /><em>Printer</em>:  gets and sets the name of the printing device</p>
<p><em>PrintToFile</em>(String FileName): Prints to the specified file using the current property settings     <br /><em>SubmitPrint</em>: Prints the file using the current property settings</p>
<p>   <br /><strong>DrawingPrintManager Object</strong>     <br />The DrawingPrintManager object derives from PrintManager and has some additional properties and methods specific to drawing documents. </p>
<p><em>AllColorsAsBlack:</em> No colors in the print     <br /><em>PrintRange</em>: Can be set to kPrintCurrentSheet, kPrintAllSheets, kPrintSheetRange.     <br /><em>ScaleMode / Scale</em>:  Gets and sets how the scale of the print is defined.     <br /><em>RemoveLineWeights:</em> All lines will have the same default width </p>
<p><em>GetSheetRange / SetSheetRange</em>:  Gets/sets the sheet range to print.</p>
<p><strong>Print Sample VB.NET</strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> PrintSample()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oDrawDoc <span style="color: blue;">As</span> <span style="color: #2b91af;">DrawingDocument</span></p>
<p style="margin: 0px;">    oDrawDoc = mApp.ActiveDocument</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oPrintMgr <span style="color: blue;">As</span> <span style="color: #2b91af;">DrawingPrintManager</span></p>
<p style="margin: 0px;">    oPrintMgr = oDrawDoc.PrintManager</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">With</span> oPrintMgr</p>
<p style="margin: 0px;">        .Printer = <span style="color: #a31515;">"\\ADSOREPS1\oreprn001"</span></p>
<p style="margin: 0px;">        .NumberOfCopies = 1</p>
<p style="margin: 0px;">        .ScaleMode = _</p>
<p style="margin: 0px;">      <span style="color: #2b91af;">PrintScaleModeEnum</span>.kPrintFullScale</p>
<p style="margin: 0px;">        .PaperSize = _</p>
<p style="margin: 0px;">          <span style="color: #2b91af;">PaperSizeEnum</span>.kPaperSize11x17</p>
<p style="margin: 0px;">        .SubmitPrint()</p>
<p style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">With</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong> </strong></p>
<p><strong>File Translation </strong></p>
<p><strong>Simple Translation using Open and SaveAs</strong>     <br />You can use the Document.SaveAs and Documents.Open methods to translate documents in and out of Inventor. The extension of the filename supplied will be used to determine which translator to use. With this approach default settings are used. The default settings are the settings last used when interactively translating a file. In this code snippet an stp file is opened and a document is saved as and AutoCAD dwg file.</p>
<p><em>Documents.Open( “C:\Temp\Test.stp” )      <br />Document.SaveAs( “C:\Temp\New.dwg”, True )</em></p>
<p><strong>File Translation using the translator Add-Ins</strong>     <br />If you want to control the settings when translating files you use the Translator Add-Ins. The main properties and methods of translator add-ins are these:</p>
<p><em>HasOpenOptions</em>: Returns whether or not the translator has options available for opening files. The three arguments (DataMedium, TranslationContext, NameValueMap ) contain settings you can use. </p>
<p><em>Open</em>: Opens (translates) a file. This method takes four objects as arguments that control how the open will work.</p>
<blockquote>
<p><em>DataMedium</em>: Use the FileName property to set the file name to open. </p>
</blockquote>
<blockquote>
<p><em>TranslationContext</em>: For file, set Type to kFileBrowseIOMechanism you can place the translated file into an existing document with the OpenIntoExisting property</p>
</blockquote>
<blockquote>
<p><em>NameValueMap</em>: Use this to set the options for the open</p>
</blockquote>
<blockquote>
<p><em>Object</em>: The object that will be created - usually a document </p>
</blockquote>
<p><em>HasSaveCopyAsOptions</em>: Returns whether or not the translator has options available for saving files. The three arguments (Object, TranslationContext, NameValueMap ) will contain settings you can use. </p>
<p><em>SaveCopyAs</em>: Save the document to the specified data-source. This method takes the following arguments:</p>
<blockquote>
<p><em>Object</em>: The document to be saved       <br /><em>TranslationContext</em>: For file set Type to  kFileBrowseIOMechanism  </p>
</blockquote>
<blockquote>
<p><em>NameValueMap</em>: Use this to set the options for the translation       <br /><em>DataMedium</em>: Use the FileName property to set the file name to save </p>
<p> </p>
</blockquote>
<p>Each of the translator Add-Ins have a GUID. You can use this identifier (String) with the <em>ItemById</em> method of the <em>ApplicationAddIns</em> property of the Inventor Application object to instantiate the translator. The following example gets the STEP translator and uses the HasOpenOptions() method to print the options (that could be set before using the Open method) to the immediate window. </p>
<p><strong>Accessing Translator’s Open Options – VB.NET</strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> GetTranslatorOpenOptions()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: green;">'Using the GUID of the STEP Translator</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> clsId <span style="color: blue;">As</span> <span style="color: blue;">String</span></p>
<p style="margin: 0px;">    clsId = <span style="color: #a31515;">"{90AF7F40-0C01-11D5-8E83-0010B541CD80}"</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oTranslator <span style="color: blue;">As</span> <span style="color: #2b91af;">TranslatorAddIn</span></p>
<p style="margin: 0px;">    oTranslator = _</p>
<p style="margin: 0px;">        mApp.ApplicationAddIns.ItemById(clsId)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> medium <span style="color: blue;">As</span> <span style="color: #2b91af;">DataMedium</span></p>
<p style="margin: 0px;">    medium = _</p>
<p style="margin: 0px;">        mApp.TransientObjects.CreateDataMedium</p>
<p style="margin: 0px;">    <span style="color: green;">' medium.FileName = "C:\MyInventorDoc.xxx"</span></p>
<p style="margin: 0px;">    medium.MediumType = _</p>
<p style="margin: 0px;">            <span style="color: #2b91af;">MediumTypeEnum</span>.kFileNameMedium</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> context <span style="color: blue;">As</span> <span style="color: #2b91af;">TranslationContext</span></p>
<p style="margin: 0px;">    context = mApp.TransientObjects.</p>
<p style="margin: 0px;">                     CreateTranslationContext</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> options <span style="color: blue;">As</span> <span style="color: #2b91af;">NameValueMap</span></p>
<p style="margin: 0px;">    options = mApp.TransientObjects.</p>
<p style="margin: 0px;">                          CreateNameValueMap</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> index <span style="color: blue;">As</span> <span style="color: blue;">Integer</span></p>
<p style="margin: 0px;">    <span style="color: blue;">If</span> oTranslator.HasOpenOptions _</p>
<p style="margin: 0px;">            (medium, context, options) <span style="color: blue;">Then</span></p>
<p style="margin: 0px;">        <span style="color: blue;">For</span> index = 1 <span style="color: blue;">To</span> options.Count</p>
<p style="margin: 0px;">            <span style="color: #2b91af;">Debug</span>.Print(options.Name(index) _</p>
<p style="margin: 0px;">&amp; <span style="color: #a31515;">" = "</span> &amp; options.Value(options.Name(index)))</p>
<p style="margin: 0px;">        <span style="color: blue;">Next</span></p>
<p style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">If</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong>Accessing Translator’s Save Options - VB.NET</strong></p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> GetTranslatorSaveAsOptions()</p>
<p style="margin: 0px;">    <span style="color: green;">' Using GUID of the DWF Translator</span></p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> clsId <span style="color: blue;">As</span> <span style="color: blue;">String</span></p>
<p style="margin: 0px;">    clsId = <span style="color: #a31515;">"{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}"</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> oTranslator <span style="color: blue;">As</span> <span style="color: #2b91af;">TranslatorAddIn</span></p>
<p style="margin: 0px;">    oTranslator =</p>
<p style="margin: 0px;">        mApp.ApplicationAddIns.ItemById(clsId)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> context <span style="color: blue;">As</span> <span style="color: #2b91af;">TranslationContext</span></p>
<p style="margin: 0px;">    context =</p>
<p style="margin: 0px;">   mApp.TransientObjects.CreateTranslationContext</p>
<p style="margin: 0px;">    context.Type =</p>
<p style="margin: 0px;">        <span style="color: #2b91af;">IOMechanismEnum</span>.kUnspecifiedIOMechanism</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> options <span style="color: blue;">As</span> <span style="color: #2b91af;">NameValueMap</span></p>
<p style="margin: 0px;">    options =</p>
<p style="margin: 0px;">        mApp.TransientObjects.CreateNameValueMap</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> SourceObject <span style="color: blue;">As</span> <span style="color: blue;">Object</span></p>
<p style="margin: 0px;">    SourceObject = mApp.ActiveDocument</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Dim</span> index <span style="color: blue;">As</span> <span style="color: blue;">Integer</span></p>
<p style="margin: 0px;">    <span style="color: blue;">If</span> oTranslator.HasSaveCopyAsOptions _</p>
<p style="margin: 0px;">        (SourceObject, context, options) <span style="color: blue;">Then</span></p>
<p style="margin: 0px;">        <span style="color: blue;">For</span> index = 1 <span style="color: blue;">To</span> options.Count</p>
<p style="margin: 0px;">            <span style="color: #2b91af;">Debug</span>.Print(options.Name(index) &amp;</p>
<p style="margin: 0px;">      <span style="color: #a31515;">" = "</span> &amp; options.Value(options.Name(index)))</p>
<p style="margin: 0px;">        <span style="color: blue;">Next</span></p>
<p style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">If</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong>Inventor 2013: Built-in Translator Add-Ins GUIDs</strong></p>
<p>DWF:                {0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}    <br />PDF:                 {0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}     <br />DWFx:              {0AC6FD97-2F4D-42CE-8BE0-8AEA580399E4}     <br />JT:                    {16625A0E-F58C-4488-A969-E7EC4F99CACD}     <br />i-drop:               {21DB88B0-BFBF-11D4-8DE6-0010B541CAA8}     <br />CATIA Part:       {2FEE4AE5-36D3-4392-89C7-58A9CD14D305}     <br />SolidWorks:       {402BE503-725D-41CB-B746-D557AB83BAF1}     <br />Pro/E:               {46D96B7A-CF8A-49C9-8703-2F40CFBDF547}     <br />STL:                  {533E9A98-FC3B-11D4-8E7E-0010B541CD80}     <br />DWF:                {55EBD0FA-EF60-4028-A350-502CA148B499}     <br />Pro/E Granite:    {66CB2667-73AD-401C-A531-64EC701825A1}     <br />IDF:                  {6C5BBC04-5D6F-4353-94B1-060CD6554444}     <br />SAT:                 {89162634-02B6-11D5-8E80-0010B541CD80}     <br />CATIA Product: {8A88FC01-0C32-4B3E-BE12-DDC8DF6FFF18}     <br />Pro/E Neutral     {8CEC09E3-D638-4E8F-A6E1-0D1E1A5FC8E3}     <br />CATIA Import:    {8D1717FA-EB24-473C-8B0F-0F810C4FC5A8}Parasolid Text:   {8F9D3571-3CB8-42F7-8AFF-2DB2779C8465}     <br />STEP:               {90AF7F40-0C01-11D5-8E83-0010B541CD80}     <br />IGES:                {90AF7F44-0C01-11D5-8E83-0010B541CD80}     <br />UGS NX:            {93D506C4-8355-4E28-9C4E-C2B5F1EDC6AE}     <br />Content Center   {A547F528-D239-475F-8FC6-8F97C4DB6746}     <br />Parasolid Binary:{A8F8F8E5-BBAB-4F74-8B1B-AC011251F8AC}     <br />Drag &amp; Drop      {B95D705C-E915-4A5B-A498-E73AC98923A2}     <br />DWG:               {C24E3AC2-122E-11D5-8E91-0010B541CD80}     <br />DXF:                 {C24E3AC4-122E-11D5-8E91-0010B541CD80}     <br />Alias:                {DC5CD10A-F6D1-4CA3-A6E3-42A6D646B03E}     </p>
<p><strong>DataIO Object      <br /></strong>Some Inventor objects support a DataIO object. You can use this object to get input and output of formatted data. Use the GetInputFormats / GetOutputFormats methods to get the list of formats supported by a DataIO objects (ex DXF, DWG for sketches, FlatPattern, XML for iProperties, SAT for worksurfaces,…)</p>
<p><strong>DataIO VB.NET examples</strong></p>
<p> </p>
<div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt;">
<p style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> ExportWorkSurface()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">Dim</span> oWorkSurfaces <span style="color: blue;">As</span> <span style="color: #2b91af;">WorkSurfaces</span></p>
<p style="margin: 0px;">        oWorkSurfaces = mApp.ActiveDocument.</p>
<p style="margin: 0px;">              ComponentDefinition.WorkSurfaces</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">Dim</span> oDataIO <span style="color: blue;">As</span> <span style="color: #2b91af;">DataIO</span></p>
<p style="margin: 0px;">        oDataIO = oWorkSurfaces(1).</p>
<p style="margin: 0px;">                     SurfaceBodies(1).DataIO</p>
<p style="margin: 0px;">        oDataIO.WriteDataToFile _</p>
<p style="margin: 0px;">           (<span style="color: #a31515;">"ACIS SAT"</span>, <span style="color: #a31515;">"C:\Temp\result.sat"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> ExportSketchDXF()</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">Dim</span> oSketch <span style="color: blue;">As</span> <span style="color: #2b91af;">PlanarSketch</span></p>
<p style="margin: 0px;">        oSketch = mApp.ActiveDocument.</p>
<p style="margin: 0px;">            ComponentDefinition.Sketches(1)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">        <span style="color: blue;">Dim</span> oDataIO <span style="color: blue;">As</span> <span style="color: #2b91af;">DataIO</span></p>
<p style="margin: 0px;">        oDataIO = oSketch.DataIO</p>
<p style="margin: 0px;">        <span style="color: blue;">Call</span> oDataIO.WriteDataToFile _</p>
<p style="margin: 0px;">               (<span style="color: #a31515;">"DXF"</span>, <span style="color: #a31515;">"C:\Temp\dxfout.dxf"</span>)</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;">    <span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p><strong>Lab: Access the Translator Add-In options</strong>     <br />Create a windows forms application. On the form have a ListView, a ComboBox and a Button. In the ComboBox allow the user to select the name of a Translator. When the button is clicked populate the ListView with the open options and save options for the selected Translator Add-In. Here are examples of the completed Lab. (VB.NET and C#)  </p>
<p> 
<span class="asset  asset-generic at-xid-6a00e553fcbfc68834017c36f4d914970b"><a href="http://modthemachine.typepad.com/files/inventor_training_module_11_samples.zip">Download Inventor_Training_Module_11_Samples</a></span></p>
<p>-Wayne    </p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/02/inventor-api-training-lesson-11.html</feedburner:origLink></entry>
    <entry>
        <title>ETO 2013 R2  Add-In template, VS Add-Ins can impact ETO Studio  InventorApplication global rule</title>
        <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/modthemachine/~3/aLjyqn8zlSM/eto-2013-r2-add-in-template-vs-add-ins-can-impact-eto-studio-inventorapplication-global-rule.html" />
        <link rel="replies" type="text/html" href="http://modthemachine.typepad.com/my_weblog/2013/02/eto-2013-r2-add-in-template-vs-add-ins-can-impact-eto-studio-inventorapplication-global-rule.html" thr:count="0" />
        <id>tag:typepad.com,2003:post-6a00e553fcbfc68834017d41026ded970c</id>
        <published>2013-02-12T15:05:17-08:00</published>
        <updated>2013-02-12T15:05:17-08:00</updated>
        <summary>Here are a couple of things about ETO 2013 R2 that I have found recently. 1. If you have used the Inventor ETO Add-In template you may find that the ribbon tab for the Add-In does not display properly when...</summary>
        <author>
            <name>Wayne Brill</name>
        </author>
        
        
<content type="xhtml" xml:lang="en-US" xml:base="http://modthemachine.typepad.com/my_weblog/">
<div xmlns="http://www.w3.org/1999/xhtml"><p>Here are a couple of things about ETO 2013 R2 that I have found recently.  </p>  <p>1. If you have used the Inventor ETO Add-In template you may find that the ribbon tab for the Add-In does not display properly when Inventor is launched through ETO Studio. When Intent is started from Visual Studio, it does extensive processing in its OnReady handler. It reads command-line arguments and they tell it to load or create a model and establish communications with VS. Because of this the event handlers in the Add-In can be called later compared to when they are called when Inventor is started normally.  </p>  <p>To avoid this behavior you can call the code that creates the ribbon in the IntentInitialized function. Here is a slightly modified version of the Add-In code. (In IntentModel.cs) This change fixed the problem in one case. (Keep in mind that the the Add-In template should be considered as a starting point). </p>  <div style="font-family: consolas; background: #eeeeee; color: black; font-size: 10pt">   <p style="margin: 0px"><span style="color: green">// This will be called if and when Intent </span></p>    <p style="margin: 0px"><span style="color: green">//gets initialized by the host.</span></p>    <p style="margin: 0px"><span style="color: blue">void</span> IntentInitialized</p>    <p style="margin: 0px">    (<span style="color: #2b91af">IntentAPI</span> intentAPI, <span style="color: blue">object</span> hostAPI)</p>    <p style="margin: 0px">{</p>    <p style="margin: 0px"> <span style="color: green">// Set up model event handlers if desired.</span></p>    <p style="margin: 0px">    <span style="color: #2b91af">IHostAPI</span> host = (<span style="color: #2b91af">IHostAPI</span>)hostAPI;</p>    <p style="margin: 0px">    <span style="color: #2b91af">ModelEvents</span> ModelEvent = </p>    <p style="margin: 0px">                    intentAPI.ModelEvents;</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    host.Events.BeforeModelLoad += </p>    <p style="margin: 0px">        <span style="color: blue">new</span> <span style="color: #2b91af">EventHandler</span>(Events_BeforeModelLoad);</p>    <p style="margin: 0px">    ModelEvent.BeforeRender += </p>    <p style="margin: 0px">        <span style="color: blue">new</span> <span style="color: #2b91af">EventHandler</span>&lt;<span style="color: #2b91af">BeforeModelRenderArgs</span>&gt;</p>    <p style="margin: 0px">                       (ModelEvent_BeforeRender);</p>    <p style="margin: 0px">    ModelEvent.AfterRender += </p>    <p style="margin: 0px">        <span style="color: blue">new</span> <span style="color: #2b91af">EventHandler</span>&lt;<span style="color: #2b91af">AfterModelRenderedArgs</span>&gt;</p>    <p style="margin: 0px">                       (ModelEvent_AfterRender);</p>    <p style="margin: 0px"> </p>    <p style="margin: 0px">    <span style="color: green">// Added to resolve problem with AddIn </span></p>    <p style="margin: 0px">    <span style="color: green">// ribbon when debugging</span></p>    <p style="margin: 0px">    <span style="color: blue">if</span> (intentAPI.Models.Count &gt; 0)</p>    <p style="margin: 0px">    {</p>    <p style="margin: 0px">        m_gui.Activate();</p>    <p style="margin: 0px">    }</p>    <p style="margin: 0px">}</p> </div>  <p> </p>  <p>2. We have found in one case that ETO Studio is adversely effected by the Visual Studio Add-In named ReSharper. Some of the symptoms are the following:</p>  <blockquote>   <p><em>Error Message when opening the ETO Studio project: “The parameter is incorrect”. </em></p> </blockquote>  <blockquote>   <p><em>Edit Rule Error - “Design for selected part not loaded in Visual Studio Environment. Please make sure the project containing the design is open” </em></p> </blockquote>  <blockquote>   <p><em>ETO Model browser sees the designs under root, but cannot open them. Clicking “Edit Design” gives the same error as above. </em></p> </blockquote>  <blockquote>   <p><em>Design Navigator shows no User Designs</em></p>    <p> </p> </blockquote>  <p>The behavior has been reported to Autodesk ETO engineering. For now the suggestion is to disable the Visual Studio Add-In.</p>  <p> </p>  <p>3. There is now an InventorApplication global Rule. Before that, you had to use hidden %%InventorApplication. Here you see the ETO Console in Visual Studio using the Inventor API:</p>  <p><a href="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017d41026dca970c-pi"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://modthemachine.typepad.com/.a/6a00e553fcbfc68834017c36d3ba4a970b-pi" width="463" height="126" /></a></p>  <p>-Wayne</p></div>
</content>



    <feedburner:origLink>http://modthemachine.typepad.com/my_weblog/2013/02/eto-2013-r2-add-in-template-vs-add-ins-can-impact-eto-studio-inventorapplication-global-rule.html</feedburner:origLink></entry>
 
</feed><!-- ph=1 -->
