Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Access consumed body of a rectangular pattern feature

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
andy
576 Views, 4 Replies

Access consumed body of a rectangular pattern feature

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

4 REPLIES 4
Message 2 of 5
J-Camper
in reply to: andy

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.

Message 3 of 5
andy
in reply to: J-Camper

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")

 

Message 4 of 5
J-Camper
in reply to: andy

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

Message 5 of 5
andy
in reply to: J-Camper

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

 

anyway, thanks for the solution. 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report