Create circular pattern in assembly

Create circular pattern in assembly

jedQB94J
Advocate Advocate
624 Views
4 Replies
Message 1 of 5

Create circular pattern in assembly

jedQB94J
Advocate
Advocate

Hi,

 

I have tried copy som code from the forum, there looks like something I need, what I need i if the "workPlane_sub_beam" are = 0 then do nothing else create an circular pattern on "Y axis" instance of 2.

 

circular.png

 

If Parameter("Skeleton", "WorkPlane_sub_beam") = 0 Then
	' do nothing
Else

Dim oCdef As ComponentDefinition
oCdef = ThisDoc.Document.ComponentDefinition

Dim objCol As ObjectCollection
objCol = ThisApplication.TransientObjects.CreateObjectCollection

'Feature to be patterned
objCol.Add(oCdef.Features("Extrusion1"))

'degrees
oDeg = 180 

'create pattern
'....CircularPatternFeatures.Add(Features in Pattern, Axis, NaturalAxisDirection, Count, Angle, FitWithinAngle)
oCdef.Features.CircularPatternFeatures.Add(objCol, oCdef.WorkAxes.Item("Z Axis"), False, 2, oDeg , True)
End If

 

Thanks,

 

0 Likes
625 Views
4 Replies
Replies (4)
Message 2 of 5

matt_jlt
Collaborator
Collaborator

The .Add method is old / not available anymore

 

there are a few posts about this in the forums, here are a few of them with more info

https://forums.autodesk.com/t5/inventor-customization/the-hole-pattern-is-not-at-uniform-length-radi...

 

https://forums.autodesk.com/t5/inventor-customization/create-circular-pattern-feature/m-p/5593847

 

 

This is working code to do what you want. It is more complicated as it is made to ensure there are no errors as it was taken from some other code i wrote.

 

' Check document is a part / a document is open
If ThisApplication.Documents.VisibleDocuments.Count = 0 Or ThisApplication.ActiveEditDocument.DocumentType <> Inventor.DocumentTypeEnum.kPartDocumentObject Then
	MessageBox.Show("A Part document must be open")
End If

' Get active part document
Dim oDoc As Inventor.PartDocument = ThisApplication.ActiveDocument
' Get part component definition
Dim oCompDef As Inventor.PartComponentDefinition = oDoc.ComponentDefinition
' Create a new object collection
Dim oColl As Inventor.ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
' Set the found flag for the feature
Dim bFound As Boolean = False

' Iterate through all features
For Each oFeature As Inventor.PartFeature In oCompDef.Features
	' Check feature name matches
	If oFeature.Name = "Extrusion1" Then
		' Add to collection & set the flag
		oColl.Add(oFeature)
		bFound = True
	End If
Next

' Feature wan't found so exit
If Not bFound Then
	MessageBox.Show("The target feature was not found")
	Exit Sub
End If

' Reset Flag
bFound = False

Dim oWA As Inventor.WorkAxis
For Each oWA In oCompDef.WorkAxes
	If oWA.Name = "Z Axis" Then
		bFound = True
		Exit For
	End If
Next ' Next axis

' Feature wan't found so exit
If Not bFound Then
	MessageBox.Show("The target axis was not found")
	Exit Sub
End If

' Set Angle
oDeg = "180 deg"

Dim oCPFDef As Inventor.CircularPatternFeatureDefinition = oCompDef.Features.CircularPatternFeatures.CreateDefinition(oColl, oWA, True, 2, oDeg, False)
Dim oCPF As Inventor.CircularPatternFeature = oCompDef.Features.CircularPatternFeatures.AddByDefinition(oCPFDef)

' Get the angle parameter and fix (due to bug) - Angle is always item 1
oCPF.Parameters.Item(1).Expression = oDeg

 

 

0 Likes
Message 3 of 5

jedQB94J
Advocate
Advocate

Hi,

 

Sorry, I got this error.

 

error.png

 

I have attach files.

0 Likes
Message 4 of 5

dutt.thakar
Collaborator
Collaborator

@jedQB94J 

 

The reason you are getting an error because you are trying to run the code provided by @matt_jlt in an assembly document, the code is only applicable for the part document.

 

Another thing, I have seen in the snapshot you have provided in the question is that you are trying to pattern a feature named "Extrusion1" using code, but it is not inside the assembly, can you please be more specific? whether you are trying to pattern a feature that is inside a part file? or you already have a feature created inside the assembly and you want to pattern it?  Or you want to pattern any part located in the assembly?

 

Please try to explain and you will get more elaborative help here.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
0 Likes
Message 5 of 5

jedQB94J
Advocate
Advocate

Hi @dutt.thakar,

 

What i want is search  in the explore tree for parts in assembly, then create a circular pattern around "Y-axis" instance of 2 in 180 deg.

 

circular pattern.PNG

 

The "Skeleton" part should not be patterned.

 

Thanks,

0 Likes