Hello Lubomir,
First thanks for getting back to me.
I can confirm it does not always default to the longest side in Inventor 2017, I have for instance a drawing I select A-Side but it will choose some short edge along another face not even on the A-Side. Almost like selecting the A-Side does not effect the default alignment axis.
I know I can enter the Edit Flat Pattern Definitions and select a new side to use for alignment axis and I can get this to work as expected.
The thing is how do I do this via code only. The task I have is to fully automate this process. I have the engineers accepting the fact they have to first assign the A-Side to get the Flat Pattern in the correct orientation when creating the flat pattern. They have a grain arrow embross and the arrow has to be in the correct orientation when the flat pattern is created and unfolded ie arrow is left to right the arrow must be left to right in unfolded part as well. This way when the part is pulled into a drawing it is correct orientation without having to rotate the view cube angle in the drawing while pulling in the flat pattern part.
The task I can't figure out is how to set the correct alignment axis to a specific edge, apply the AlignmentType, Flip on the Alignment axis, and flip on the Base Face if needed, not sure what is all needed but should be similar for all parts or have a detectable way to get the end orientation correct for a final output. By final output the initial flat pattern saved is not the flat pattern needed as end result with my code which is used for machining. I need to flip the pattern and rotate accordingly, ie left to right arrow is flipped version so it is now left to right with the part flipped and the arrow is now on the back side of the flat pattern part or if arrow is up the same flip has to be performed but in the drawing need to apply a 90deg rotation, I tried to do the 90 deg rotation in the flat pattern but figured just as easy to do that in the final drawing.
I need the part that gets pulled into the drawing in correct format first however, so lets focus on nothing to do with rotation for now. Just the flipping of the flat pattern via code so it works on all parts correctly.
I have tried many methods all to fail.
I figure I will need to detect the edge I want to use as an axis so I have written this code to find correct edge on A-Side:
SheetMetalComponentDefinition ShtMtlCompDef = PRTDoc.ComponentDefinition as SheetMetalComponentDefinition;
ShtMtlCompDef.FlatPattern.Edit();
Edge ShtMtlEdge = null;
double rightmostx = double.MinValue;
foreach (Edge tmpShtMtlEdge in ShtMtlCompDef.FlatPattern.ASideFace.ASideFace.Edges)
{
if (tmpShtMtlEdge.StartVertex.Point.X > rightmostx)
{
rightmostx = tmpShtMtlEdge.StartVertex.Point.X;
ShtMtlEdge = tmpShtMtlEdge;
}
}
via debugging statements I do confirm this represents the right most vertical edge on the A-Side.
ShtMtlEdge using debugging does now contain an edge with the correct parameters I expect
This next part I have done so many ways I will just list my latest attempts
AlignmentTypeEnum aligntype = AlignmentTypeEnum.kHorizontalAlignment;
object alignto = null;
bool aligndir = false;
ShtMtlCompDef.FlatPattern.GetAlignment(out aligntype, out alignto, out aligndir);
alignto = ShtMtlEdge;
aligntype = AlignmentTypeEnum.kVerticalAlignment;
ShtMtlCompDef.FlatPattern.SetAlignment(aligntype, alignto, aligndir);
This does not flip the part, it seems to just set the alignment edge, I have no idea how to confirm what this actually does. BTW this is a hidden api method, I found this online, it does not resolve via intellisense in visual studio until after I have everything completely defined. Afterwards intellisense works and see the method definition.
ShtMtlCompDef.FlatPattern.FlipBaseFace();
Now when this happens it does not flip correctly, as if the BaseFace is not the same face and A-Side Face or something. So not sure what is happening here but it appears to flip on the default axis instead of the one I tried to assign.
ShtMtlCompDef.FlatPattern.ExitEdit();
Another method to do that last part is using the FlatPatternOrientation object.
FlatPatternOrientation FltPatOrient = ShtMtlCompDef.FlatPattern.FlatPatternOrientations.ActiveFlatPatternOrientation;
FltPatOrient.AlignmentAxis = ShtMtlEdge;
FltPatOrient.FlipAlignmentAxis = false;
FltPatOrient.AlignmentType = AlignmentTypeEnum.kVerticalAlignment;
FltPatOrient.FlipBaseFace = true;
FltPatOrient.Activate();
ShtMtlCompDef.FlatPattern.ExitEdit();
This sometimes works on some files but not all of them if I switch some stuff to other settings I can get it to work on those other files but not on the original ones etc. There is nothing for me to key off of on what to do in the FlatPatternOrientation object to figure out how to handle the orientation correctly. Again it almost seems the Edge is not selected correctly.
I have tried to select the edge as below to no solution either
PRTDoc.SelectSet.Select(ShtMtlEdge);
FltPatOrient.AlignmentAxis = m_InventorApp.ActiveDocument.SelectSet[1];
If anyone has any idea how to common-ize these tasks so they work on all flat patterns that would be great. As I said engineers have the A-Side set so when the flat pattern is generated it is in the correct front orientation with grain arrow correctly displayed on the front to start with. I need an end result of the flip so it is same orientation but back side is now the front side. The problem I believe is that edge definition is incorrect and I do not know how to get it set correctly to do a vertical flip on the right most vertical edge, it seems I can choose any right most edge on any face actually as long as I do not do FlipAlignmentAxis.
Also I have tried to use the right most edge of the Base face via the following code
double rightmostx = double.MinValue;
foreach (Edge tmpShtMtlEdge in ShtMtlCompDef.FlatPattern.BaseFace.Edges)
{
if (tmpShtMtlEdge.StartVertex.Point.X > rightmostx)
{
rightmostx = tmpShtMtlEdge.StartVertex.Point.X;
ShtMtlEdge = tmpShtMtlEdge;
}
}
which again in my debugging I confirmed does find the right most edge of that face.
ofc this does not work either I get it flipping and everthing randomly rotated it seems as if the wrong edge was used still. even if I change AlignmentType to horixonalalignment still comes out wrong.
This is very confusing and complicated as to how Inventor uses all these pieces to generate the final output and I can't find any common ground to build an automation plugin to do this. I can get manual common tasks to work as I want but it seems to set my edge correctly and use it as intended so I believe I am not setting the edge correctly and assigning it to the Alignment axis as needed.
Thanks for any help and sorry for the wall of text.
Shannon