Applying char length rule to all assemblies/parts in an assembly

Applying char length rule to all assemblies/parts in an assembly

GICain
Contributor Contributor
366 Views
2 Replies
Message 1 of 3

Applying char length rule to all assemblies/parts in an assembly

GICain
Contributor
Contributor

Greetings all! 

 

Let me preface by saying I code like a toddler.

 

What I'm trying to do is have a rule that checks if the Stock Number is > 18 characters and the Description is > 40 characters. If it is, I have an error message that displays, warning the designer.

 

I have 2 problems. 

  • I need this to work for assemblies/parts created before today. The event triggers placed on a standard part/assy file will only apply to anything created after today.
    • I have a dirty way to get around this by using iLogicVb.RunExternalRule("ruleFileName") in an existing rule and piggy backing off existing triggers. Plan is to use that for 3-6 months until we get through the older stuff.
  • The other issue is the rule I created only checks the current open file. If there are issues with 3 parts in an assembly, it just returns the error of the assembly 3x. 

I tried searching the forums but didn't find anything or maybe I wasn't asking the right question. 

 

Code posted below and thanks in advance. 

 

Best,

Gabe

 

If Len(iProperties.Value("Project", "Description")) > 40 And Len(iProperties.Value("Project", "Stock Number")) > 18 Then
	MessageBox.Show("Error, Description Exceeds 40 Characters" _
	& vbLf & "" _'blank
	& vbLf & "Error, SAP Exceeds 18 Characters" _
	& vbLf & "" _ 'blank
	& vbLf & ThisDoc.FileName(True) _
	& vbLf & "" _ 'blank
	& vbLf & ThisDoc.Path, "Desc & SAP Error")
	
Else If Len(iProperties.Value("Project", "Description")) > 40 And Len(iProperties.Value("Project", "Stock Number")) <= 18 Then
	MessageBox.Show("Error, Description Exceeds 40 Characters" _
	& vbLf & "" _ 'blank
	& vbLf & ThisDoc.FileName(True) _
	& vbLf & "" _ 'blank
	& vbLf & ThisDoc.Path, "Desc Error")

Else If Len(iProperties.Value("Project", "Description")) <= 40 And Len(iProperties.Value("Project", "Stock Number")) > 18 Then
	MessageBox.Show("Error, SAP Number Exceeds 18 Characters" _
	& vbLf & "" _ 'blank
	& vbLf & ThisDoc.FileName(True) _
	& vbLf & "" _ 'blank
	& vbLf & ThisDoc.Path, "SAP Error")
End If

 

Gabe Cain
Structural Designer/Engineering Checker
0 Likes
Accepted solutions (1)
367 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

The following rule will check a document and all referenced documents that have been saved before now (DateTime.Now). I guess if you save it as an external rule and then trigger it on before save then you will get what you wanted.

Sub Main()

    Dim doc As Document = ThisDoc.Document
	CheckDocument(doc)

	For Each refDoc As Document In doc.AllReferencedDocuments
		CheckDocument(refDoc)
	Next

End Sub

Private Sub CheckDocument(doc As Document)

    Dim info As New System.IO.FileInfo(doc.FullFileName)
	If (info.LastWriteTime < DateTime.Now()) Then
		Dim propSet = doc.PropertySets.Item("Design Tracking Properties")
		Dim stockNumber = Len(propSet.Item("Stock Number").Value)
		Dim description = Len(propSet.Item("Description").Value)

		If description > 40 And stockNumber > 18 Then
			MessageBox.Show("Error, Description Exceeds 40 Characters" _
					& vbLf & "" _ 'blank
					& vbLf & "Error, SAP Exceeds 18 Characters" _
					& vbLf & "" _ 'blank
					& vbLf & doc.FullFileName, "Desc & SAP Error")

		ElseIf description > 40 And stockNumber <= 18 Then
			MessageBox.Show("Error, Description Exceeds 40 Characters" _
					& vbLf & "" _ 'blank
					& vbLf & doc.FullFileName, "Desc Error")

		ElseIf description <= 40 And stockNumber > 18 Then
			MessageBox.Show("Error, SAP Number Exceeds 18 Characters" _
					& vbLf & "" _ 'blank
					& vbLf & doc.FullFileName, "SAP Error")
		End If
	End If
End Sub

 

JelteDeJong_0-1656021608856.png

 

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 3 of 3

GICain
Contributor
Contributor

@JelteDeJong,

Works great, thank you!

 

The only issue is that older parts won't have the global trigger so my plan is to piggy back off a rule already in place until we work through the older projects. 

 

I also have a plan to make a rule with the sole intent of running other rules not currently in place with global triggers. 

 

Thanks again,

Gabe

Gabe Cain
Structural Designer/Engineering Checker
0 Likes