Wrong output through API when accessing Rangebox Points

Wrong output through API when accessing Rangebox Points

h.schkorwaga
Advocate Advocate
1,050 Views
4 Replies
Message 1 of 5

Wrong output through API when accessing Rangebox Points

h.schkorwaga
Advocate
Advocate

Hello everyone,

 

when saving an part file the saveevent triggers a smal procedure which reads/calculates the dimensions of the flatpattern.

 

Length = Math.Round(Math.Abs(sheetMetalComponentDefinition.FlatPattern.RangeBox.MaxPoint.X - sheetMetalComponentDefinition.FlatPattern.RangeBox.MinPoint.X), accuracy);
Width =  Math.Round(Math.Abs(sheetMetalComponentDefinition.FlatPattern.RangeBox.MaxPoint.Y - sheetMetalComponentDefinition.FlatPattern.RangeBox.MinPoint.Y), accuracy);
Height = Math.Round(Math.Abs(sheetMetalComponentDefinition.FlatPattern.RangeBox.MaxPoint.Z - sheetMetalComponentDefinition.FlatPattern.RangeBox.MinPoint.Z), accuracy);

With this dimensions I do some check afterwards (f.e. sheetmetal settings are correct).

 

The height I get when using the calculation above (MaxPoint.Z - MinPoint.Z) is wrong for a more little complex sheet metal parts than flat parts, "standard" boxes (base with four flanges) and so on.

 

I made some investigations by adding two workpoints to the flatpattern through the API:

WorkPoint workPoint_Z1 = sheetMetalComponentDefinition.FlatPattern.WorkPoints.AddFixed(sheetMetalComponentDefinition.FlatPattern.RangeBox.MaxPoint);
WorkPoint workPoint_Z2 = sheetMetalComponentDefinition.FlatPattern.WorkPoints.AddFixed(sheetMetalComponentDefinition.FlatPattern.RangeBox.MinPoint);

 

I attached some screenshots in the ZIP-File below.

 

They show a simple box and the corresponding flatpattern with the two inserted Workpoint (through API) - they seem to sit perfectly on the vertices. The 3mm thickness is set correctly and measure tool shows the same. Also if I measure from bottom to top flatpattern face --> 3mm --> all fine!

 

I also added a little more complex part (2mm thickness is set correctly) and the corresponding flatpattern. As you can see in one of the screenshots the workpoints are off the part/flatpattern-body and away from the vertice where they should sit. Measuring the delta between the workpoints returns NOT the thickness the parts has when checking face to face delta. --> Wrong!

 

Ok now you say the second parte is a derived one but I also tried a part which looks similar from scratch and with a hole whit the same problem.

 

Simple question with maybe a difficult answer from your side... Why????

 

Thank you in advance

BR

0 Likes
1,051 Views
4 Replies
Replies (4)
Message 2 of 5

Sergio.D.Suárez
Mentor
Mentor

Hello, here I share another method to take the measurements of the unfolded sheet, which I use, and it seems safe.

 

Dim doc As PartDocument= ThisDoc.Document
Dim oSheetCompDef As SheetMetalComponentDefinition = doc.ComponentDefinition
Dim accuracy As Integer = 3 

If oSheetCompDef.HasFlatPattern = False Then 
	oSheetCompDef.Unfold
	oSheetCompDef.FlatPattern.ExitEdit
End If

Dim oWidth As Double = Math.Round(oSheetCompDef.Thickness.Value, accuracy)
Dim oHeight As Double =  Math.Round(oSheetCompDef.FlatPattern.Width, accuracy)
Dim oLength As Double = Math.Round(oSheetCompDef.FlatPattern.Length, accuracy)


MessageBox.Show("Width: " & oWidth & " cm" & vbCrLf & _
				"Height: " & oHeight & " cm" & vbCrLf & _
				"Length: " & oLength & " cm")
				

 However, regarding the creation of work points in the flatpattern taking the coordinates of the box, I have encountered this error before and I do not remember what I did to skip it. If I find any explanation I will place it in the thread. 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

0 Likes
Message 3 of 5

h.schkorwaga
Advocate
Advocate

Hello and thank you for your reply,

 

I already know following properties.

oSheetCompDef.FlatPattern.Width
oSheetCompDef.FlatPattern.Length

OK - it seems they both return the correct value - then I can switch my code.

 

In the meantime I saw that length and width could also be wrong. So when i look on the f.e top-face and look for my two workpoints - they could be totally off the body. A collegue sent me a sheetmetal where a sheet is rolled to a pipe, the width should be about 500mm and the calculation was 1200mm - Whaaat???

 

Concerning this:

oSheetCompDef.Thickness.Value

Do you know where this value comes from? Is this from the sheetmetal-setting? If yes I can't take it.

I like to compare the "settings thickness-value" to the calculated/queried/measured one to check if the sheetmetal has the correct body-height.

 

BR

 

0 Likes
Message 4 of 5

Sergio.D.Suárez
Mentor
Mentor

oSheetCompDef.Thickness.Value
It is the value assigned to the current sheet thickness by default. I use it a lot because it is independent of the parameter name, you can have another inventor language, but it returns the same parameter (if I accessed by parameter name it would return an error)
For the accesses of the previous measures of the length and width, you need the FlatPattern of the sheet, it may be the case that it does not exist yet, or that it cannot be created, then it will return an error, but you will be able to access the current established thickness.
For example, when you import a sheet with a thickness of 3.17 mm but you have a default of 0.5 mm the access oSheetCompDef.Thickness.Value will return 0.5 mm, but you cannot create the actual sheet display until the value of 0.5 is corrected at 3.17 mm (which is the real value of the imported metal sheet)

Grettings!


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

0 Likes
Message 5 of 5

h.schkorwaga
Advocate
Advocate

Yes correct 😉 - but as explained this is not what I wnat to achieve.

I looked in the API-help but unfortunately there is no propertie like

 

sheetMetalComponentDefinition.FlatPattern.thickness

which should return the body-Z-axis-length of the unfolded part.

 

 

Then I tried following:

int i = 1;
foreach (Vertex vertex in sheetMetalComponentDefinition.FlatPattern.TopFace.Vertices)
{
    WorkPoint workPoint = sheetMetalComponentDefinition.FlatPattern.WorkPoints.AddFixed(vertex.Point);
    workPoint.Name = "TopFAce" + i.ToString();
    i++;
}

i = 1;
foreach (Vertex vertex in sheetMetalComponentDefinition.FlatPattern.BottomFace.Vertices)
{
    WorkPoint workPoint = sheetMetalComponentDefinition.FlatPattern.WorkPoints.AddFixed(vertex.Point);
    workPoint.Name = "BottomFace" + i.ToString();
    i++;
}

If the flatpattern could be created the second loop produces workpoints that are all off the body. Okeeeey. That seems not to be correct, hm? 😉

 

Next try:

int i = 1;
foreach (Vertex vertex in sheetMetalComponentDefinition.FlatPattern.Body.Vertices)
{
    if (i == 1) // skip first run of loop to access the previous item
    {                       
        i++;
        continue;
    }
    if (sheetMetalComponentDefinition.FlatPattern.Body.Vertices[i - 1].Point.Z != vertex.Point.Z)
    {
        Height = Math.Round(Math.Abs(sheetMetalComponentDefinition.FlatPattern.Body.Vertices[i - 1].Point.Z - vertex.Point.Z), accuracy);
        break;
    }
    i++;
}

This works good since now with both test parts.

 

 

 

 

 

0 Likes