Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Drawing Tree Nodes - DoPreSelect not highlighting components Blue in View

Tiffany_Hayden_
Collaborator
Collaborator

Drawing Tree Nodes - DoPreSelect not highlighting components Blue in View

Tiffany_Hayden_
Collaborator
Collaborator

I'm looping through the nodes and it seems like when using the API DoPreSelect that in the tree the node will put the box around the node to identify the node as being PreSelected but the component in the view doesn't highlight blue like when this occurs manually. 

 

The DoSelect works correctly in both manual and API. The tree highlights the node in blue and the components turn a greenish color in the view. 

 

 

TiffanyHaydenSWQYG_0-1654023872937.png

TiffanyHaydenSWQYG_1-1654023989122.png

 

 

 

Tiffany Hayden
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
Reply
Accepted solutions (3)
974 Views
19 Replies
Replies (19)

A.Acheson
Mentor
Mentor

If you run the code right through it will not highlight the views but if you place a message after the pre highlighting you can see the results. The preselected nodes are not stored it would seem. 

If this solved a problem, please click (accept) as solution.ā€Œā€Œā€Œā€Œ
Or if this helped you, please, click (like)ā€Œā€Œ
Regards
Alan
0 Likes

Tiffany_Hayden_
Collaborator
Collaborator

So I put a stop in the code right after the DoPreSelect and it doesn't highlight. A message box would act like a stop in VBA I would assume. 

Tiffany Hayden
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

A.Acheson
Mentor
Mentor

I was using ilogic environment. If you can share the VBA code for this section I can check for the same results here. 

If this solved a problem, please click (accept) as solution.ā€Œā€Œā€Œā€Œ
Or if this helped you, please, click (like)ā€Œā€Œ
Regards
Alan
0 Likes

Tiffany_Hayden_
Collaborator
Collaborator

@A.Acheson 

Here is an example. I was writing an iterative function but I wrote something smaller that dives in from the Sheet/Drawingview/SectionView/Assembly. And does a DoPreSelect on the Assembly. 

 

Public Function PreSelectTest()


    Dim oDrawView As DrawingView: Set oDrawView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Pick View.")
    Dim oDoc As DrawingDocument: Set oDoc = ThisApplication.ActiveDocument
    
    On Error Resume Next
    'Early Exit
    If oDoc Is Nothing Then Exit Function
    
    Dim i As Integer
    Dim oNode As BrowserNode
    Dim oBrowser As BrowserPane
    Dim oSheet As Sheet: Set oSheet = oDrawView.Parent
    Dim oNativeObject As Object
    Dim oSubNodes As BrowserNodesEnumerator
    Dim oSubNode As BrowserNode
    Dim oSubNodes2 As BrowserNodesEnumerator
    Dim oSubNode2 As BrowserNode
    Dim oNativeObject2 As Object
    Dim oSubNodes3 As BrowserNodesEnumerator
    Dim oSubNode3 As BrowserNode
    Dim oNativeObject3 As Object
    
    For Each oBrowser In oDoc.BrowserPanes
        If oBrowser.Name = "Model" Then
            'FIND THE SHEET
            For i = 1 To oBrowser.TopNode.BrowserNodes.Count
                Set oNode = oBrowser.TopNode.BrowserNodes.item(i)

                If Not oNode Is Nothing Then
                    If oNode.BrowserNodes.Count > 0 Then
                        If oNode.BrowserNodeDefinition.Label = oSheet.Name Then
                            Set oSubNodes = oNode.BrowserNodes
                            'FIND THE DRAWING VIEW
                            For Each oSubNode In oSubNodes
                                Set oNativeObject = oSubNode.NativeObject
                                
                                If TypeOf oNativeObject Is DrawingView Then
                                    Set oSubNodes2 = oSubNode.BrowserNodes
                                    'FIND THE SECTION VIEW
                                    For Each oSubNode2 In oSubNodes2
                                        Set oNativeObject2 = oSubNode2.NativeObject
                                        
                                        If TypeOf oNativeObject2 Is SectionDrawingView Then
                                            Set oSubNodes3 = oSubNode2.BrowserNodes
                                            'FIND THE FIRST ASSEMBLY
                                            For Each oSubNode3 In oSubNodes3
                                                Set oNativeObject3 = oSubNode3.NativeObject
                                                
                                                If oNativeObject.DefinitionDocumentType = kAssemblyDocumentObject Then
                                                    'PRESELECT
                                                    oSubNode3.DoPreSelect
                                                    Debug.Print ("stop") 'add stop here to see the PreSelect
                                                End If
                                            Next
                                        End If
                                    Next
                                End If
                            Next
                        End If
                    End If
                End If
            Next
        End If
    Next
    
End Function

  

Tiffany Hayden
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

A.Acheson
Mentor
Mentor

I haven't had a chance to try the vba code but I did use a physical messagebox in the ilogic version in order to slow down and stop the code to allow user Interaction and see the graphics update. You could also try 

 

ThisApplication.UserInterfaceManager.DoEvents()

 

The symptoms look very similar to this post. What is the ultimate goal with the preselect?  

If this solved a problem, please click (accept) as solution.ā€Œā€Œā€Œā€Œ
Or if this helped you, please, click (like)ā€Œā€Œ
Regards
Alan
0 Likes

Tiffany_Hayden_
Collaborator
Collaborator

So I would like the preselect to mimic what is done manually. When you over a selectable node the component will turn blue in the view. The DoSelect works the same both manually and using the API. But the DoPreSelect does not. The blue would be more vibrant for the user than the greenish color using the DoSelect. 

 

I just added this and it doesn't seem to fix the problem. 

 

    oDoc.SelectSet.Clear
    ThisApplication.ActiveView.Update
    For Each oNode In oCollectSelects
        Call oDoc.SelectSet.Select(oNode)
    Next
    Call ThisApplication.UserInterfaceManager.DoEvents
    ThisApplication.ActiveView.Update

 

Tiffany Hayden
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

Tiffany_Hayden_
Collaborator
Collaborator
Accepted solution

Looks like you only have to do this! 

 

oNode.DoPreSelect
ThisApplication.ActiveView.Update

 

The blue starts showing up! 

Tiffany Hayden
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

Tiffany_Hayden_
Collaborator
Collaborator

@A.Acheson Have you ever been successful at multiselect nodes on a drawing? I've used the selectset.SelectMultiple and it doesn't work because the nodes aren't entities. But when you add the oNode.NativeObject that doesn't work either. Just thought I'd ask. 

Tiffany Hayden
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

WCrihfield
Mentor
Mentor
Accepted solution

My next suggestion would be to maybe use a HighlightSet, then specify what specific color you want it to be.  But that would require a lot more processing, because you could not simply add the nodes to it, you would have to add the drawing geometry to it.  You could get the drawing geometry by capturing the node's native object, then using the drawingview's DrawingCurves property, then loop them, adding them to an ObjectCollection.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

Tiffany_Hayden_
Collaborator
Collaborator

@WCrihfield Would it be something like this? 

 

    Dim oDrawCurves As DrawingCurvesEnumerator
    Dim oHSet  As HighlightSet
    
    For Each oNode In oCollectSelects
        Set oDrawCurves = GetOccDrawingCurves(oDrawView, oNode.NativeObject)
        Set oHSet = oDoc.CreateHighlightSet
        Call oHSet.AddItem(oDrawCurves)
        oHSet.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)

    Next

Tiffany Hayden
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

WCrihfield
Mentor
Mentor

I wasn't able to throw together a proper example of this in VBA before I leave, but I created some iLogic code that contains most of the process for doing what I was suggesting.  I am not including a proper way to identify the BrowserNode to represent the one you were trying the pre-select thing on.  This code also assumes that this browser node is representing an assembly component.

Sub Main
	oDDoc = ThisDrawing.Document
	oMPane = oDDoc.BrowserPanes.Item("Model")
	'oObj = oDDoc.SelectSet.Item(1)
	
	'<<<< set a value here, one way or another >>>>
	Dim oCompNode As BrowserNode = Nothing
	'oCompNode = oMPane.GetBrowserNodeFromObject(oObj)
	'oCompNode = oObj
	
	Dim oComp As ComponentOccurrence = Nothing
	Dim oParentView As DrawingView = Nothing
	Try
		If TypeOf oCompNode.NativeObject Is ComponentOccurrence Then
			oComp = oCompNode.NativeObject
			oParentView = FindNodeParentView(oCompNode)
		End If
	Catch
	End Try
	If IsNothing(oComp) Or IsNothing(oParentView) Then Exit Sub
	Dim oDCurves As DrawingCurvesEnumerator = Nothing
	Try
		oDCurves = oParentView.DrawingCurves(oComp)
	Catch
		Exit Sub
	End Try
	Dim oTO As TransientObjects = ThisApplication.TransientObjects
	Dim oObjColl As ObjectCollection = oTO.CreateObjectCollection
	For Each oDCurve As DrawingCurve In oDCurves
		oObjColl.Add(oDCurve)
	Next
	Dim oHLSet As HighlightSet = oDDoc.CreateHighlightSet
	oHLSet.AddMultipleItems(oObjColl)
	oHLSet.Color = oTO.CreateColor(0, 255, 0)
End Sub

Function FindNodeParentView(oInputNode As BrowserNode) As DrawingView
	If TypeOf oInputNode.Parent Is BrowserPane Then Return Nothing
	If TypeOf oInputNode.Parent Is BrowserNode Then
		Dim oParentNode As BrowserNode = oInputNode.Parent
		Try 'sometimes checking NativeObject throws Error
			If TypeOf oParentNode.NativeObject Is DrawingView Then
				Dim oDView As DrawingView = oParentNode.NativeObject
				Return oDView
			Else
				FindNodeParentView(oParentNode)
			End If
		Catch
		End Try
	End If
	Return Nothing
End Function

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

Tiffany_Hayden_
Collaborator
Collaborator

Great Thank you I'll check it out! 

Tiffany Hayden
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

Tiffany_Hayden_
Collaborator
Collaborator

@WCrihfield Would you know why I can't use the NativeObject of the node to get the drawing curves. I'm getting an error when I try to get the drawing curves for the native object. Even though it's a component occurrence. 

 

    Dim oDrawCurve As DrawingCurve
    Dim oDrawCurves As DrawingCurvesEnumerator
    Dim oHSet  As HighlightSet
    Dim oCollectCurves As ObjectCollection: Set oCollectCurves = ThisApplication.TransientObjects.CreateObjectCollection
    Dim oOccNode As ComponentOccurrence
    
    For Each oNode In oCollectSelects
        Set oOccNode = oNode.NativeObject
        Set oDrawCurves = oDrawView.DrawingCurves(oOccNode) 'GetOccDrawingCurves(oDrawView, oOccNode) '


    Next

 

TiffanyHaydenSWQYG_0-1654116802092.png

TiffanyHaydenSWQYG_1-1654116821263.png

 

Tiffany Hayden
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

A.Acheson
Mentor
Mentor

If I am not mistaken you should be setting a Drawing curve rather than setting a collection 

 

 Set oDrawCurve = oDrawView.DrawingCurves(oOccNode)

Syntax

 

DrawingCurvesEnumerator.Item( Index As Long ) As DrawingCurve

 

Here is a post that may help you out some bit. 

If this solved a problem, please click (accept) as solution.ā€Œā€Œā€Œā€Œ
Or if this helped you, please, click (like)ā€Œā€Œ
Regards
Alan
0 Likes

Tiffany_Hayden_
Collaborator
Collaborator

It looks like it's set right. I wonder if there is something wrong with using the component occurrence from a node it doesn't like. Even though the native object from a node, in this case, is a component occurrence, it should be able to be used in this situation. 

 

TiffanyHaydenSWQYG_0-1654169558789.png

 

Tiffany Hayden
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

Tiffany_Hayden_
Collaborator
Collaborator
Accepted solution

@A.Acheson @WCrihfield 

Found a solution using the highlight. 

Steps: 

- Collect all parts/Assemblies in the view as componentoccurrenceproxy's. 

- compare the node to the parts in the collection. Part.nativeobject. Comparing ComponentOccurrence to ComponentOccurence. 

- Loop through the nodes. Once you get the component occurrence proxy, use that to get the drawing curves. 

- Loop through the drawing curves and then loop through the segments on the drawing curves. 

- Add the segments to the collection

- create a highlightset 

- Use the AddMultipleItems on the HighLightSet to add the collection of segments

- Change the color of the set (If needed). 

 

The trick for me was using the componentoccurrenceproxy instead of the NativeObject from the node. You have to use a proxy if you are doing sub/nodes. Nodes within nodes. 

 

    Dim oCollectComps As ObjectCollection: Set oCollectComps = CollectOcc_Iterative(oDrawView, kPartDocumentObject)
    Dim oOcc As ComponentOccurrence
    Dim oDrawCurve As DrawingCurve
    Dim oDrawCurveSeg As DrawingCurveSegment
    Dim oDrawCurves As DrawingCurvesEnumerator
    Dim oCollectCurves As ObjectCollection: Set oCollectCurves = ThisApplication.TransientObjects.CreateObjectCollection
    Dim oHSet As HighlightSet
    
    
    For Each oNode In oCollectSelects
        Set oNativeObject = oNode.NativeObject
    
        For Each oOcc In oCollectComps
            If oOcc.NativeObject Is oNativeObject Then
                Set oDrawCurves = oDrawView.DrawingCurves(oOcc)
                For Each oDrawCurve In oDrawCurves
                    For Each oDrawCurveSeg In oDrawCurve.Segments
                        Call oCollectCurves.Add(oDrawCurveSeg)
                    Next
                Next
            End If
        Next
        
    Next
    
    Set oHSet = oDoc.CreateHighlightSet
    oHSet.Clear
    Call oHSet.AddMultipleItems(oCollectCurves)
    oHSet.Color = ThisApplication.TransientObjects.CreateColor(0, 255, 0)

 

 

 

Tiffany Hayden
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

Tiffany_Hayden_
Collaborator
Collaborator

@A.Acheson @WCrihfield 

 

Thanks for all your help! 

Tiffany Hayden
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

WCrihfield
Mentor
Mentor

I totally spaced on the proxy thing concerning the node's returned component object.  Should have tested TypeOf against both ComponentOccurrence and for ComponentOccurrenceProxy, then maybe not declared the variable's Type beforehand so it could hold either one.  Sometimes it seems like I'm trying to contemplate 10 different things at once, then end up making those kinds of mistakes.  I knew you would figure it out though. šŸ˜‰

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Tiffany_Hayden_
Collaborator
Collaborator

@WCrihfield  Thanks! It took a lot of forum searches and piecing stuff together! lol But that's programming life. 

Tiffany Hayden
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