Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
ts2.cad3
348 Views, 6 Replies

Write flat pattern area parameter to each sheet metal in the assembly

Hi all, i get this error:"Object variable or With block variable not set" in this simple macro. 

Someone have any tips?

 

 

Sub Main
	
Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAssyDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition
Dim oSSet As SelectSet = oAssyDoc.SelectSet
Dim oDoc As Inventor.Document


	For Each oDoc In oAssyDoc.AllReferencedDocuments
		'verify document type (we are interested in metal sheets only)
		If oDoc.ComponentDefinition.Type = kSheetMetalComponentDefinitionObject Then

			Dim oDef As SheetMetalComponentDefinition = oDoc.ComponentDefinition
			Dim oColl As ComponentOccurrencesEnumerator = oAssyDef.Occurrences.AllReferencedOccurrences(oDoc)
				If oColl.Count > 0 Then
					'select all found components
					Dim oOcc As ComponentOccurrence= oObj
					
					For Each oOcc In oColl
						Call cQM(oOcc, oDoc, oDef)
					Next oOcc
				End If
			End If		
	Next
End Sub

Sub cQM(oOcc, oDoc, oDef)


	Dim oDocName As String = oDoc.DisplayName 

'        If oCompDef.HasFlatPattern = False Then		
'            oCompDef.Unfold 
'			oCompDef.FlatPattern.ExitEdit         
'            'Dim ACTD As Document = TryCast(ThisApplication.ActiveDocument, Document)
'            ACTD.Close()
'        End If        
        Dim extents_area As Double = oDef.Flatpattern.Length * 10 * oDef.Flatpattern.Width * 10
        Dim sfr As Double = extents_area 
        
     
        sfr = CStr(sfr)

        iProperties.Value(oDocName, "Custom", "QTA_MATERIALE") = sfr
		iProperties.Value(oDocName, "Custom", "DIMENSIONI") = ""
			

End Sub