I logic rule work in AI2020 but don't in AI2017

I logic rule work in AI2020 but don't in AI2017

ts2.cad3
Enthusiast Enthusiast
325 Views
2 Replies
Message 1 of 3

I logic rule work in AI2020 but don't in AI2017

ts2.cad3
Enthusiast
Enthusiast

Hello,  this simple rule work fine in inventor 2020, but in inventor 2017 i got an error : impossible to find member.

Does anyone have any idea how this could be solved?

 

' Get the active assembly.
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
'Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oRefDoc As Document
For Each oRefDoc In oAsmDoc.AllReferencedDocuments 
    Dim baseUnits As String = oRefDoc.ComponentDefinition.BOMQuantity.BaseUnits
    Dim unitQuantity As String = oRefDoc.ComponentDefinition.BOMQuantity.UnitQuantity

    If baseUnits = "mm" Then
        Dim UQN As Integer = InStrRev(unitQuantity, " ", -1)
        Dim UQ As String = Left(unitQuantity, UQN)

        Dim DIMENSIONI As Double = CDblAny(UQ)
        Dim QTA As String = CStr(CDblAny(UQ) / 1000)

        For i = 1 To Len(QTA)
            If Mid$(QTA, i, 1) = "," Then Mid$(QTA, i, 1) = "."
        Next
        iProperties.Value(System.IO.Path.GetFileName(oRefDoc.FullFileName) , "Custom", "QTA") = QTA
        iProperties.Value(System.IO.Path.GetFileName(oRefDoc.FullFileName) , "Custom", "DIMENSIONI") = DIMENSIONI
    End If
Next

 

 

ts2cad3_0-1649921556275.png

Thanks

 

0 Likes
Accepted solutions (2)
326 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Hi @ts2.cad3.  Just some thoughts...  Have you tried changing the 2 instances of "Mid$(" to "Mid("?  Is it possible that you may have any referenced documents in your assembly that are not saved yet?  If so, then attempting to access the oRefDoc.FullFileName will fail / throw error.  Is it possible that any of the referenced documents might possibly ReadOnly for some reason...like Content Center stuff, or stuff saved in a ReadOnly library type area?  If so, then the lines of code attempting to set new values to the two custom iProperties will fail.  Maybe just for starters, enclose all the code within your loop within a Try...Catch statement, then in the Catch side use a MsgBox() or MessageBox.Show() statement to show what error happened, while letting it continue on to the next referenced document after that point, instead of stopping the whole process.

Something like this, just for some feedback to start with.

 

' Get the active assembly.
Dim oAsmDoc As AssemblyDocument = ThisDoc.Document
'Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oRefDoc As Document
For Each oRefDoc In oAsmDoc.AllReferencedDocuments
	Try
	    Dim baseUnits As String = oRefDoc.ComponentDefinition.BOMQuantity.BaseUnits
	    Dim unitQuantity As String = oRefDoc.ComponentDefinition.BOMQuantity.UnitQuantity
	    If baseUnits = "mm" Then
	        Dim UQN As Integer = InStrRev(unitQuantity, " ", -1)
	        Dim UQ As String = Left(unitQuantity, UQN)
	
	        Dim DIMENSIONI As Double = CDblAny(UQ)
	        Dim QTA As String = CStr(CDblAny(UQ) / 1000)
	
	        For i = 1 To Len(QTA)
	            If Mid(QTA, i, 1) = "," Then Mid(QTA, i, 1) = "."
	        Next
	        iProperties.Value(System.IO.Path.GetFileName(oRefDoc.FullFileName) , "Custom", "QTA") = QTA
	        iProperties.Value(System.IO.Path.GetFileName(oRefDoc.FullFileName) , "Custom", "DIMENSIONI") = DIMENSIONI
	    End If
	Catch oEx As Exception
		MsgBox(oEx.Message & vbCrLf & oEx.StackTrace, vbExclamation, "")
	End Try
Next

 

But if there are tons of referenced documents, and this throws an error for each iteration, that could be really annoying to deal with.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Another thing that comes to mind is that maybe not every referenced document you are looping through is currently open.  I know that normally, when you open an assembly, it also either 'initializes' or opens all of the other documents being referenced by the assembly.  But I'm not 100% sure this is always the case when using things like 'Express Mode (Load Express)' are used ; or when using LODs (LevelOfDetailRepresentations) where every instance of components that represent a referenced document in the assembly may be suppressed.  So, you could use something like If Not oRefDoc.Open Then...followed by a line that opens that document invisibly in the background.  Then, if you had to open it, also use a line to close it (oRefDoc.Close) when done with it (before the end of that loop).  Generally, if the document is not open, you will not be able to write iProperties to it using normal iLogic or Inventor API.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)