Just looking for some advice on how to best handle errors with iLogic.
For example I want to use FirstModelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.Full
You can use a lot of VB.Net commands in iLogic, one thing to do is check to see if the string is empty before proceeding.
Sub Main Dim FirstModelName As String = getmodelname(ThisApplication.ActiveDocument) If Not String.IsNullOrEmpty(FirstModelName) Then 'do what you want with the value returned MsgBox(FirstModelName) End If End Sub 'function to return the referenced document full name Private Function getModelName(ByVal oDrawDoc As DrawingDocument) As String If oDrawDoc.ActiveSheet.DrawingViews.Count > 0 Then Dim oView As DrawingView = oDrawDoc.ActiveSheet.DrawingViews.Item(1) Return oView.ReferencedDocumentDescriptor.FullDocumentNam
e End If Return Nothing End Function
you can also use the Try Catch function in iLogic to handle the errors:
using the same function as above.
Sub Main Try Dim FirstModelName As String = getmodelname(ThisApplication.ActiveDocument) If String.isnullorempty(FirstmodelName) Then Throw New Exception("No Base View in Active Drawing") End If 'do what you want with the value returned MsgBox(FirstModelName) Catch ex As Exception ' if you do not want to see the error just remove the MsgBox MsgBox(ex.Message) End Try End Sub
Access a broad range of knowledge to help get the most out of your products and services.