Object Reference not set to instance of an object - Surface Body Collection

Object Reference not set to instance of an object - Surface Body Collection

David.Berken
Participant Participant
490 Views
2 Replies
Message 1 of 3

Object Reference not set to instance of an object - Surface Body Collection

David.Berken
Participant
Participant

I am trying to make a custom picked list of surface bodies to export and derive as individual components. I can get it to work for all surface bodies but want to make something where the user can pick the individual surface bodies and only export them. I get an error of object reference not set to instance of an object at the Got Here message. Any help would be greatly appreciated.

 

	Dim CustomPartCollection As ObjectCollection
	
	Dim PickParts As Integer
	PickParts = MessageBox.Show("Do you want to pick individual parts", "Pick Parts", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
	
	Dim sb1 As Object
	
	Dim c As Integer
	c=0
	
	If PickParts = vbYes Then
		
		Dim Cancel As Boolean
		Cancel = False
		
		Do While Cancel = False
			Question = MessageBox.Show("Do you wish to pick another Solid Body?", "Pick Parts", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
			If Question = vbYes Then
				sb1 = ThisApplication.CommandManager.Pick(kPartBodyFilter, "Pick Solid Body to Export")
				'MsgBox("Got Here")
				Call CustomPartCollection.Add(sb1)
				c = c + 1
			Else
				Cancel = True
			End If
		Loop
0 Likes
Accepted solutions (1)
491 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

You did not create an object collection.

 

Dim CustomPartCollection As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()

Dim PickParts As Integer
PickParts = MessageBox.Show("Do you want to pick individual parts", "Pick Parts", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

Dim sb1 As Object

Dim c As Integer = 0

If PickParts = vbYes Then

    Dim Cancel As Boolean = False

    Do While Cancel = False
        Dim Question = MessageBox.Show("Do you wish to pick another Solid Body?", "Pick Parts", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        If Question = vbYes Then
            sb1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick Solid Body to Export")
            'MsgBox("Got Here")
            Call CustomPartCollection.Add(sb1)
            c = c + 1
        Else
            Cancel = True
        End If
    Loop
End If

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

David.Berken
Participant
Participant
Thank you so much! I knew it had to be something simple
0 Likes