Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good morning everyone, I have modified this rule so that it is compatible with my work (I took the basic rule from this forum).
What I can't do is: if "Bend Up and Bend Down" are present in the properties everything works fine, but if the properties are not present the rule does not create new ones. where is it wrong? Thank you.
Imports Inventor
Public Sub Main()
Try
Dim partDoc As PartDocument = ThisApplication.ActiveDocument
If partDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject AndAlso partDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Dim sheetMetalDef As SheetMetalComponentDefinition = partDoc.ComponentDefinition
If Not sheetMetalDef.HasFlatPattern Then
sheetMetalDef.Unfold()
End If
Dim flatPattern As FlatPattern = sheetMetalDef.FlatPattern
Dim upsCount As Integer = 0
Dim downsCount As Integer = 0
For Each bendResult As FlatBendResult In flatPattern.FlatBendResults
If Not bendResult.IsOnBottomFace Then
If bendResult.IsDirectionUp Then
upsCount += 1
Else
downsCount += 1
End If
End If
Next
SetCustomProperty(partDoc, "Bend Up", upsCount)
SetCustomProperty(partDoc, "Bend Down", downsCount)
End If
Catch ex As Exception
MessageBox.Show("Errore durante l'elaborazione del documento: " & vbCrLf & ex.Message, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Sub SetCustomProperty(doc As Document, name As String, value As Integer)
Try
Dim userDefinedProps As Object = doc.PropertySets.Item("User Defined Properties")
Dim customProp As Object = Nothing
' Cerca la proprietà utente con il nome specificato
For Each prop As Object In userDefinedProps
If prop.Name = name Then
customProp = prop
Exit For
End If
Next
' Se la proprietà esiste, aggiorna il valore, altrimenti aggiungila
If customProp IsNot Nothing Then
customProp.Value = value
Else
userDefinedProps.Add(value, name)
End If
Catch ex As Exception
MessageBox.Show("Errore durante la gestione delle proprietà utente: " & ex.Message, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Solved! Go to Solution.