FlatExtents Length and Width Return Zero when Using iLogic in Assembly

FlatExtents Length and Width Return Zero when Using iLogic in Assembly

TheClenched
Contributor Contributor
1,058 Views
5 Replies
Message 1 of 6

FlatExtents Length and Width Return Zero when Using iLogic in Assembly

TheClenched
Contributor
Contributor

Hey guys,

 

So I have been messing around with sheet metal and returning flat pattern sizes using iLogic. However, whenever I use iLogic in my Assembly (which contains some sheet metal parts), and use the FlatExtentsLength and the FlatExtentsWidth functions in the iLogic rule I made at the assembly level, the numbers are always returned at zero. However, when I create a rule in the part itself and run the FlatExtentsLength  and width Rule at the part level itself, it returns the correct sizes of the flat pattern. Do you guys have any insight into this? Any help would be appreciated.

 

Thanks,

 

AT

0 Likes
Accepted solutions (1)
1,059 Views
5 Replies
Replies (5)
Message 2 of 6

TheClenched
Contributor
Contributor

Here is the example I use at the part level, just to test what it returns at,

Dim extents_length As Double
Dim extents_width As Double

extents_length = SheetMetal.FlatExtentsLength
extents_width = SheetMetal.FlatExtentsWidth

MessageBox.Show(extents_length)
MessageBox.Show(extents_width)

This returns the correct value.

 

This is the code that I use at the assembly level (with multiple sheet metal parts).

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document

For Each docFile In openDoc.AllReferencedDocuments


Dim FNamePos As Integer = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String = Right(docFile.FullFileName, Len(docFile.FullFileName) -FNamePos)
Dim docPNum As String = iProperties.Value(docFName, "Project", "Part Number")

If iProperties.Value(docFName, "Project", "Part Number") = "AL03060" Then
	MessageBox.Show("Did I Make it?")
' Checks to see if the active document is a standard part.
	If docFile.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}"
   		' If it is a standard part it is converted to sheet metal
   	Try
      docFile.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
  	Catch
      ' Catch error and exit rule when part can't be converted
      ' Example: multiple solid body part
      	Return
   	End Try
	End If
	MessageBox.Show(docFile.SubType)

' Gets the document's units of measure
Dim uom As UnitsOfMeasure = docFile.UnitsOfMeasure
' Converts length unit to a string
Dim Units As String = uom.GetStringFromType(uom.LengthUnits)
' Gets the X & Y dimensions of the part from sheetmetal extents
X = SheetMetal.FlatExtentsLength
Y = SheetMetal.FlatExtentsWidth

MessageBox.Show(X)
MessageBox.Show(Y)


' Go to the FlatPattern
Dim oSMCD As SheetMetalComponentDefinition
oSMCD = docFile.ComponentDefinition
' Look for Flatpattern
If Not oSMCD.HasFlatPattern Then
   ' Create Flatpattern if the part doesn't have one
   oSMCD.Unfold()
   docFile.Update2(True)
Else
   oSMCD.FlatPattern.Edit
End If

' Get the min and max point of the Flatpattern
Dim minPoint As Point = oSMCD.SurfaceBodies.Item(1).RangeBox.MinPoint
Dim maxPoint As Point = oSMCD.SurfaceBodies.Item(1).RangeBox.MaxPoint



' Tickness is maxPoin - minPoint
' Since FlatPattern always returns "cm", we have to multiple it by 10 to get "mm"
Z = (maxPoint.Z - minPoint.Z) * 10

' Create measure strings
Dim LengthString As String = MaxOfMany (X,Y,Z)
Dim WidthString As String = X + Y + Z - MaxOfMany (X,Y,Z) - MinOfMany(X,Y,Z)
Dim ThicknessString As String = MinOfMany (X,Y,Z)
' Sets iProperties for Length, Width & Thickness.  Unit string is added to each value.
MessageBox.Show(LengthString)
MessageBox.Show(WidthString)
MessageBox.Show(ThicknessString)

' Exit the FlatPattern
oSMCD.FlatPattern.ExitEdit()

Else
End If

Next

 This returns zero in my message boxes for X and Y.

 

Any help would be greatly appreciate.

 

Thanks,

 

AT

0 Likes
Message 3 of 6

marcin_otręba
Advisor
Advisor
Accepted solution

Hi,

 

 

 

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document

For Each docFile In openDoc.AllReferencedDocuments


Dim FNamePos As Integer = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String = Right(docFile.FullFileName, Len(docFile.FullFileName) -FNamePos)
Dim docPNum As String = iProperties.Value(docFName, "Project", "Part Number")

If iProperties.Value(docFName, "Project", "Part Number") = "AL03060" Then
	MessageBox.Show("Did I Make it?")
' Checks to see if the active document is a standard part.
	If docFile.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}"
   		' If it is a standard part it is converted to sheet metal
   	Try
            docFile.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
  	Catch
      ' Catch error and exit rule when part can't be converted
      ' Example: multiple solid body part
      	'Return
   	End Try
	End If
	MessageBox.Show(docFile.SubType)
If docFile.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
' Gets the document's units of measure
Dim uom As UnitsOfMeasure = docFile.UnitsOfMeasure
' Converts length unit to a string
Dim Units As String = uom.GetStringFromType(uom.LengthUnits)
' Gets the X & Y dimensions of the part from sheetmetal extents

' Go to the FlatPattern
Dim oSMCD As SheetMetalComponentDefinition
oSMCD = docFile.ComponentDefinition
' Look for Flatpattern
If Not oSMCD.HasFlatPattern Then
   ' Create Flatpattern if the part doesn't have one
   oSMCD.Unfold()
   docFile.Update2(True)
Else
  ' oSMCD.FlatPattern.Edit
End If

Dim fp As FlatPattern = oSMCD.FlatPattern

X = fp.Length

Y = fp.Width

' Get the min and max point of the Flatpattern
Dim minPoint As Point = fp.RangeBox.MinPoint
Dim maxPoint As Point = fp.RangeBox.MaxPoint



' Tickness is maxPoin - minPoint
' Since FlatPattern always returns "cm", we have to multiple it by 10 to get "mm"
Z = (maxPoint.Z - minPoint.Z) * 10

' Create measure strings
Dim LengthString As String = MaxOfMany (X,Y,Z)
Dim WidthString As String = X + Y + Z - MaxOfMany (X,Y,Z) - MinOfMany(X,Y,Z)
Dim ThicknessString As String = MinOfMany (X,Y,Z)
' Sets iProperties for Length, Width & Thickness.  Unit string is added to each value.
MessageBox.Show(LengthString & " x " & WidthString & " x " & ThicknessString)

' Exit the FlatPattern
oSMCD.FlatPattern.ExitEdit()
End If
Else
End If

Next

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 4 of 6

TheClenched
Contributor
Contributor

Hi,

 

Thanks for the reply. The code worked except for the fact that the thickness came out 10x larger than it should be (came out at 3 cm instead of 0.3 cm). But yeah, I was able to fix that.

 

Out of curiosity, do you know why the Sheetmetal extents code did not work at the assembly level?

 

Let me know if you do or do not know.

 

Thanks,

 

AT

0 Likes
Message 5 of 6

marcin_otręba
Advisor
Advisor

i think because this :

 

X = SheetMetal.FlatExtentsLength
Y = SheetMetal.FlatExtentsWidth

will work only if you are in sheetmetal part.

If you work with assembly occurrences or reference documents then you must set up what part yyou are reffering to firts to use any component of it.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 6 of 6

TheClenched
Contributor
Contributor

Alright,

 

Thanks for all the assistance. You rock!

 

AT

0 Likes