cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

VB API cast selected table to ITable

AlexCote
7-Bedrock

VB API cast selected table to ITable

Hi,

I am doing a little program in which the user will select a table in a drawing, and then the program will read that table and extract information and do stuff with it.

My problem is that I can't figure out how to cast the selected object to a table object.

Here's how I launch the selection process:

 

 

 

	Private Sub BtnSelectTable_Click(sender As Object, e As EventArgs) Handles BtnSelectTable.Click
		Try
			Dim SelectedTable As IpfcSelections = SelectFeatures(theBaseSession)

			For i = 0 To SelectedTable.Count - 1
				Dim CurrTbl As IpfcTable = SelectedTable.Item(i)
				MsgBox(CurrTbl.GetRowCount)
			Next


		Catch ex As Exception
			MsgBox(ex.Message & vbNewLine & vbNewLine & ex.StackTrace,, GetCurrentMethod().Name)
		End Try
	End Sub

 

 

 

Here's how I select the drawing table (comes from the PTC supplied example):

 

 

 

	Public Function SelectFeatures(ByVal session As IpfcBaseSession) As IpfcSelections
		Dim selections As IpfcSelections
		Dim selectionOptions As IpfcSelectionOptions

		Try

			'======================================================================
			'Selection options are set to select only features with a specified max
			'number.
			'======================================================================
			selectionOptions = (New CCpfcSelectionOptions).Create("dwg_table")
			selections = session.Select(selectionOptions, Nothing)

			SelectFeatures = selections

		Catch ex As Exception
			MsgBox(ex.Message.ToString + Chr(13) + ex.StackTrace.ToString)
			Return Nothing
		End Try
	End Function

 

 

 

I can confirm that the selection works, if I select somethings I can get a correct COUNT of how many object I have selected.

The problem is that when I try to cast the selected object to any kind of table object to be able to work with it I get casting error:

image.png

Any idea?

1 ACCEPTED SOLUTION

Accepted Solutions

Finally found something that works ...

	Private Sub BtnSelectTable_Click(sender As Object, e As EventArgs) Handles BtnSelectTable.Click
		Try
			Dim SelectedTable As IpfcSelections = SelectFeatures(theBaseSession)

			For i = 0 To SelectedTable.Count - 1
				Dim TmpCurrTbl As IpfcSelection = SelectedTable.Item(i)
				Dim CurrTbl As IpfcTable = TmpCurrTbl.SelItem
				MsgBox(CurrTbl.GetRowCount)
			Next


		Catch ex As Exception
			MsgBox(ex.Message & vbNewLine & vbNewLine & ex.StackTrace,, GetCurrentMethod().Name)
		End Try
	End Sub

The "SelectedTable.Item(i)" is returning an object of type IpfcSelection (notice the missing S at the end). This object then return an handle to the item, and can be set to the type of object you need.

View solution in original post

1 REPLY 1

Finally found something that works ...

	Private Sub BtnSelectTable_Click(sender As Object, e As EventArgs) Handles BtnSelectTable.Click
		Try
			Dim SelectedTable As IpfcSelections = SelectFeatures(theBaseSession)

			For i = 0 To SelectedTable.Count - 1
				Dim TmpCurrTbl As IpfcSelection = SelectedTable.Item(i)
				Dim CurrTbl As IpfcTable = TmpCurrTbl.SelItem
				MsgBox(CurrTbl.GetRowCount)
			Next


		Catch ex As Exception
			MsgBox(ex.Message & vbNewLine & vbNewLine & ex.StackTrace,, GetCurrentMethod().Name)
		End Try
	End Sub

The "SelectedTable.Item(i)" is returning an object of type IpfcSelection (notice the missing S at the end). This object then return an handle to the item, and can be set to the type of object you need.

Top Tags