Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic - Handling Errors?

2 REPLIES 2
Reply
Message 1 of 3
mthomas
3255 Views, 2 Replies

iLogic - Handling Errors?

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

 

Mike Thomas

2 REPLIES 2
Message 2 of 3
BMiller63
in reply to: mthomas

You might want to post questions of this nature here:

Autodesk Inventor Customization

Message 3 of 3
Mike.Wohletz
in reply to: mthomas

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.

Post to forums