iLogic Auto Text Call Out for each part View, Code Help

iLogic Auto Text Call Out for each part View, Code Help

Anonymous
Not applicable
968 Views
11 Replies
Message 1 of 12

iLogic Auto Text Call Out for each part View, Code Help

Anonymous
Not applicable

So, I was using a code to automatically place part information form the IDW placed Parts List.  It seems to work fin on new drawings or the first time you use it, but once that drawing is closed and you open back up, change the amount of a certain part your have in the assembly, or anything like that, it fails and gives an error.  I have attached the code in a text file.  Basically, all we want to do is run the rule and have it automatically place a text box under each part view with the following info,  Part Number, Description, Material, & QTY.  I had the rule extracting this info from the manually placed parts list in the IDW, it worked fine no matter how many times you changed something in the assembly, you could run it and everything would update, but now that the document has been closed, and re-opened, it pops an error.  Any help would be greatly appreciated.  We can also pull info from the BOM, that would be fine as well, just need to get the info under each part.  Thanks in advance

0 Likes
Accepted solutions (2)
969 Views
11 Replies
Replies (11)
Message 2 of 12

Owner2229
Advisor
Advisor
Accepted solution

Hi, I've shortened your code a bit, tested it and works for me. Even after re-open.

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
For Each oSheet As Inventor.Sheet In oDoc.Sheets
    If oSheet.DrawingViews.Count = 0 Then Continue For
    For Each oView As DrawingView In oSheet.DrawingViews
        Dim oModelFileName As String = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
        Dim oPartList As PartsList
        If oDoc.ActiveSheet.PartsLists.Count > 0 Then
            oPartList = oDoc.ActiveSheet.PartsLists.Item(1)
        Else
            For Each oSheet_B In oDoc.Sheets
                If oSheet_B.PartsLists.Count = 0 Then Continue For
                oPartList = oSheet_B.PartsLists.Item(1)
            Next
        End If
        If oPartList Is Nothing Then Continue For
        For Each oRow As PartsListRow In oPartList.PartsListRows
            Dim oRowFileName As String = oRow.ReferencedFiles.Item(1).FullFileName
            If UCase(oModelFileName) <> UCase(oRowFileName) Then Continue For
            Dim Title As String = iProperties.Value("Summary", "Title")
            Dim oItemValue As String = oRow.Item("Part Number").Value
            Dim oItemMaterial As String = oRow.Item("Material").Value
            Dim oItemQTY As String = oRow.Item("QTY").Value
            Dim oStringName As String = "<StyleOverride Bold='True' FontSize='0.32'>" & Title & "-" & oItemValue & " </StyleOverride>"
            Dim oStringMaterial As String = "<Br/><StyleOverride FontSize='0.305'>" & oItemMaterial & " </StyleOverride>"
            Dim oStringItem As String = "<Br/><StyleOverride FontSize='0.305'>" & " QTY: " & oItemQTY & " </StyleOverride>"
            oView.ShowLabel = True
            oView.Label.FormattedText = oStringName & oStringMaterial & oStringItem
        Next
    Next
Next 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 12

Anonymous
Not applicable

Thank you, It worked for me to one the test assembly I tried it on, but for some reason, I am still getting this error on this certain large assembly only.  Any ideas what could be causing this?  Have anything to do with me deleting the original Parts List and placing a new one?  error given is below.  Thank you!

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.PartsListRow.get_Item(Object Index)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 4 of 12

Owner2229
Advisor
Advisor
Accepted solution

Here's my best shot, based on my testing:

In your new parts list you're missing one of the columns ("Part Number", "Material" or "QTY").

 

Make sure these are present in the parts list, or I can write in an exception that will ignore it, so let me know.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 5 of 12

Anonymous
Not applicable

Thank you, I had them Present, but I had changed the Header to just say "Part" instead of Part Number, the weird thing was, that I knew this, and had tried changing it in the code to match the change, but it still kicked back until I returned it to say Part Number in the Parts List.  Thank you!

0 Likes
Message 6 of 12

Owner2229
Advisor
Advisor

You're welcomed Smiley Happy

 

Edit, to prevent unnecessary looping:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
For Each oSheet As Inventor.Sheet In oDoc.Sheets
    If oSheet.DrawingViews.Count = 0 Then Continue For
    For Each oView As DrawingView In oSheet.DrawingViews
        Dim oModelFileName As String = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
        Dim oPartList As PartsList
        If oDoc.ActiveSheet.PartsLists.Count > 0 Then
            oPartList = oDoc.ActiveSheet.PartsLists.Item(1)
        Else
            For Each oSheet_B In oDoc.Sheets
                If oSheet_B.PartsLists.Count = 0 Then Continue For
                oPartList = oSheet_B.PartsLists.Item(1)
Exit For Next End If If oPartList Is Nothing Then Continue For For Each oRow As PartsListRow In oPartList.PartsListRows Dim oRowFileName As String = oRow.ReferencedFiles.Item(1).FullFileName If UCase(oModelFileName) <> UCase(oRowFileName) Then Continue For Dim Title As String = iProperties.Value("Summary", "Title") Dim oItemValue As String = oRow.Item("Part Number").Value Dim oItemMaterial As String = oRow.Item("Material").Value Dim oItemQTY As String = oRow.Item("QTY").Value Dim oStringName As String = "<StyleOverride Bold='True' FontSize='0.32'>" & Title & "-" & oItemValue & " </StyleOverride>" Dim oStringMaterial As String = "<Br/><StyleOverride FontSize='0.305'>" & oItemMaterial & " </StyleOverride>" Dim oStringItem As String = "<Br/><StyleOverride FontSize='0.305'>" & " QTY: " & oItemQTY & " </StyleOverride>" oView.ShowLabel = True oView.Label.FormattedText = oStringName & oStringMaterial & oStringItem Next Next Next
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 7 of 12

Anonymous
Not applicable

So, it was working fine, and then i replaced a couple parts, put in a couple new flat patterns and it is giving the same error, with no other changes, could you help with that exception to see if that is the cause?

0 Likes
Message 8 of 12

Owner2229
Advisor
Advisor

Sure, here you go. If any of the parts list's columns will be missing, it won't be shown in the part's label.

Therefore if the label is empty, all the columns are missing (or wrong).

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
For Each oSheet As Inventor.Sheet In oDoc.Sheets
    If oSheet.DrawingViews.Count = 0 Then Continue For
    For Each oView As DrawingView In oSheet.DrawingViews
        Dim oModelFileName As String = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
        Dim oPartList As PartsList
        If oDoc.ActiveSheet.PartsLists.Count > 0 Then
            oPartList = oDoc.ActiveSheet.PartsLists.Item(1)
        Else
            For Each oSheet_B In oDoc.Sheets
                If oSheet_B.PartsLists.Count = 0 Then Continue For
                oPartList = oSheet_B.PartsLists.Item(1)
                Exit For
            Next
        End If
        If oPartList Is Nothing Then Continue For
        For Each oRow As PartsListRow In oPartList.PartsListRows
            Dim oRowFileName As String = oRow.ReferencedFiles.Item(1).FullFileName
            If UCase(oModelFileName) <> UCase(oRowFileName) Then Continue For
            Dim LabelText As String = vbNullString
            Try
Dim Title As String = iProperties.Value("Summary", "Title") Dim oItemValue As String = oRow.Item("Part Number").Value LabelText += "<StyleOverride Bold='True' FontSize='0.32'>" & Title & "-" & oItemValue & "</StyleOverride>" Catch End Try Try Dim oItemMaterial As String = oRow.Item("Material").Value If LabelText <> vbNullString Then LabelText += "<Br/>" LabelText += "<StyleOverride FontSize='0.305'>" & oItemMaterial & "</StyleOverride>" Catch End Try Try Dim oItemQTY As String = oRow.Item("QTY").Value If LabelText <> vbNullString Then LabelText += "<Br/>" LabelText += "<StyleOverride FontSize='0.305'>" & " QTY: " & oItemQTY & "</StyleOverride>" Catch End Try oView.ShowLabel = True oView.Label.FormattedText = LabelText Next Next Next
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 9 of 12

Anonymous
Not applicable

Thank you, but this is really weird, after checking it into Vault, then checking it back out to make an update, then I run the rule(even the exception one) and I get this error.  Any ideas of what could possibly be happening here?

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.ReferencedFileDescriptors.get_Item(Int32 Index)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Message 10 of 12

Anonymous
Not applicable

Also, here is a little more info, the assembly is ~100 Parts, a couple are phantom parts.  It is comprised of all sheet metal and has sub assemblies and rules in some sub-assemblies etc. no other rules are running when this one is ran, and I have zero idea of why this would happen, literally nothing has changed since I checked it in and back out, besides putting a couple "custom parts" in the parts list that are stock flat pattern parts that are not in the assembly.  But the kicker is, I tried it before making these changes, I'm really stumped, it has to be something somewhere else besides the rule maybe?  Not sure.  This is meant to be a template for our engineering team to use to make out enclosures in a faster, more correct manner.  All I need is the flat patterns/parts to be labeled automatically with correct updating quantities and material.  Not sure what is wrong for it to pop that error code, Thanks for all of your help!

0 Likes
Message 11 of 12

Anonymous
Not applicable

So, i figured out why it would not run, it is because i put custom parts in the parts list, is there any way to make it run WITH the custom parts in there?

0 Likes
Message 12 of 12

Owner2229
Advisor
Advisor

Yes it is. Try this one below.

I wrote in two exceptions. The first will handle missing document reference / custom view and the second will catch a row with missing document reference / custom row.

 

Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
For Each oSheet As Inventor.Sheet In oDoc.Sheets
    If oSheet.DrawingViews.Count = 0 Then Continue For
    For Each oView As DrawingView In oSheet.DrawingViews
Dim oRefDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
If oRefDoc Is Nothing Then Continue For Dim oModelFileName As String = oRefDoc.FullFileName Dim oPartList As PartsList If oDoc.ActiveSheet.PartsLists.Count > 0 Then oPartList = oDoc.ActiveSheet.PartsLists.Item(1) Else For Each oSheet_B In oDoc.Sheets If oSheet_B.PartsLists.Count = 0 Then Continue For oPartList = oSheet_B.PartsLists.Item(1) Exit For Next End If If oPartList Is Nothing Then Continue For For Each oRow As PartsListRow In oPartList.PartsListRows
If oRow.ReferencedFiles.Count = 0 Then Continue For Dim oRowFileName As String = oRow.ReferencedFiles.Item(1).FullFileName If UCase(oModelFileName) <> UCase(oRowFileName) Then Continue For Dim LabelText As String = vbNullString Try Dim Title As String = iProperties.Value("Summary", "Title") Dim oItemValue As String = oRow.Item("Part Number").Value LabelText += "<StyleOverride Bold='True' FontSize='0.32'>" & Title & "-" & oItemValue & "</StyleOverride>" Catch End Try Try Dim oItemMaterial As String = oRow.Item("Material").Value If LabelText <> vbNullString Then LabelText += "<Br/>" LabelText += "<StyleOverride FontSize='0.305'>" & oItemMaterial & "</StyleOverride>" Catch End Try Try Dim oItemQTY As String = oRow.Item("QTY").Value If LabelText <> vbNullString Then LabelText += "<Br/>" LabelText += "<StyleOverride FontSize='0.305'>" & " QTY: " & oItemQTY & "</StyleOverride>" Catch End Try oView.ShowLabel = True oView.Label.FormattedText = LabelText Next Next Next
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes