Create sheetmetal face with multiple flanges

Create sheetmetal face with multiple flanges

Cadkunde.nl
Collaborator Collaborator
423 Views
3 Replies
Message 1 of 4

Create sheetmetal face with multiple flanges

Cadkunde.nl
Collaborator
Collaborator

Hello,

 

Attached I got a part (inventor 2020) with an ilogic rule.

The part is like a skeleton model, and the script creates a new part with the skeleton derived in.

The user gets a prompt to select a face.

 

The script then has to make a sheetmetal face and flanges on the edges.

 

The script crashes when trying to make the second flange.

 

It works when i select all edges and then make 1 flange.

But I want to make 1 flange per edge, so that I can later add an angle to each.

 

I am clueless why the script crashes on making the 2nd flange.

Any help is greatly appreciated.

0 Likes
Accepted solutions (2)
424 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

The problem here is that you want to use the topFace multiple times. After the first time you add a flange, the face (and edges) stop existing. It will be transformed into a new face. (at best it will look like the old face but smaller because of the radius of the flange.) Therefore you can't use that face any more. you need to select the new face or one of the new edges.

in the example below you can select the edges manually so you can see it can work.

 

 

Dim oApp As Inventor.Application = ThisApplication

Dim oDoc As PartDocument = ThisDoc.Document

Dim templateFilePath = "C:\Users\Public\Documents\Autodesk\Inventor 2023\Templates\en-US\Sheet Metal.ipt" ' ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject)
Dim template As PartDocument = oApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, templateFilePath, True)

Dim oDerivedPartDef As DerivedPartUniformScaleDef = template.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(oDoc.FullFileName)
template.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPartDef)

oApp.CommandManager.ControlDefinitions.Item("AppViewCubeHomeCmd").Execute()
oApp.ActiveView.Fit()

Dim oFace As Face = oApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select face")

If (oFace.SurfaceType <> SurfaceTypeEnum.kPlaneSurface) Then Exit Sub


Dim oSketch As Inventor.PlanarSketch = template.ComponentDefinition.Sketches.Add(oFace)
oSketch.Edit()
Dim oEdgeLoop As Inventor.EdgeLoop = oFace.EdgeLoops(1)

For Each oEdge As Inventor.Edge In oEdgeLoop.Edges
	oSketch.AddByProjectingEntity(oEdge)
Next

oSketch.ExitEdit()

Dim oProfile As Profile = oSketch.Profiles.AddForSolid() ', Profile
Dim cd As SheetMetalComponentDefinition = template.ComponentDefinition
Dim oSMF As SheetMetalFeatures = cd.Features
Dim oFFD As FaceFeatureDefinition = oSMF.FaceFeatures.CreateFaceFeatureDefinition(oProfile)

Dim oFF As FaceFeature = oSMF.FaceFeatures.Add(oFFD)

Do
	Dim edge = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartEdgeLinearFilter, "Select edge")
	If (edge Is Nothing) Then Exit Do
	Dim edgeSet As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection
	edgeSet.Add(edge)

	Dim flangeDef As FlangeDefinition = oSMF.FlangeFeatures.CreateFlangeDefinition(edgeSet, "90", 5)
	oSMF.FlangeFeatures.Add(flangeDef)
Loop

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 4

A.Acheson
Mentor
Mentor
Accepted solution

Just once change needed. It seems that the edges selected from the solid body will be modified by the added flange and therefore won't existing to add to the edgeset. If you take the edge collection directly from the face selected this will be solved. 

Dim topFace As Face = oFF.Faces.Item(6)  

 

AAcheson_0-1676931132341.png

 

Update Rule:

Dim oApp As Inventor.Application = ThisApplication

Dim oDoc As PartDocument = ThisDoc.Document

Dim oPartDoc As PartDocument
oPartDoc = oApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, "C:\Templates\Sheet Metal.ipt", True) 'ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject)

Dim oDerivedPartDef As DerivedPartUniformScaleDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.CreateUniformScaleDef(oDoc.FullFileName)
oPartDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Add(oDerivedPartDef)

oApp.CommandManager.ControlDefinitions.Item("AppViewCubeHomeCmd").Execute()
oApp.ActiveView.Fit()

Dim oFace As Face = oApp.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select face")

If Not oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then Exit Sub

oPlanarSurface = oFace.Geometry
Dim oSketch As Inventor.PlanarSketch = oPartDoc.ComponentDefinition.Sketches.Add(oFace)
oSketch.Edit
Dim oEdgeLoop As Inventor.EdgeLoop = oFace.EdgeLoops(1)

For Each oEdge As Inventor.Edge In oEdgeLoop.Edges
	oSketch.AddByProjectingEntity(oEdge)
Next

oSketch.ExitEdit

Dim oProfile As Profile = oSketch.Profiles.AddForSolid(), Profile
Dim cd As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
Dim oSMF As SheetMetalFeatures = cd.Features
Dim oFFD As FaceFeatureDefinition = oSMF.FaceFeatures.CreateFaceFeatureDefinition(oProfile)

Dim oFF As FaceFeature = oSMF.FaceFeatures.Add(oFFD)
Dim tg As TransientGeometry = ThisApplication.TransientGeometry
Dim topFace As Face = oFF.Faces.Item(6)'cd.SurfaceBodies.Item(1).Faces.Item(6)

Dim edgeSet As EdgeCollection = ThisApplication.TransientObjects.CreateEdgeCollection

Dim flangeDef As FlangeDefinition


Dim i As Integer
For Each oEdge In topFace.Edges
	edgeSet.Clear
	flangeDef = oSMF.FlangeFeatures.CreateFlangeDefinition(edgeSet, "90", 5)
	edgeSet.Add(oEdge)
	oSMF.FlangeFeatures.Add(flangeDef)	
Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 4 of 4

Cadkunde.nl
Collaborator
Collaborator

thanks guys, much appreciated.

This did the trick:

Dim topFace As Face = oFF.Faces.Item(6)  

But I'll add both as solution. The explanation is clear.

0 Likes