iLogic skip iProperty feild when it does not exit

iLogic skip iProperty feild when it does not exit

schmidkeadam
Contributor Contributor
413 Views
1 Reply
Message 1 of 2

iLogic skip iProperty feild when it does not exit

schmidkeadam
Contributor
Contributor

ok I'm stumped...... What I am going for is to have Ilogic go out and sum my subassembly custom iproperties. The code that I have is able to go out and read the illogic if the iproperties exits but it gets an error when one of the subassemblies does not have the custom Iproperties. How do I change my code that if one of my subassemblies does not have custom iproperties, it will not error out?

 

SyntaxEditor Code Snippet

'- - - - - - - - - - - find or create custom iProperty - - - - - - - - - - 
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments      
'--------------------------------------------------------------------------------- (Water Creation) 
Dim propertyName1 As String = "Water (PSI)"

oCustomPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")
Try

oProp = oCustomPropertySet.Item(propertyName1)
Catch

oCustomPropertySet.Add(0, propertyName1)
End Try
Next

'---------------------------------------------------------------------------------- (Voltage Creation) 
Dim propertyName3 As String = "Voltage"

oCustomPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")
Try

oProp = oCustomPropertySet.Item(propertyName3)
Catch

oCustomPropertySet.Add(0, propertyName3)
End Try

'- - - - - - - - - - - Sum of the Custom iProperty - - - - - - - - - - 

iProperties.Value("Custom", "Water (PSI)") = 0

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences

If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then

xNumber = iProperties.Value("Custom", "Water (PSI)") 

yNumber = iProperties.Value(oOccurrence.Name,"Custom", "Water (PSI)")
sumNumber =  xNumber + yNumber

iProperties.Value("Custom", "Water (PSI)") = sumNumber

End If
Next
'----------------------------------------------------------------------
iProperties.Value("Custom", "Voltage") = 0
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

For Each oOccurrence In oAsmCompDef.Occurrences

If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then

xNumber = iProperties.Value("Custom", "Voltage") 

yNumber = iProperties.Value(oOccurrence.Name,"Custom", "Voltage")
sumNumber =  xNumber + yNumber 

iProperties.Value("Custom", "Voltage") = sumNumber 
End If
Next
'-------------------------------------- Message Box

Water = iProperties.Value("Custom", "Water (PSI)")
Voltage = iProperties.Value("Custom", "Voltage")

MessageBox.Show("Water = " & Water & vbLf &
"Voltage = " & Voltage & vbLf, " Summary ")

 

0 Likes
414 Views
1 Reply
Reply (1)
Message 2 of 2

bradeneuropeArthur
Mentor
Mentor

hi,

 

Use in general an Empty string like this example:

oCustomPropertySet.Add("", propertyName1)

you are never sure what the value needs to be like a string or a double

 

or use this method:

oCustomPropertySet.Add("0", propertyName1)

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Dimension Component! | Partlist Export! | Derive I-properties! | Vault Prompts Via API! | Vault Handbook/Manual!
Drawing Toggle Sheets! | Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes