Access consumed body of a rectangular pattern feature

andy
Explorer
Explorer

Access consumed body of a rectangular pattern feature

andy
Explorer
Explorer

Hello,

 

Is there a way to access the source body that was used to create a rectangular pattern feature (pattern solids)  trough vba?

 

Kind regards,

 

Andy

0 Likes
Reply
Accepted solutions (1)
578 Views
4 Replies
Replies (4)

J-Camper
Advisor
Advisor

If you find the RectangularPatternFeature in your Part Features, use the "Definition" property to access the RectangularPatternFeatureDefinition where you can find "AffectedBodies" property that gives an ObjectCollection of all affected bodies. 

 

Links direct you to the online Inventor Help pages for more documentation.

0 Likes

andy
Explorer
Explorer

AffectedBodies gives a collection of the result.

I would like to get the source body of the feature if possible.

(see screenshot in attachment - result must be body "dr_ts_03")

 

0 Likes

J-Camper
Advisor
Advisor
Accepted solution

Okay, try this then:

Sub Main
	'Verify rule is running in a part file. Not necessary, if stored local to Part File
	If ThisDoc.Document.DocumentType <> kPartDocumentObject
		Exit Sub
	End If
	
	'Declare main variables
	Dim oDoc As PartDocument = ThisDoc.Document
	Dim oCD As PartComponentDefinition = oDoc.ComponentDefinition
	Dim BrowserPane As BrowserPane = oDoc.BrowserPanes.Item("Model")
	Dim oName As String

	'Determine subtype of Part Document to know correct Browser GUID
		'Sheet metal: "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
		'Part: "{4D29B490-49B2-11D0-93C3-7E0706000000}"
	If oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" 'Sheet Metal Part
		For Each oNodeA As BrowserNode In BrowserPane.TopNode.BrowserNodes(1).BrowserNodes(3).BrowserNodes
			For Each oNodeB As BrowserNode In oNodeA.BrowserNodes		
				If InStr(oNodeB.BrowserNodeDefinition.Label, "Pattern of") <> 0 Then
					oName = oNodeB.BrowserNodeDefinition.Label
					oName = Right(oName, Len(oName) -11)
					oName = oName.Remove(oName.IndexOf(":")) 
					MessageBox.Show("Parent solid name for " & oNodeA.BrowserNodeDefinition.Label & " is: " & oName, "Parent Solid Found")
				End If
			Next
		Next
	Else 'Assumed to be normal part because earlier test
		For Each oNodeA As BrowserNode In BrowserPane.TopNode.BrowserNodes(2).BrowserNodes
			For Each oNodeB As BrowserNode In oNodeA.BrowserNodes
				If InStr(oNodeB.BrowserNodeDefinition.Label, "Pattern of") <> 0 Then
					oName = oNodeB.BrowserNodeDefinition.Label
					oName = Right(oName, Len(oName) -11)
					oName = oName.Remove(oName.IndexOf(":")) 
					MessageBox.Show("Parent solid name for " & oNodeA.BrowserNodeDefinition.Label & " is: " & oName, "Parent Solid Found")
				End If
			Next
		Next
	End If
End Sub

It's a truncated piece of Pattern solid renaming code I used as an external rule, so some terminology may need to be added to get it to function as a VBA macro.  It looks at solid bodies through the Browser Pane to determine their source body created from any kind of Pattern, and then renamed the solid based on the Parent name.  If you would like the renaming portion I can post more but it looks like you have renaming done already.  "oName" will be the name of your parent solid and you can set a SurfaceBody Object by checking for that name in "SurfaceBodies" if you need the parent as a SurfaceBody Object

0 Likes

andy
Explorer
Explorer

I find it a bit strange that there is no shorter method to achieve this

 

anyway, thanks for the solution. 

 

 

 

0 Likes