Inventor Customization

Inventor Customization

Reply
*Expert Elite*
mthomas
Posts: 303
Registered: ‎06-17-2010
Message 1 of 3 (954 Views)

iLogic - Handling Errors?

954 Views, 2 Replies
12-16-2010 07:24 AM

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

**Master
BMiller63
Posts: 2,533
Registered: ‎01-28-2009
Message 2 of 3 (951 Views)

Re: iLogic - Handling Errors?

12-16-2010 07:27 AM in reply to: mthomas

You might want to post questions of this nature here:

Autodesk Inventor Customization

Valued Mentor
Mike.Wohletz
Posts: 376
Registered: ‎07-29-2008
Message 3 of 3 (897 Views)

Re: iLogic - Handling Errors?

12-18-2010 11:56 AM 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

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.