Rectangular Pattern - Part - iLogic

Rectangular Pattern - Part - iLogic

jason_snyder
Enthusiast Enthusiast
1,886 Views
2 Replies
Message 1 of 3

Rectangular Pattern - Part - iLogic

jason_snyder
Enthusiast
Enthusiast

Hi All,


I'm after some code to automatically rectangular pattern a work plane along a 3D sketch at a given distance along the 3D sketch.


I have a few to do and don't want to keep clicking and entering the values into Rectangular Pattern dialog box. As typically, only the distance along the 3D sketch changes for the new work plane. Hence, all I want to input is the distance / spacing and the rest does its thing.

 

 

I have tried oPartDoc.ComponentDefinition.Features.RectangularPatternFeatures.Add() but errors out:

"Unable to cast object of type 'System.String" to type 'Inventor.ObjectCollection'."

 

I assume this is the work plane on which it errors out?


This array / rectangular pattern is being done in a part, not an assembly.

 

 

Attached is a picture explaining the tick boxes I want hardwired and the variable input I want.

 


If anyone knows how I can do this let me know.

Cheers,

Jason Snyder

0 Likes
Accepted solutions (1)
1,887 Views
2 Replies
Replies (2)
Message 2 of 3

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

 

try this, im using Inventor 2014 and VBA macro don't place this code at iLogic rule:

 

 

Public Sub PatternPlaneSketch3DR1()
Dim oPD As PartDocument
Set oPD = ThisApplication.ActiveDocument

 

Dim oPCD As PartComponentDefinition
Set oPCD = oPD.ComponentDefinition

 

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

 

Dim oBjCol As ObjectCollection
Set oBjCol = ThisApplication.TransientObjects.CreateObjectCollection

 

Call oBjCol.Add(oSWP)

 

Dim oSL3D As SketchLine3D
Set 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
Set oPath = oPCD.Features.CreatePath(oSL3D)

 

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


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


End Sub

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 3 of 3

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

 

 

Edit: whoops, wrong topic

0 Likes