iLogic Not Working Correctly When iProperty not found

iLogic Not Working Correctly When iProperty not found

Matthew_Policelli
Advocate Advocate
523 Views
4 Replies
Message 1 of 5

iLogic Not Working Correctly When iProperty not found

Matthew_Policelli
Advocate
Advocate

I am trying to write an iLogic that inputs the "Pattern" custom iProperty into the view label and turns it on. If the Pattern iProperty is not found, I want it to not change the label, turn off the label visibility, and move on to the next view. I want it linked to the iProperty rather than just the value because I don't want people to have to run the iLogic all over again if the pattern letter changes on one of the parts.

 

The issue I am having is this: The code works just fine when every view on the drawing has the Pattern custom iProperty. However, when the first placed view (or maybe any view, I'm not sure) does not have this custom property, the code selects the wrong custom property on all the views that have the custom property and also turns off the view label on those views.

 

It seems that when the code can't find the "PATTERN" iProperty, it selects a different one and then doesn't look for the "PATTERN" iProperty on the following iterations, but I'm not sure why this would happen.

 

What am I doing wrong?

 

Here is my code:

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oView As DrawingView
Dim oPatProp As Inventor.Property
Dim oPat As String

For Each oView In oSheet.DrawingViews
	Dim oMDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oCProps As Inventor.PropertySet = oMDoc.PropertySets.Item("Inventor User Defined Properties")
	Try
		oView.ShowLabel = True
		oPatProp = oCProps.Item("PATTERN")
		oPat = "<Property Document='model' FormatID='" & oCProps.InternalName & _
		"' PropertyID='" & oPatProp.PropId & "' />"
		
		'check if input is correct (will remove from final code)
		a = InputBox("", "Before Changes:", oView.Label.FormattedText) 
		
		oView.Label.FormattedText = oPat
	Catch
		oView.ShowLabel = False
End Try

Next

 

After running the code, all the views have their view labels hidden, and this in the view label text:

Matthew_Policelli_1-1636391311677.png

 

This is a list of the custom iProperties in the view that doesn't have "PATTERN":

Matthew_Policelli_0-1636391260950.png

 

This is a list of our custom iProperties in the views that do have "PATTERN":

2021-11-08 12_01_02-Autodesk Inventor Professional 2020.jpg

0 Likes
Accepted solutions (1)
524 Views
4 Replies
Replies (4)
Message 2 of 5

Matthew_Policelli
Advocate
Advocate

I've narrowed the problem down to this line:

 

oView.Label.FormattedText = oPat

 

 For some reason, even though I can get the correct value returned using 

 

MsgBox(oPatProp.Value)

 

It gives me this error when I get to the line to set the label to the parameter string:

Matthew_Policelli_0-1636400706917.png

 

So why can't it set the label to that xml string even though it can find the value of the parameter?

0 Likes
Message 3 of 5

JelteDeJong
Mentor
Mentor

There are some things wrong with your formatted text. try this:

Dim propSetName = "User Defined Properties"
Dim propName = "PATTERN"

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet

For Each oView As DrawingView In oSheet.DrawingViews
    Dim oMDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
    Dim oCProps As Inventor.PropertySet = oMDoc.PropertySets.Item(propSetName)
    Try
        oView.ShowLabel = True
        Dim oPatProp As Inventor.Property = oCProps.Item(propName)
        Dim text = String.Format("<Property Document='model' PropertySet='{0}' Property='{1}' FormatID='{2}' PropertyID='4'>{1}</Property>",
               propSetName, propName, oCProps.InternalName)

        oView.Label.FormattedText = text
    Catch
        oView.ShowLabel = False
    End Try
Next

 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 5

Matthew_Policelli
Advocate
Advocate

Hello, and thanks for the reply 🙂

 

I tried your code and it still does not change the label to the correct parameter. This time it changes it to this:

Matthew_Policelli_0-1636458280485.png

To try to figure out what was happening, I added two message boxes to the code to compare the "text" string and the formatted text of the view label after it is set to = text:

 

MsgBox(text,Title:="Text String Value")  						'<-------- check text string value
        oView.Label.FormattedText = text
MsgBox(oView.Label.FormattedText,Title:="Label Formatted Text")    '<-------- check label value

 

 

Here are the results:

Matthew_Policelli_3-1636458874867.png

Matthew_Policelli_4-1636458897039.png

 

As you can see, even though the code sets the formatted text of the label to equal the text string, they aren't equal.

Is this a bug? It doesn't seem to be an issue with the code.

 

0 Likes
Message 5 of 5

Matthew_Policelli
Advocate
Advocate
Accepted solution

The only way I can get it to work is to temporarily add the custom iproperty to files that don't have it, and then delete it at the end of the code. This may be a bit of a roundabout method but it works. However, is there a way for me to have it turn off alerts for read only files? (so have it add the iproperty for read only and then delete the pattern without asking if I want to change it or check it out from vault?)

0 Likes