Select set problem

Select set problem

Anonymous
Not applicable
951 Views
6 Replies
Message 1 of 7

Select set problem

Anonymous
Not applicable

This code works in a main assembly but it doesnt work if the sketch is in a subassembly. I think it is about selecting parts in context of a assembly. Here is the picture of the situation where the rule is used. Any help please?

 

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument

Dim oObject As Object
oObject = ThisApplication.ActiveEditObject

Dim oSelectSet As SelectSet
oSelectSet = oDoc.SelectSet

If oObject.Type = ObjectTypeEnum.kPlanarSketchObject Then
	For Each oEntity In oObject.SketchEntities
		
		If oEntity.ConstraintStatus = 51716 Or oEntity.ConstraintStatus = 51715 Then
			'kUnknownConstraintStatus
			'kOverConstrainedConstraintStatus
			oSelectSet.Select(oEntity)
		End If	
	Next
	
	For Each oEntity In oObject.SketchEntities
	If oEntity.Type = 83896576 Then
		'kSketchPointObject	
		If oEntity.Reference = True Then
			oSelectSet.Select(oEntity)
		End If
	End If
	Next
End If

 

0 Likes
Accepted solutions (1)
952 Views
6 Replies
Replies (6)
Message 2 of 7

Martin-Winkler-Consulting
Advisor
Advisor

You are in edit mode of the sketch or/and the included Part.

Have a look wether the select object of the main assembly have members within this status.

Try selecting the sketch without edit mode.

Martin Winkler
CAD Developer
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

0 Likes
Message 3 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

It's a bit complex to do it this way since you want to access the sketch from the top assembly. You'll have to create a proxy object of the sketch in the top assembly in order to select entities from it with the top assemblys select set.

 

I wrote this for you. Hope it helps 🙂

 

Sub Main
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oObject As Object
oObject = ThisApplication.ActiveEditObject

Dim oSelectSet As SelectSet
oSelectSet = oDoc.SelectSet



If oObject.Type = ObjectTypeEnum.kPlanarSketchObject Then
	Dim oSketchProx As Object = CreateSketchProxy(oDoc.ComponentDefinition.ActiveOccurrence.OccurrencePath, oObject.Name)
	For Each oEntity In oSketchProx.SketchEntities
		
		If oEntity.ConstraintStatus = 51716 Or oEntity.ConstraintStatus = 51715 Then
			'kUnknownConstraintStatus
			'kOverConstrainedConstraintStatus
			oSelectSet.Select(oEntity)
		End If	
	Next
	
	For Each oEntity In oSketchProx.SketchEntities
	If oEntity.Type = 83896576 Or oEntity.Type = kSketchPointProxyObject Then 'Its now a sketchpointproxy
		'kSketchPointObject	
		If oEntity.Reference = True Then
			
			oSelectSet.Select(oEntity)
		End If
	End If
	Next
End If
End Sub
Function CreateSketchProxy(oOccList As ComponentOccurrencesEnumerator, oSketchName As String) As Object
	Dim oProx As Object
	For i = oOccList.Count To 1 Step -1
		If i = oOccList.Count
			Call oOccList(i).CreateGeometryProxy(oOccList(i).Definition.Sketches.Item(oSketchName), oProx)
		Else
			Call oOccList(i).CreateGeometryProxy(oProx, oProx)
		End If

	Next
	Return oProx
End Function
0 Likes
Message 4 of 7

Anonymous
Not applicable

Ok this is the solution but this is one complex code.....

Message 5 of 7

JhoelForshav
Mentor
Mentor

Yes, working with objects within occurrences from the containing assembly can be a bit complex since you have to set up a proxy for them. The assembly itself contains only a structure with references to other parts/assemblies. Therefore these objects doesn't really exist within the assembly so you have to create proxies to reference them.

In the UI this is done automatically when you select the objects.

The function I've written here (CreateSketchProxy) might look a bit complex, but it's written that way in order to be able to dig up proxies from all levels. The rest of the code is basically the same as the one you posted to begin with 🙂

0 Likes
Message 6 of 7

Anonymous
Not applicable

I always struggle with using proxies, I read abou them (https://adndevblog.typepad.com/manufacturing/2013/07/occurrences-contexts-definitions-proxies.html)

but i just don't understand how to use them in situaions like this one. A lot of my questions on the forum are about using proxies.

Anyway, here is the rest of my code in VBA. I will use it to clear sketshes of broken geometry enteties. 

 

Sub ClearSketch_CLEAR()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oObject As Object
Set oObject = ThisApplication.ActiveEditObject

Dim oSelectSet As SelectSet
Set oSelectSet = oDoc.SelectSet

If oObject.Type = ObjectTypeEnum.kPlanarSketchObject Then
    Dim oSketchProx As Object
    If oDoc.FullDocumentName = oObject.Parent.Document.FullDocumentName Then
        Set oSketchProx = ThisApplication.ActiveEditObject
    Else
        Set oSketchProx = CreateSketchProxy(oDoc.ComponentDefinition.ActiveOccurrence.OccurrencePath, oObject.Name)
    End If

    For Each oentity In oSketchProx.SketchEntities
        If oentity.ConstraintStatus = 51716 Or oentity.ConstraintStatus = 51715 Then
            'kUnknownConstraintStatus
            'kOverConstrainedConstraintStatus
            oSelectSet.Select (oentity)
        End If
    Next
    
    For Each oentity In oSketchProx.SketchEntities
    If oentity.Type = 83896576 Or oentity.Type = kSketchPointProxyObject Then 'Its now a sketchpointproxy
        'kSketchPointObject
        If oentity.Reference = True Then
            oSelectSet.Select (oentity)
        End If
    End If
    Next
    ThisApplication.CommandManager.ControlDefinitions.Item("BreakLinkCmd").Execute2 (True)
    ThisApplication.ActiveDocument.Update
End If
End Sub

Function CreateSketchProxy(oOccList As ComponentOccurrencesEnumerator, oSketchName As String) As Object
    Dim oProx As Object
    For i = oOccList.Count To 1 Step -1
        If i = oOccList.Count Then
            Call oOccList(i).CreateGeometryProxy(oOccList(i).Definition.Sketches.Item(oSketchName), oProx)
        Else
            Call oOccList(i).CreateGeometryProxy(oProx, oProx)
        End If
    Next
    Set CreateSketchProxy = oProx
End Function

 

Message 7 of 7

JhoelForshav
Mentor
Mentor

I get that. I actually did my masters thesis on the subject of building product configurators in Inventor. The use of proxies in assembly constraints etc. drove me crazy back then😅

 

Thanks for sharing the complete code! Im sure it'll come in handy for a lot of people here! 🙂