Community
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.FullFileName). It works if there is a view in the drawing. However what would be the best procedure to check if there is actually a view in the drawing?
Thanks
You might want to post questions of this nature here:
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.FullDocumentName 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
Can't find what you're looking for? Ask the community or share your knowledge.