- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am trying to create an addin that aligns a bunch of drawingviews.
For doing this I cycle through the selectset and check if the object is a drawingview, sectionview or detailview.
The piece of code below shows what I am doing
For a = 1 To ss.Count
' When testing I found some objects that have a value of nothing and no type, they cause an error. Skip this error - should check this
On Error Resume Next
If ss.Item(a).Type = kDrawingViewObject Or ss.Item(a).Type = kSectionDrawingViewObject Or ss.Item(a).Type = kDetailDrawingViewObject Then
If Err Then
' catch the error and do nothing if it is found
Else
' If the item is a view object then set it
Set oview = ss.Item(a)
' The views found in this loop are the views that have to be aligned to eachother
' Store them in an array by combining them into a string
viewCol(b) = (oview.Position.x & ";" & oview.Position.y)
' b is the counter for when an actual view is found
b = b + 1
' Save the first views width and height
If b = 1 Then
height1 = oview.Height
width1 = oview.Width
End If
End If
End If
Next
I have included a screenshot of the contents of the selectset. As you can see some items have the value 'Nothing', these items are the definitions of section/detail views. When checking their type I get an error because the object doesn't have a type, it is nothing. (generic object)
In VBA i solved this by doing what I did in the piece of code above, I check if there is an error and do nothing, but I can still continue with the rest of the code without errors.
Now I am trying to convert my code to VB.Net and I am using a try, catch statement as follows, in this case the entire script will be stopped if i put the catch statement at the bottom, the code will give an error but proceed doing the rest when I put the catch at the end of the for loop;
Try
For a = 1 To ss.Count
' When testing I found some objects that have a value of nothing and no type, they cause an error. Skip this error - should check this
If ss.Item(a).Type = ObjectTypeEnum.kDrawingViewObject Or ss.Item(a).Type = ObjectTypeEnum.kSectionDrawingViewObject Or ss.Item(a).Type = ObjectTypeEnum.kDetailDrawingViewObject Then
' If the item is a view object then set it
oview = ss.Item(a)
' The views found in this loop are the views that have to be aligned to eachother
' Store them in an array by combining them into a string
viewCol(b) = (oview.Position.X & ";" & oview.Position.Y)
' b is the counter for when an actual view is found
b = b + 1
' Save the first views width and height
If b = 1 Then
height1 = oview.Height
width1 = oview.Width
End If
End If
Next
' If b is still 0 there were no views selected
If b = 0 Then
MsgBox("No views selected!", vbCritical)
Exit Sub
ElseIf b = 1 Then
MsgBox("Only one view selected!", vbCritical)
Exit Sub
End If
'THIS CATCH IS PROBABLY HAPPENING BECAUSE THERE ARE 'GENERICOBJECTS' IN THE SELECTION, THEY HAVE NO TYPE
'I THINK IT IS THE DEFINITION OF THE SECTION/DETAIL VIEW CAUSING TROUBLE
Catch ex As Exception
'MessageBox.Show(ex.ToString)
'Stop
MsgBox("Invalid selection!")
End Try
Which leads to my question(s):
Can you prevent this from happening in a way that I did in VBA? Or is there a way to use On error resume next in VB NET? Or is there a way of identifying an object which has no type before I check if it is one of the 3 drawingviewobjects?
Or do I need to use the try..catch statements completely differently?
Thanks in advance
Solved! Go to Solution.