How do you determine if selected part in drawing is a toolbox part or not in API Macro? Does swToolBoxPartType_e work the same in a drawing? I need my macro to skip all toolbox parts but skip normal parts/assemblies.
How do you determine if selected part in drawing is a toolbox part or not in API Macro? Does swToolBoxPartType_e work the same in a drawing? I need my macro to skip all toolbox parts but skip normal parts/assemblies.
This code will give you an info that in Drawing View1 which component is Tooolbox part.
It will check only Top level component for Sub Assembly we need to change the logic.. Cheers!
Dim swApp As Object
Dim Part As ModelDoc2
Dim swDrw As DrawingDoc
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swDrw = Part
boolstatus = Part.ActivateView("Drawing View1")
boolstatus = Part.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0.60929, 0.64133, 0, False, 0, Nothing, 0)
Dim swView As View
Set swView = Part.SelectionManager.GetSelectedObject6(1, -1)
Dim RootDrwComp As DrawingComponent
Set RootDrwComp = swView.RootDrawingComponent
Dim vDrawChildCompArr As Variant
vDrawChildCompArr = RootDrwComp.GetChildren
Dim vDrawChildComp As Variant
For Each vDrawChildComp In vDrawChildCompArr
Dim swDrawComp As DrawingComponent
Set swDrawComp = vDrawChildComp
Dim swComp As Component2
Set swComp = swDrawComp.Component
Dim swCompModel As ModelDoc2
Set swCompModel = swComp.GetModelDoc2
Dim Bret As Boolean
Bret = swCompModel.Extension.ToolboxPartType '>>>Return Value is True then Component is ToolBox Part
Next
End Sub
Thanks,
How would i do it on a single selected part...? i.e. An already selected single part in a view.
Instead of selecting the component in view, Select the component in drawing Feature manager tree and run this Below code.
Dim swApp As Object
Dim Part As ModelDoc2
Dim swDrw As DrawingDoc
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swDrw = Part
Dim DwgDoc As DrawingComponent
Set DwgDoc = Part.SelectionManager.GetSelectedObject6(1, -1)
Dim swComp As Component2
Set swComp = DwgDoc.Component
Dim swCompModel As ModelDoc2
Set swCompModel = swComp.GetModelDoc2
Dim Bret As Boolean
Bret = swCompModel.Extension.ToolboxPartType 'Return Value is True then Component is ToolBox Part
End Sub
That works well selecting the part in the drawing feature manager tree, but i need to read it as a user selecting a part in a view on the drawing.
Open your drawing >Select component entity like edge, vertex > Try this out
Dim swApp As Object
Dim Part As ModelDoc2
Dim swDrw As DrawingDoc
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swDrw = Part
Dim cnt As Integer
cnt = Part.SelectionManager.GetSelectedObjectCount 'Always get the count before getting Edge,Vertex etc... object
Dim objtyp As Long
objtyp = Part.SelectionManager.GetSelectedObjectType3(2, 0)
Dim Ent As Entity
Set Ent = Part.SelectionManager.GetSelectedObject6(2, 0)
Dim swComp As Component2
Set swComp = Ent.GetComponent
Dim swCompModel As ModelDoc2
Set swCompModel = swComp.GetModelDoc2
Dim Bret As Boolean
Bret = swCompModel.Extension.ToolboxPartType 'Return Value is True then Component is ToolBox Part
End Sub
Awesome, it works ...however selecting a cylinder round "edge" crashes? Selecting a cylinders face & end edge works. Is there a different getselected object for that type of selections?
Ya Its silhouette edge. Try this code, hope will work fine .. Cheers
Dim swApp As Object
Dim Part As ModelDoc2
Dim swDrw As DrawingDoc
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Ent As Entity
Dim swComp As Component2
Dim swCompModel As ModelDoc2
Dim Bret As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swDrw = Part
Dim cnt As Integer
cnt = Part.SelectionManager.GetSelectedObjectCount 'Always get the count before getting Edge,Vertex..etc object
Dim objtyp As Long
objtyp = Part.SelectionManager.GetSelectedObjectType3(2, 0)
If objtyp = 46 Then 'It will work for Cylindrical round edge
Dim SilEdge As SilhouetteEdge
Set SilEdge = Part.SelectionManager.GetSelectedObject6(2, 0)
Dim Face As Face2
Set Face = SilEdge.GetFace
Set Ent = Face
Set swComp = Ent.GetComponent
Set swCompModel = swComp.GetModelDoc2
Bret = swCompModel.Extension.ToolboxPartType 'Return Value is True then Component is ToolBox Part
Else
Set Ent = Part.SelectionManager.GetSelectedObject6(2, 0)
Set swComp = Ent.GetComponent
Set swCompModel = swComp.GetModelDoc2
Bret = swCompModel.Extension.ToolboxPartType 'Return Value is True then Component is ToolBox Part
End If
End Sub
Perfect!!!, I get a crash if nothing is selection. Whats the easiest way to prompt for selection if one wasn't made?
Try this ... please makt it as Correct answer ....
Dim swApp As Object
Dim Part As ModelDoc2
Dim swDrw As DrawingDoc
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Ent As Entity
Dim swComp As Component2
Dim swCompModel As ModelDoc2
Dim Bret As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swDrw = Part
Dim cnt As Integer
cnt = Part.SelectionManager.GetSelectedObjectCount 'Always get the count before getting Edge,Vertex..etc object
If cnt <> 0 Then
Dim objtyp As Long
objtyp = Part.SelectionManager.GetSelectedObjectType3(2, 0)
If objtyp <> 0 Then
If objtyp = 46 Then 'It will work for Cylindrical round edge
Dim SilEdge As SilhouetteEdge
Set SilEdge = Part.SelectionManager.GetSelectedObject6(2, 0)
Dim Face As Face2
Set Face = SilEdge.GetFace
Set Ent = Face
Set swComp = Ent.GetComponent
Set swCompModel = swComp.GetModelDoc2
Bret = swCompModel.Extension.ToolboxPartType 'Return Value is True then Component is ToolBox Part
Else
Set Ent = Part.SelectionManager.GetSelectedObject6(2, 0)
Set swComp = Ent.GetComponent
Set swCompModel = swComp.GetModelDoc2
Bret = swCompModel.Extension.ToolboxPartType 'Return Value is True then Component is ToolBox Part
End If
End If
End If
End Sub
Try this ... please makt it as Correct answer ....
Dim swApp As Object
Dim Part As ModelDoc2
Dim swDrw As DrawingDoc
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Ent As Entity
Dim swComp As Component2
Dim swCompModel As ModelDoc2
Dim Bret As Boolean
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Set swDrw = Part
Dim cnt As Integer
cnt = Part.SelectionManager.GetSelectedObjectCount 'Always get the count before getting Edge,Vertex..etc object
If cnt <> 0 Then
Dim objtyp As Long
objtyp = Part.SelectionManager.GetSelectedObjectType3(2, 0)
If objtyp <> 0 Then
If objtyp = 46 Then 'It will work for Cylindrical round edge
Dim SilEdge As SilhouetteEdge
Set SilEdge = Part.SelectionManager.GetSelectedObject6(2, 0)
Dim Face As Face2
Set Face = SilEdge.GetFace
Set Ent = Face
Set swComp = Ent.GetComponent
Set swCompModel = swComp.GetModelDoc2
Bret = swCompModel.Extension.ToolboxPartType 'Return Value is True then Component is ToolBox Part
Else
Set Ent = Part.SelectionManager.GetSelectedObject6(2, 0)
Set swComp = Ent.GetComponent
Set swCompModel = swComp.GetModelDoc2
Bret = swCompModel.Extension.ToolboxPartType 'Return Value is True then Component is ToolBox Part
End If
End If
End If
End Sub