Flat Pattern Size Custom iProperty

Flat Pattern Size Custom iProperty

Anonymous
Not applicable
857 Views
2 Replies
Message 1 of 3

Flat Pattern Size Custom iProperty

Anonymous
Not applicable

I have a rule that checks if parts in an assembly are sheet metal. if they are it adds a custom iproperty to the part, and is supposed to fill the custom property with the length and width of the part. 

 

It all works except for the actual length and width of the flat pattern.

 

SyntaxEditor Code Snippet

Dim oDoc As Document
 
Dim asmDoc As AssemblyDocument  
asmDoc = ThisApplication.ActiveDocument  
 
Dim asmDef As AssemblyComponentDefinition  
asmDef = asmDoc.ComponentDefinition 
 
For Each oDoc In asmDoc.AllReferencedDocuments
   If oDoc.DocumentType = kPartDocumentObject And oDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
      Dim propertyName As String = "Blank Size"
      Dim propertyValue As String = Round(SheetMetal.FlatExtentsWidth, 0) & " x " & Round(SheetMetal.FlatExtentsLength, 0) 
 
      customPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
 
      Try
         prop = customPropertySet.Item(propertyName)
      Catch
         ' Assume error means not found
         customPropertySet.Add("", propertyName)
         prop = customPropertySet.Item(propertyName)
      End Try
 
      prop.Value = propertyValue

   End If 
 
Next

I'm assuming it has to do with the  property value as string, and thought something along the lines of this

 

Dim oSheet As PartDocument
oSheet = ThisApplication.ActiveDocument

Dim oSheetmetal As SheetMetalComponentDefinition
oSheetmetal = oSheet.FlatPattern

Dim propertyName As String = "Blank Size"
Dim propertyValue As String = oSheetmetal.Length() & " x" & osheetmetal.Width()

 

Is required.

 

Am I on the right track? Could someone point me in the right direction here?

 

Cheers

0 Likes
Accepted solutions (1)
858 Views
2 Replies
Replies (2)
Message 2 of 3

b_sharanraj
Advocate
Advocate
Accepted solution
Hi @Anonymous

The Function SheetMetal.FlatExtentsLength & SheetMetal.FlatExtentsWidth will only work in iLogic of Sheetmetal Component.

For accessing these functions you need to modify your code slightly.

Try once the below code 🙂 

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim oDoc As Document 

If openDoc.DocumentType = 12291 Then

    For Each oDoc In openDoc.AllReferencedDocuments
        'Is a Sheet Metal File
        If oDoc.SubType.Equals("{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}") Then

            'Obtain max & min flat sizes of part
            Dim smComp As SheetMetalComponentDefinition = oDoc.ComponentDefinition
            If smComp.HasFlatPattern Then
                'Get Units of Measure Object
                Dim uom As UnitsOfMeasure = oDoc.UnitsOfmeasure
                'Get FlatPattern Dims returned as the document units
                Length = uom.ConvertUnits(smComp.FlatPattern.Length, "cm", uom.LengthUnits)
                Width = uom.ConvertUnits(smComp.FlatPattern.Width, "cm", uom.LengthUnits)
                        
                Flt_Ptrn_Len = Round(Length,0) 
                Flt_Ptrn_Wid = Round(Width,0) 
                
                Dim propertyName As String = "Blank Size"
                Dim propertyValue As String = Flt_Ptrn_Len & " x " & Flt_Ptrn_Wid
                
                customPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
 
      Try
         prop = customPropertySet.Item(propertyName)
      Catch
         ' Assume error means not found
         customPropertySet.Add("", propertyName)
         prop = customPropertySet.Item(propertyName)
      End Try
 
      prop.Value = Flt_Ptrn_Len &" x "& Flt_Ptrn_Wid
                
            End If
        End If
    Next
    
Else
       
End If


Regards

B.Sharan Raj

Message 3 of 3

Anonymous
Not applicable

Perfect, thank you so much, I was miles off.

0 Likes