<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I make a hole through multiple solid bodies with VBA? in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9321523#M105882</link>
    <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN class=""&gt;Thank you for your answer.&lt;/SPAN&gt; &lt;SPAN class=""&gt;You are the only one who answered me.&lt;/SPAN&gt; &lt;SPAN&gt;I really appreciate your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;I tried several times but the code doesn't work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;I get the following error message:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Error in rule: Rule4, in document: DerivedPart.ipt

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.ObjectCollection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6939FFDD-BA10-11D2-B779-0060B0F159EF}' failed due to the following error: &lt;SPAN class=""&gt;Interface not supported&lt;/SPAN&gt; (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;Working with inventor vba is frustrating.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For me, the documentation is extremely thin.&lt;/SPAN&gt; &lt;SPAN&gt;It seems that I can't close the gaps between the sparse comments.&lt;/SPAN&gt; &lt;SPAN&gt;Sometimes the forum saves me.&lt;/SPAN&gt; &lt;SPAN&gt;Here I sometimes get hints that help me.&lt;/SPAN&gt; &lt;SPAN&gt;But all in all, it's not enough.&lt;/SPAN&gt; &lt;SPAN&gt;i don't get it baked.&lt;/SPAN&gt; &lt;SPAN&gt;Too bad that there is no usable documentation with which one can learn vba well.&lt;/SPAN&gt; &lt;SPAN&gt;I spend far too much time looking for useful examples and explanations.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Does anyone have any suggestions or ideas on how to learn vba comfortable?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 16 Feb 2020 19:32:47 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-02-16T19:32:47Z</dc:date>
    <item>
      <title>How can I make a hole through multiple solid bodies with VBA?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9300687#M105727</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the code below, I tried to make a hole through a feature and a derived component. The hole only ever goes through a solid.&lt;BR /&gt;Is there someone who has a snippet of code for me with which you can make a hole through several solid bodies?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub X()

Dim oCD As PartComponentDefinition
Set oCD = ThisApplication.ActiveDocument.ComponentDefinition

Dim oSketch As PlanarSketch
oSketch = oCD.Sketches.Item(2)

Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid

Dim oED As ExtrudeDefinition
Set oED = oCD.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
Call oED.SetDistanceExtent("1000 mm", kNegativeExtentDirection)

Dim oExtrude As ExtrudeFeature
Set oExtrude = oCD.Features.ExtrudeFeatures.Add(oED)

End Sub&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="holeThroughMultipleBodies.png" style="width: 639px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/726545i4A44CF1272246D5F/image-size/large?v=v2&amp;amp;px=999" role="button" title="holeThroughMultipleBodies.png" alt="holeThroughMultipleBodies.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 12:08:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9300687#M105727</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-06T12:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I make a hole through multiple solid bodies with VBA?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9313966#M105732</link>
      <description>&lt;P&gt;Add this additional line.&lt;/P&gt;&lt;PRE&gt;Sub X()

Dim oCD As PartComponentDefinition
Set oCD = ThisApplication.ActiveDocument.ComponentDefinition

Dim oSketch As PlanarSketch
Set oSketch = oCD.Sketches.Item(2)

Dim oProfile As Profile
Set oProfile = oSketch.Profiles.AddForSolid

Dim oED As ExtrudeDefinition
Set oED = oCD.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
Call oED.SetDistanceExtent("1000 mm", kNegativeExtentDirection)

Dim oExtrude As ExtrudeFeature
Set oExtrude = oCD.Features.ExtrudeFeatures.Add(oED)

&lt;FONT color="#FF0000"&gt;oExtrude.SetAffectedBodies(oCD.SurfaceBodies)&lt;/FONT&gt;

End Sub&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Feb 2020 19:53:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9313966#M105732</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2020-02-12T19:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can I make a hole through multiple solid bodies with VBA?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9321523#M105882</link>
      <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN class=""&gt;Thank you for your answer.&lt;/SPAN&gt; &lt;SPAN class=""&gt;You are the only one who answered me.&lt;/SPAN&gt; &lt;SPAN&gt;I really appreciate your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;I tried several times but the code doesn't work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;I get the following error message:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Error in rule: Rule4, in document: DerivedPart.ipt

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.ObjectCollection'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6939FFDD-BA10-11D2-B779-0060B0F159EF}' failed due to the following error: &lt;SPAN class=""&gt;Interface not supported&lt;/SPAN&gt; (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;Working with inventor vba is frustrating.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For me, the documentation is extremely thin.&lt;/SPAN&gt; &lt;SPAN&gt;It seems that I can't close the gaps between the sparse comments.&lt;/SPAN&gt; &lt;SPAN&gt;Sometimes the forum saves me.&lt;/SPAN&gt; &lt;SPAN&gt;Here I sometimes get hints that help me.&lt;/SPAN&gt; &lt;SPAN&gt;But all in all, it's not enough.&lt;/SPAN&gt; &lt;SPAN&gt;i don't get it baked.&lt;/SPAN&gt; &lt;SPAN&gt;Too bad that there is no usable documentation with which one can learn vba well.&lt;/SPAN&gt; &lt;SPAN&gt;I spend far too much time looking for useful examples and explanations.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Does anyone have any suggestions or ideas on how to learn vba comfortable?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 19:32:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9321523#M105882</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-16T19:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: How can I make a hole through multiple solid bodies with VBA?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9321649#M105885</link>
      <description>&lt;P&gt;Hi, this is what I was using for something similar. This was for iLogic not VBA. In this case the extrusions are already created - I just wanted to make sure they cut through every solid. It does require all cut extrusions to come after new solids in the tree I think (otherwise it is adding bodies to the collection that don't exist when the subtraction is taking place). A try/catch operation would probably fix that... I also planned to add revolves in there but haven't had time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'This rule compiles all the solids created by extrusions and commands all cuts to cut through all solids
'This is required where you have an unknown amount of solids to cut through (i.e. tank strakes)
Dim oDoc As PartDocument
oDoc = ThisDoc.Document
Dim oPartDef As ComponentDefinition
oPartDef = oDoc.ComponentDefinition

'create a collection to hold the solids to act on
Dim oExtrusion As ExtrudeFeature 
Dim NewBodyObjCol As ObjectCollection
NewBodyObjCol = ThisApplication.TransientObjects.CreateObjectCollection

'Iterate through each extrudefeature in part, establish if its a cut and then set to the list of all bodies
For Each oExtrusion In oPartDef.Features.ExtrudeFeatures
	'If an extrusion creates a new solid then add the solid it creates to a collection
	If oExtrusion.Definition.Operation = kNewBodyOperation Then
		NewBodyObjCol.Add(oExtrusion.Definition.AffectedBodies.Item(1))
			'Alternatively if the extrusion is a cut then use the collection created above to cut through everything
	Else If oExtrusion.Definition.Operation = kCutOperation Then
		oExtrusion.SetAffectedBodies(NewBodyObjCol)
	End If
Next oExtrusion


	&lt;/PRE&gt;&lt;P&gt;Cheers, Glenn&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 22:38:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9321649#M105885</guid>
      <dc:creator>gcoombridge</dc:creator>
      <dc:date>2020-02-16T22:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: How can I make a hole through multiple solid bodies with VBA?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9322925#M105912</link>
      <description>&lt;P&gt;Hello&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have adapted the code of my two previous ones&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4047630"&gt;@gcoombridge&lt;/a&gt;&amp;nbsp;and created this code snippet (VBA).&lt;/P&gt;&lt;PRE&gt;Sub Hole_throuh_all_Bodies()
    Dim oCD As PartComponentDefinition
    Set oCD = ThisApplication.ActiveDocument.ComponentDefinition
    Dim oSketch As PlanarSketch
    Set oSketch = oCD.Sketches.Item("Skizze4")
    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid
    Dim oED As ExtrudeDefinition
    Set oED = oCD.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, kCutOperation)
    Call oED.SetDistanceExtent("1000 mm", kNegativeExtentDirection)
    Dim oExtrude As ExtrudeFeature
    Set oExtrude = oCD.Features.ExtrudeFeatures.add(oED)
    Dim objCol1 As ObjectCollection
    Set objCol1 = ThisApplication.TransientObjects.CreateObjectCollection
    For Each oExtrude In oCD.Features.ExtrudeFeatures
        If oExtrude.Definition.Operation = kNewBodyOperation Then
            objCol1.add (oExtrude.Definition.AffectedBodies.Item(1))
        ElseIf oExtrude.Definition.Operation = kCutOperation Then
            oExtrude.SetAffectedBodies objCol1
        End If
    Next oExtrude
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my part bevor running the macro:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2020-02-17 14_31_53-Window.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/730708i67C9941578B7115F/image-size/large?v=v2&amp;amp;px=999" role="button" title="2020-02-17 14_31_53-Window.png" alt="2020-02-17 14_31_53-Window.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and after macro:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2020-02-17 14_32_13-Window.png" style="width: 999px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/730709iBA60757F6349C7C7/image-size/large?v=v2&amp;amp;px=999" role="button" title="2020-02-17 14_32_13-Window.png" alt="2020-02-17 14_32_13-Window.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it helps you. Maybe you can adapt it to your needs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Aleks&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 13:36:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9322925#M105912</guid>
      <dc:creator>fullevent</dc:creator>
      <dc:date>2020-02-17T13:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I make a hole through multiple solid bodies with VBA?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9323032#M105913</link>
      <description>&lt;P&gt;OK. I opened your part, got an error, because it couldn't find the linked original version of the derived part, but I just skipped that. I used the Module1 of for that document to insert and modify your code untill I got it to work. Try this VBA code.&lt;/P&gt;&lt;PRE&gt;Sub CreateExtrudeFeat()

    Dim oPDoc As PartDocument
    Set oPDoc = ThisApplication.ActiveDocument
    
    Dim oPDef As PartComponentDefinition
    Set oPDef = oPDoc.ComponentDefinition
    
    Dim oSketch As PlanarSketch
    Set oSketch = oPDef.Sketches.Item(2)
    
    Dim oProfile As Profile
    Set oProfile = oSketch.Profiles.AddForSolid
    
    Dim oExtFeats As ExtrudeFeatures
    Set oExtFeats = oPDef.Features.ExtrudeFeatures
    
    Dim oExtDef As ExtrudeDefinition
    Set oExtDef = oExtFeats.CreateExtrudeDefinition(oProfile, kCutOperation)
    Call oExtDef.SetDistanceExtent("1000 mm", kNegativeExtentDirection)
    
    Dim oExtFeat As ExtrudeFeature
    Set oExtFeat = oExtFeats.Add(oExtDef)
    
    If oPDef.HasMultipleSolidBodies = True Then
        Call AddAffectedBodies(oPDef, oExtFeat)
    End If

End Sub

Private Sub AddAffectedBodies(oPDef As PartComponentDefinition, oExtFeat As ExtrudeFeature)

    Dim oBodies As ObjectCollection
    
    For Each oBody In oPDef.SurfaceBodies
        oBodies.Add (oBody)
    Next
    
    Call oExtFeat.SetAffectedBodies(oBodies)
    
End Sub&lt;/PRE&gt;&lt;P&gt;Let me know if this works for you.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 14:25:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9323032#M105913</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2020-02-17T14:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: How can I make a hole through multiple solid bodies with VBA?</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9324425#M105966</link>
      <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;Hi there&lt;/SPAN&gt;,&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;the first time that I get two good answers.&lt;/SPAN&gt; &lt;SPAN class=""&gt;Thank you for your efforts.&lt;/SPAN&gt; &lt;SPAN class=""&gt;This code is like good music and it works very well.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 06:27:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/how-can-i-make-a-hole-through-multiple-solid-bodies-with-vba/m-p/9324425#M105966</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-18T06:27:30Z</dc:date>
    </item>
  </channel>
</rss>

