Hello! I would like to access right click menu in drawing design tree
and restrict users for not to delete drawing blocks from design tree manager
Is it possible, if yes then how should I write API for it
Attached screen image for your reference.
my code is as below: ------------
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Public bol1 As Boolean
Public mystr As String
Sub main()
Dim RootNode As SldWorks.TreeControlItem
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager
Set FeatureMgr = Part.FeatureManager
Set RootNode = FeatureMgr.GetFeatureTreeRootItem()
Traverse_Nodes RootNode, 1
FeatureMgr.Select True
End Sub
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub Traverse_Nodes(node As SldWorks.TreeControlItem, Level As Integer)
Dim Childnode As SldWorks.TreeControlItem
Dim Cnode As SldWorks.TreeControlItem
Dim Feat As SldWorks.Feature
Dim FeatTypeName As String
Dim comp As SldWorks.Component2
Dim CompDoc As SldWorks.DrawingDoc
Dim Indent As String
Indent = Space(Level * 4)
Set Childnode = node.GetFirstChild
If Childnode Is Nothing Then
'An empty folder causes an empty node
Debug.Print " Empty Folder"
End If
While Not Childnode Is Nothing
'If the node is a feature type is 1
If Childnode.ObjectType = 1 Then
Set Feat = Childnode.Object
FeatTypeName = Feat.GetTypeName
'If the feature is a folder with part in it or a pattern with parts in it
'If FeatTypeName = "FtrFolder" Or InStr(FeatTypeName, "Pattern") > 0 Then
If FeatTypeName = "BlockFolder" Or FeatTypeName = "SketchBlockDef" Then
' If FeatTypeName = "SketchBlockDef" Then
'Prints the name of the folder and goes through the components
Debug.Print Childnode.Text
If Childnode.Text <> "Blocks" Then
Feat.DeSelect
End If
Traverse_Nodes Childnode, Level + 1
End If
'If the node is a component
ElseIf Childnode.ObjectType = 2 Then
Set comp = Childnode.Object
Debug.Print Indent & comp.Name2
Set Cnode = Childnode.GetFirstChild
Set CompDoc = comp.GetModelDoc
'This get parts and mates in subassemblies
If Not CompDoc Is Nothing Then
If CompDoc.GetType = 2 Then
'This loops through subassemblies
'To get Sub Comps unremark next line.
'Traverse_Nodes Childnode, Level + 1 'XXXXXXXXXXXXXXXXXXXXXXXXX
End If
End If
Else
Debug.Print Indent & "Not Sure of node type"
End If
NoSubs:
Set Childnode = Childnode.GetNext
Wend
End Sub
SolidworksApi macros