iLogic/iProperty error

iLogic/iProperty error

Anonymous
Not applicable
1,131 Views
5 Replies
Message 1 of 6

iLogic/iProperty error

Anonymous
Not applicable

Hello,

 

I setup a basic routine to generate custom iProperties for a file:

'Checks To see If the following iProperties exist and creates them if necessary

Dim FabProcess As String = "FABRICATION PROCESS"
Dim Inspect As String = "INSPECTION REQUIRED (Y/N)"
Dim merge As String = "MERGE"
Dim finish As String = "FINISH"


customPropertySet = ThisDoc.Document.PropertySets.Item _
("Inventor User Defined Properties")

Try
prop = customPropertySet.Item(FabProcess)
prop = customPropertySet.Item(Inspect)
prop = customPropertySet.Item(merge)
' prop = customPropertySet.Item(finish)
Catch
' Assume error means not found
customPropertySet.Add("", FabProcess)
customPropertySet.Add("", Inspect)
customPropertySet.Add("", merge)
' customPropertySet.Add("", finish)
End Try

'output the custom iproperties and update the file
RuleParametersOutput()
InventorVb.DocumentUpdate()

 

Eveything runs fine until I un-comment the "finish" lines.

 

Any ideas?

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

frederic.vandenplas
Collaborator
Collaborator

You do a try catch over your entire block of code, so if one fails, all those behind will not be executed too.

 

Try catch should be avoided if you know that there is a possibility that something can/will go wrong (like there is no iprop 

with that name)

 

If you do want to use it, put try catch around each iprop retrieve line

 

It's more neat to check if it's there and if not execute the code...

 

Dim FabProcess As String = "FABRICATION PROCESS"
Dim Inspect As String = "INSPECTION REQUIRED (Y/N)"
Dim merge As String = "MERGE"
Dim finish As String = "FINISH"

customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")

If customPropertySet.Item(FabProcess) Is Nothing Then
customPropertySet.Add("", FabProcess)
End If
If customPropertySet.Item(Inspect) Is Nothing Then
customPropertySet.Add("", Inspect)
End If
If customPropertySet.Item(merge) Is Nothing Then
customPropertySet.Add("", merge)
End If
If customPropertySet.Item(finish) Is Nothing Then
customPropertySet.Add("", finish)
End If

RuleParametersOutput()
InventorVb.DocumentUpdate()
If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 3 of 6

wayne.brill
Collaborator
Collaborator

Hello S.McCarthy,

 

Can you mark this issue as solved (by Frederic) or reply with the current status? If you are getting errors please upload an Inventor file with the rule that is not working. (I am only seeing two posts on this issue).

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 4 of 6

b.mccarthy
Collaborator
Collaborator

Implementing the code supplied by Frederic generates an error. I can get the code to work using Try/Catch, but only for 3 fields. Adding a 4th causes the routine to fail, even if I reorder the code.

 

This is the current code:

 

'Checks To see If the following iProperties exist and creates them if necessary

 Dim FabProcess As String = "FABRICATION PROCESS"
 Dim Inspect As String = "INSPECTION REQUIRED (Y/N)"
 Dim finish As String = "FINISH"
 Dim merge As String = "MERGE"


customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")

If customPropertySet.Item(FabProcess) Is Nothing Then
	customPropertySet.Add("", FabProcess)
End If
If customPropertySet.Item(Inspect) Is Nothing Then
	customPropertySet.Add("", Inspect)
End If
If customPropertySet.Item(merge) Is Nothing Then
	customPropertySet.Add("", merge)
End If
If customPropertySet.Item(finish) Is Nothing Then
	customPropertySet.Add("", finish)
End If

'Try
'		  prop = customPropertySet.Item(finish)
'          prop = customPropertySet.Item(FabProcess)
'          prop = customPropertySet.Item(Inspect)
''          prop = customPropertySet.Item(merge)
'          
'Catch
'      ' Assume error means not found
'	 	  customPropertySet.Add("", finish)
'          customPropertySet.Add("", FabProcess)
'          customPropertySet.Add("", Inspect)
''          customPropertySet.Add("", merge)
'End Try



'output the custom iproperties and update the file
RuleParametersOutput()
InventorVb.DocumentUpdate()

)
I ran this code in a new part, assembly and drawing, and it fails everytime, regardless of which section of code is active.Any ideas?

0 Likes
Message 5 of 6

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi,

 

I find that error checking needs to be used when trying to get a property that may or may not exist.  (there is not a method like PropertySets.PropertySetExists for a Property) You can see this approach using error checking in the UpdateVolume() VBA example in the Inventor programming help. VBA uses Err for this. In VB.NET you would use Try Catch for similar functionality.

 

Here is the iLogic rule that works in my tests. The first time I run it in a new file the Properties are added with no values. The second time values are added to each property.

 

'Checks To see If the following iProperties exist and creates them if necessary

 Dim FabProcess As String = "FABRICATION PROCESS"
 Dim Inspect As String = "INSPECTION REQUIRED (Y/N)"
 Dim finish As String = "FINISH"
 Dim merge As String = "MERGE"

customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")

Dim myProp As Inventor.Property

Try
	myProp = customPropertySet.Item(FabProcess)
	myProp.Value = "WB_FabProcess"
Catch
	myProp = customPropertySet.Add("", FabProcess)
End Try

Try
	myProp = customPropertySet.Item(Inspect)
	myProp.Value = "WB_InSpect"
Catch
	myProp = customPropertySet.Add("", Inspect)
End Try

Try
  myProp = customPropertySet.Item(merge)
  myProp.Value = "WB_Merge"
Catch
	myProp = customPropertySet.Add("", merge)
End Try

Try
	myProp = customPropertySet.Item(finish)
	myProp.Value = "WB_finish"
Catch
	myProp = customPropertySet.Add("", finish)
End Try

'output the custom iproperties and update the file
RuleParametersOutput()
InventorVb.DocumentUpdate()

 

 

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 6 of 6

b.mccarthy
Collaborator
Collaborator

Works great!

 

Thank you!

0 Likes