Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic to Create Rectangular Pattern Of Part Feature

felix.cortes5K3Y2
Advocate

iLogic to Create Rectangular Pattern Of Part Feature

felix.cortes5K3Y2
Advocate
Advocate

Hi Forum,

 

I am trying to write a code to create the a rectangular feature pattern and was wondering if someone could help me out. Here's what I have right now:

 

Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition

Dim oRectDef As RectangularPatternFeatureDefinition = oCompDef.Features.RectangularPatternFeatures.CreateDefinition("TOP", "X-Axis", _
														True, 2, 10)
Dim oPartFeature As PartFeature = oCompDef.Features.RectangularPatternFeatures.AddByDefinition(oRectDef)

 

Best regards,

Felix

0 Likes
Reply
Accepted solutions (1)
2,057 Views
4 Replies
Replies (4)

Curtis_Waguespack
Consultant
Consultant

Hi @felix.cortes5K3Y2 .

 

Attached is an example part file ( saved in Inventor 2017 ) for you to look at.

 

I just adapted the code/file found at this link for this example.

https://forums.autodesk.com/t5/inventor-customization/rectangular-pattern-part-ilogic/m-p/7599859#M7...

 

Below is the code found in the file in cases it helps future searches.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'try to delete previous pattern, just for testing
Try
ThisApplication.ActiveDocument.ComponentDefinition.Features("TestPattern").delete
Catch
End Try

Dim oPD As PartDocument
oPD = ThisApplication.ActiveDocument

Dim oPCD As PartComponentDefinition
oPCD = oPD.ComponentDefinition

Dim oSWP As WorkPlane
oSWP = oPCD.WorkPlanes.Item(4)

Dim oBjCol As ObjectCollection
oBjCol = ThisApplication.TransientObjects.CreateObjectCollection

Call oBjCol.Add(oSWP)

Dim oSL3D As SketchLine3D
oSL3D = oPCD.Sketches3D.Item(1).SketchLines3D.Item(1)

Dim qtypattern As Integer
qtypattern = InputBox("How many to Pattern?", "Quantity of Pattern")


Dim oPath As Object
oPath = oPCD.Features.CreatePath(oSL3D)

Dim oRecFeat As RectangularPatternFeature
DistPrompt1 = InputBox("Input Distance of Pattern in cm?", "Distance of Pattern")

oRecFeat = oPCD.Features.RectangularPatternFeatures.Add(oBjCol, oPath, True, qtypattern, DistPrompt1, PatternSpacingTypeEnum.kDefault)

'rename pattern
oRecFeat.Name = "TestPattern"

felix.cortes5K3Y2
Advocate
Advocate

Thanks for the link! It doesn't work for my application but I think the code provided below is pretty darn close to being able to create it. I tried classifying the sweep that exists on my part as a object collection but it doesn't seem to work on the last line of code. 

 

Dim oPartDoc As PartDocument = ThisDoc.Document
Dim oPartComp As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oSweep As SweepFeature = oPartComp.Features.SweepFeatures.Item(2)
Dim oBjCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Call oBjCol.Add(oSweep)
Dim oAxis As WorkAxis = oPartComp.WorkAxes.Item(1)
oRectFeat = oPartComp.Features.RectangularPatternFeatures.Add(oBjCol, oAxis, True, 3, 10, PatternSpacingTypeEnum.kDefault)

 

Best regards,

Felix Cortes

0 Likes

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, try this code. I think you can put the name of the operation instead of the item number, try it and then tell us. I hope the code is useful for you. regards

 

Dim oPD As PartDocument = ThisDoc.Document
Dim oPCD As PartComponentDefinition = oPD.ComponentDefinition
Dim Xaxis As Object = oPCD.WorkAxes.Item(1)' Select X Axis

Dim oTop As PartFeature = oPCD.Features.Item(1) ' Select Feature form item number 

Dim oBjCol As ObjectCollection
oBjCol = ThisApplication.TransientObjects.CreateObjectCollection
	Call oBjCol.Add(oTop)

oRecFeat = oPCD.Features.RectangularPatternFeatures.Add(oBjCol,Xaxis,True, 5, 1, kDefault, , , , , , , , kAdjustToModelCompute, kAdjustToDirection1)

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

felix.cortes5K3Y2
Advocate
Advocate

Thanks a ton Sergio! Works great

0 Likes