ActiveEditDocument.SelectSet Issue

ActiveEditDocument.SelectSet Issue

jakevZWHTE
Explorer Explorer
1,669 Views
5 Replies
Message 1 of 6

ActiveEditDocument.SelectSet Issue

jakevZWHTE
Explorer
Explorer

Hi, Could I get some help with ActiveEditDocument.SelectSet? When working in a part document my script works fine, but when editing a part from an assembly it doesn't seem to work.

Sub Main
	Dim doc As PartDocument
	If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		If ThisApplication.ActiveEditDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject
			doc = ThisApplication.ActiveEditDocument
		Else
			Return
		End If
	Else If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		doc = ThisApplication.ActiveDocument
	End If
	If doc IsNot Nothing
		Dim obj As Object
		obj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Entity")
	 	For Each oFace In doc.ComponentDefinition.SurfaceBodies(1).Faces
			If (oFace.SurfaceType = CType(obj, Face).SurfaceType) And (Math.Round(oFace.Evaluator.Area, 6) = Math.Round(CType(obj, Face).Evaluator.Area, 6))
			doc.SelectSet.Select(oFace)
			End If
		Next
	End If
End Sub

 

0 Likes
1,670 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @jakevZWHTE.  My memory in that area may be a little rusty, but I believe the 'active' document will always receive the selections, by default, when using the 'Pick' function, even when you are in-place editing a component representing a part, within an assembly, which would make that part the 'active editing' document, because the assembly will still be the 'active' document, as you already seem to know.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

jakevZWHTE
Explorer
Explorer

Thanks for your reply @WCrihfield, when I try to add a property to ActiveDocument.SelectSet when editing part from an assembly, then it throws error "The parameter is incorrect". 

ThisApplication.ActiveDocument.SelectSet.Select(oFace)

The issue doesn't seem to be with parts getting added to doc.SelectSet. I can see parts are getting selected by adding MessageBox

MessageBox.Show(doc.SelectSet.Count & " Selected")

 The problem seems to be that the objects don't stay selected the way they do when part document is open.

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

Yes, I did a little local testing right after replying, and see what you mean.  I assumed it might be a 'context' related issue, or cross-document thing.  Besides the SelectSet.Select method, I also used a HighlightSet, and used its AddItem method on the same face, then showed a MsgBox for the user to review it, then used Clear method after message goes away, but still no indication / proof of the selection.  It is an odd situation to be using 'selection' on a non-active document, so I assume you are wanting to execute a command on something, in an effort to 'simulate' a manual user interaction sequence.

 

If there is a way to do what you want to do using Inventor API code then that is almost always the preferred route, instead of selection and command execution.  But there are a couple cases where it seems like the commands (ControlDefinitions) designed by Autodesk can 'process' certain tasks more efficiently than the API route can.

What are you trying to do with the face, after it is selected?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

jakevZWHTE
Explorer
Explorer

after the faces are selected I will use Direct Edit to modify. The reason why I use this script is just to rapidly select all faces of the same type and area.

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Ah, I see.  Although there are API objects for those types of features, and we can access the ones that already exist by API, we do not seem to be able to create new ones through the API, so unfortunately selection and command execution route may be the only way to automate a task like that.  You may have to 'open' (rather than in-place edit) that part directly/visibly to make it work though, not sure.  Good luck with that. 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes