Vba function to find the name of a solid parent

Vba function to find the name of a solid parent

Anonymous
Not applicable
524 Views
2 Replies
Message 1 of 3

Vba function to find the name of a solid parent

Anonymous
Not applicable

Hello,

With a macro in VBA, I want to recover the name of the original solid D-X7001_.Gen.cen and thus rename the new solids created.

1.PNG

 

 

 

 

Objectif: 

solid72 becomes D-X7001_.Gen.cen.id1  

solid74 becomes  D-X7001_.Gen.cen.id2

solid75 becomes  D-X7001_.Gen.cen.id2 ....


4.PNG

with AffectedByFeatures .name I manage to find the function of first level (ex: scission3)
but I cannot find the method to be able to go further in the tree structure

what's method to use, please?

 

Thanks for your help

 

0 Likes
525 Views
2 Replies
Replies (2)
Message 2 of 3

marcin_otręba
Advisor
Advisor

hi,

 

Try this:

It will find last solid body in tree.

Sub main()
	On Error Resume Next
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument


    Dim oPane As BrowserPane
    Set oPane = oDoc.BrowserPanes.Item("Model")
    Dim onode As BrowserNode
	For Each onode In oPane.TopNode.BrowserNodes.Item(2).BrowserNodes
		name = get_name(onode, onode)
		MessageBox.Show(name, "Title")
	Next
End Sub
Function get_name(onode As BrowserNode, lastnode As BrowserNode)
		For Each onode1 As BrowserNode In onode.BrowserNodes
			If onode1.NativeObject.type = 67118896 Or onode1.NativeObject.type = 83915776 Or onode1.NativeObject.type = 50385152 Then
					get_name(onode1, onode)
		    End If
			If onode1.NativeObject.type <> 67118896 And onode1.NativeObject.type <> 83915776 And onode1.NativeObject.type <> 50385152 Then
				get_name = lastnode.fullpath
				Exit For			
			End If
		
		Next
End Function

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

Message 3 of 3

Anonymous
Not applicable

Thank you very much for your quick and accurate response.

t is very interesting and I had not thought of nodes,I did not know.

 

I will test and come back to you to give you a report.

0 Likes