I have to add flat patterns to sheet metal parts that don't have any. Now, the API specifies that the part is flattened on the XY plane. And when you do this through SE's interface, this indeed happens. But when I do it through the API function, it seems to be flattened on the plane where the selected base face is. My problem is that I need it to be always on the XY plane (as it should) because otherwise the code that I have later will get really complicated. (I didn't have this problem before because I used to just copy the part as flattened. This always place the part on XY but has other problems, like bend line information not passing)
This is the function definition from the API help:FlatPatterns
Object.Add(ReferenceEdge, ReferenceFace, ReferenceVertex, ModelType)Elements
Object - Required. The object to which the method applies.
ReferenceEdge - Required Object (input). Specifies a reference edge for the flatten process, aligning the edge with the y-axis of the base reference plane. The part is flattened on the xy plane. If ReferenceFace is specified, then ReferenceEdge must be part of the specified face.
ReferenceFace - Optional Object (input). Specifies a reference face for the flatten process. If ReferenceFace is specified, then ReferenceVertex must also be specified.
ReferenceVertex - Optional Object (input). Specifies a reference vertex for the flatten process. ReferenceVertex must be part of ReferenceEdge. If ReferenceVertex is specified, then ReferenceFace must also be specified.
ModelType - Optional (input). A member of the FlattenPatternModelTypeConstants constant set that specifies the model type.
And this is the portion of the code that I use to add the flattening. I trimmed it so it just needs to be run straight. Basically I just look for the biggest face, and inside of it for the largest edge, and use them as the base for the flat pattern. The only requirement is that a sheet metal part with no flat pattern is opened. I'm attaching 2 examples, one that works and one that doesn't:
Dim objApp As Object, objDoc As Object
Dim objFlatModel As SolidEdgePart.FlatPatternModel
Dim objFlatPat As SolidEdgePart.FlatPattern
Dim objDesignModel As SolidEdgePart.Model
On Error Resume Next
Set objApp = GetObject(, "SolidEdge.Application")
If (objApp Is Nothing) Then ' If Err Then
Set objApp = CreateObject("SolidEdge.Application")
Set objDoc = objApp.ActiveDocument
Set objDesignModel = objDoc.Models.Item(1)
Dim objFace As Object, objFaces As Object
Dim objLargestFace As Object
Dim dLargest As Double
' Find Largest face
Set objFaces = objDesignModel.Body.Faces(FaceType:=igQueryPlane)
For Each objFace In objFaces
If objFace.Area > dLargest Then
Set objLargestFace = objFace
dLargest = objFace.Area
Dim objFEdge As Object, objFLargestEdge As Object
Dim objFEdges As Object
Dim minParam As Double, maxParam As Double, Length As Double
' Find largest edge in largest face
Set objFEdges = objLargestFace.Edges
For Each objFEdge In objFEdges
Call objFEdge.GetParamExtents(minParam:=minParam, maxParam:=maxParam)
Call objFEdge.GetLengthAtParam(FromParam:=minParam, ToParam:=maxParam, Length:=Length)
If objFEdge.Geometry.Type = igLine And Length > dLargest Then
Set objFLargestEdge = objFEdge
dLargest = Length
' Add flat pattern model
' Add the flat pattern itself
Set objFlatPat = objDoc.FlatPatternModels(1).FlatPatterns.Add(ReferenceEdge:=objFLargestEdge, _
ReferenceFace:=objLargestFace, ReferenceVertex:=objFLargestEdge.EndVertex, _
Thanks to anyone that can help me!
Posted by: Elias Cohenca
Post date: 4/1/2009 12:04:43 AM
I hate to be the bearer of bad news, but the flat pattern API is a real mess. I have just spent a long time developing a workaround for this problem (I needed the cut sizes - which are also wrong if you don't have the flat pattern lying on the correct plane). My first piece of advise would be to drop the whole thing - but that's probably not an option.
I can tell you how I got around it, but I can't give you any code as it was done for a work contract.
Firstly, I made sure that I only use faces whose normals are either in the x, y or z direction (otherwise you may get a flat pattern that lies diagonally wrt the main axis)
Secondly I only used edges along the main axis (this was only really to get the correct cut length)
I also skipped any faces with edges that are the same as the cut length (Solid Edge will flatten using a side face if you pass it to the method)
I then added an attached property table to the edge and face I used (you must update the model after this so that the attached property tables appear in the flattened model.
Finally I checked the orientation of the face and edge in the attached property tables wrt the main axis and if it was incorrect the I deleted and informed the user.
These are only the main steps - the process may need some refining.
I used this on approx. 4500 psm files and had 218 failures.
Hope this helps
Posted by: Calum McLellan
Post date: 4/1/2009 1:53:02 AM
Wow! That seems like a.. lot of work
I think I'll try other ways first, like maybe combining the part copy with adding a flat pattern. Did you ever try contacting their support line? I wrote them about this but so far didn't get a useful response, only the standard "send more data". It seems very odd that doing the same thing manually (even selecting the same face and edge) produces a correct result; why would the API behave differently? I work on a program that also has API available, and we don't have this kind of problems.
Thanks for your input, though. Very appreciated.
Posted by: Elias Cohenca
Post date: 4/1/2009 2:07:25 AM
The flatpatternModels item collection is also empty until entering the flatten environment.
Requires programming objApp.StartCommand(45066) before adding a FlatPatternModel.FlatPatterns feature.
kind regards marthijn