Sketch - Project Flat Pattern API

Sketch - Project Flat Pattern API

Anonymous
Not applicable
792 Views
4 Replies
Message 1 of 5

Sketch - Project Flat Pattern API

Anonymous
Not applicable

Hello everyone,

 

I'm trying to write a code snippet to perform "Project Flat Pattern" for a selected edge. I tried some different approaches but failed all.

// inputs
var oEdge = _InventorApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kPartEdgeLinearFilter, "Select an edge") as Inventor.Edge;
var oSketch = _InventorApp.CommandManager.Pick(Inventor.SelectionFilterEnum.kSketchObjectFilter, "Select a sketch to do projection") as Inventor.PlanarSketch;

// result
var sheetMetalComp = (_InventorApp.ActiveDocument as PartDocument).ComponentDefinition as SheetMetalComponentDefinition; var flatEdge = sheetMetalComp.FlatPattern.GetFlatPatternEntity(oEdge); oSketch.AddByProjectingEntity(flatEdge);

2019-10-27_11-38-25.png

 

Your help will be much appreciated!

 

(*) I'm using C# but if you're familiar with VBA or VB.NET, it's okay for me. I can understand. 🙂

 

 

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

Sergio.D.Suárez
Mentor
Mentor

Hi, have you tried with the preset commands?
I'm not sure if they would work in your programming environment, which I share below is an example of VBA. On the other hand, remember that this command projects Faces no edges.

 

Sub ProjectFlat()

    Dim oCommand As CommandManager
    Set oCommand = ThisApplication.CommandManager
    
    Dim oControlDef As ControlDefinition ' Get control definition for the line command.
    Set oControlDef = oCommand.ControlDefinitions.Item("SketchProjectFlatPatternCmd")
    oControlDef.Execute2 (True) ' Execute the command.

End Sub

I hope this can help you with your problem. Regards


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

Message 3 of 5

Anonymous
Not applicable

Thank you @Sergio.D.Suárez .

However, it seems my post wasn't well-described. Let me explain a little bit.

 

Pretend I already had:

  • A sketch set to variable oSketch.
  • A bend (face) set to variable oBend.

I want oSketch to perform "Project Flat Pattern" the oBend to it. The results are the green lines as shown below.

2019-10-28_19-35-56.pngHopefully now my question is clear. 😅

 

0 Likes
Message 4 of 5

MateriaGris
Contributor
Contributor

Hi everyone.
I am interested in knowing if it is possible to do what Anonymous asks

I want to project flat pattern onto a sketch and place a point at the end of each bend edge, but I can't find a way to do it automatically from within iLogic.

I am attaching an example file showing what I am interested in doing.
I really appreciate if you can help me.

0 Likes
Message 5 of 5

SevInventor
Advocate
Advocate

Hello Anonymous 199,

 

 

found out how to project the Flat pattern edges and bend lines and bring the sketch intend to the folded model.

Got some code of a similar topic from here:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/sketch-on-flat-pattern-issue/td-p/71...

 

Only the orientation and position of the sketch in the folded model is wrong:

I'm sure this task can be solved as well. Pleas feel free to further develop this code

 

Sub Main
'[ edit these variables as needed
sSketchName = "Flat Pattern Sketch"


'  a reference to the active document.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

'verify document type is sheet metal
If oPartDoc.ComponentDefinition.Type <> 150995200 Then
	MessageBox.Show("File is not a sheet metal part.", "iLogic")
	Exit Sub
End If

Dim oCompDef As SheetMetalComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

' Check to make sure a flat pattern is open.
If Not TypeOf ThisApplication.ActiveEditObject Is FlatPattern Then
	Try
		If oCompDef.HasFlatPattern = False Then
			oCompDef.Unfold
		Else
			oCompDef.FlatPattern.Edit
		End If
	Catch
		MessageBox.Show("Error editting the flat pattern.", "iLogic")

	End Try
End If

'  a reference to the active flat pattern.
Dim oFlatPattern As FlatPattern
oFlatPattern = ThisApplication.ActiveEditObject

Dim oFace As Face
oFace = oFlatPattern.TopFace

Dim oSketch As PlanarSketch

'clean up existing sketch
For Each oSketch In oFlatPattern.Sketches
	If oSketch.Name = sSketchName Then
		oSketch.Delete
	End If
Next

' Create a new sketch.  
' the Second argument specifies To include/Not include
' the edges of the face in the sketch.
oSketch = oFlatPattern.Sketches.Add(oFace, False)

' Change the name.
oSketch.Name = sSketchName
	
Dim oEdges As Edges




	UpEdges = oFlatPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendUpFlatPatternEdge, True) 
	For Each Upedge In UpEdges
	
		Dim line As SketchLine = oSketch.AddByProjectingEntity(Upedge)

	Next
	
	
	DownEdges = oFlatPattern.GetEdgesOfType(FlatPatternEdgeTypeEnum.kBendDownFlatPatternEdge, True) 
	For Each DownEdge In DownEdges
	
		Dim line As SketchLine = oSketch.AddByProjectingEntity(DownEdges)

	Next


	For Each oEdge In oFlatPattern.TopFace.Edges

		Call oSketch.AddByProjectingEntity(oEdge)

	Next



oCompDef.FlatPattern.ExitEdit

Dim oFace2 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Surface to add flat sketch")
Dim oSketch2 As PlanarSketch
oSketch2 = oCompDef.Sketches.Add(oFace2,True)	
oSketch.CopyContentsTo(oSketch2)
oPartDoc.Save

End Sub
0 Likes