There are many examples of creating rectangular patterns, but not many, if any, of interrogating existing patterns.
I have attached the files and a screenshot of a rectangular part inside an assembly. The part contains a rectangular pattern of holes and workplanes.
My question is how do I get hold of each proxy of the workplane in the pattern?
In other words I don't know what to put in the for loop at the end of this code fragment:
If _invApp.Documents.Count = 0 Then MsgBox("Need to open an the assembly document") Return End If If _invApp.ActiveDocument.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then MsgBox("Need to have an Assembly document active") Return End If Dim asmDoc As AssemblyDocument asmDoc = _invApp.ActiveDocument Dim asmDef As AssemblyComponentDefinition asmDef = asmDoc.ComponentDefinition Dim occurrences As ComponentOccurrences occurrences = asmDef.Occurrences Dim partOcc As ComponentOccurrence ' partOcc = occurrences.ItemByName("Block-with-hole-pattern") partOcc = occurrences.Item(1) Dim pippo As PartComponentDefinition pippo = partOcc.Definition Dim features As PartFeatures features = pippo.Features Dim RecFeatures As RectangularPatternFeatures RecFeatures = features.RectangularPatternFeatures Dim RecPattern As RectangularPatternFeature RecPattern = RecFeatures.Item(1) Dim Xparam As Parameter Xparam = RecPattern.XCount Debug.Print("This pattern has " & Xparam.Value & " x elements") Dim i As Integer, j As Integer For i = 1 To Xparam.Value Debug.Print(i & " ") ' How to get hold of the proxy for the workplane in the pattern source? Next i
The fragment assumes you've opened the assembly attached.
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
Hi
it's pretty straightforward to get a better idea about how things are structured under the APi by writting some simple VBA code as follow and analyzing the live objects using the VBA debugger.
Public Sub pattern() Dim doc As PartDocument Set doc = ThisApplication.ActiveDocument Dim pattern As RectangularPatternFeature Set pattern = doc.ComponentDefinition.Features.RectangularPatternFeatures(1) End Sub
From the video I recorded below, you can deduce that the patterned workplanes are accessible from "PatternElements.Item(idx).ResultFeatures" collection.
The video is watchable here
NB: The first pattern element is empty because it is the patterned feature itself.
Regards,
Philippe.
My question was about getting the proxies of workplanes in patterns inside parts inside assemblies.
I'll do as you suggest, but some documentation would be helpful.
Inventor API Help contains the overview article on proxies:
In the following vba sample WorkPlaneProxy objects are created using ComponentOccurrence.CreateGeometryProxy(...) method.
Sub ExplorePatternInComponent() Dim oAsmDoc As AssemblyDocument Set oAsmDoc = ThisApplication.ActiveDocument Dim oAsmDef As AssemblyComponentDefinition Set oAsmDef = oAsmDoc.ComponentDefinition Dim oOccs As ComponentOccurrences Set oOccs = oAsmDef.Occurrences Dim oOcc As ComponentOccurrence Set oOcc = oOccs.ItemByName("Block-with-hole-pattern:1") Dim oDef As PartComponentDefinition Set oDef = oOcc.Definition Dim oFeatures As PartFeatures Set oFeatures = oDef.features Dim RecFeatures As RectangularPatternFeatures Set RecFeatures = oFeatures.RectangularPatternFeatures Dim RecPattern As RectangularPatternFeature Set RecPattern = RecFeatures.Item(1) Dim Nx As Integer, Ny As Integer Dim Xparam As Parameter Set Xparam = RecPattern.XCount If Not Xparam Is Nothing Then Nx = Xparam.value Else Nx = 1 End If Dim Yparam As Parameter Set Yparam = RecPattern.YCount If Not Yparam Is Nothing Then Ny = Yparam.value Else Ny = 1 End If Debug.Print ("This pattern has " & Nx & " x " & Ny & " elements") Dim oPatternElements As FeaturePatternElements Set oPatternElements = RecPattern.PatternElements Dim oElt As FeaturePatternElement Dim sset As SelectSet Set sset = oAsmDoc.SelectSet Dim i As Integer For i = 2 To Nx Set oElt = oPatternElements.Item(i) ' Debug.Print oElt.ResultFeatures.Item(1).Name 'get work plane object (assume it is the first object 'in the collection ResultFeatures) Dim oWP As WorkPlane Set oWP = oElt.ResultFeatures.Item(1) 'Debug.Print oWP.Name 'get proxy object Dim oWpProxy As WorkPlaneProxy Set oWpProxy = Nothing Call oOcc.CreateGeometryProxy(oWP, oWpProxy) 'now you can do something useful with oWpProxy Call sset.Select(oWpProxy) Next Beep End Sub
cheers
Magic, thanks! The VB worked, and it took me some time to convert to C++, but I got there in the end.
I'd understood creating proxies, but did not understand ResultFeatures...
ResultFeatures is the collection of entities that were included in the pattern operation. In your model that could be workplane + workaxis in every pattern element.