Page 1 of 1
select a specific sketch block instance via API
Posted: Sun Jul 02, 2023 8:56 am
by mp3-250
I have a 3D Sketch in an assembly and I insert some sketch block inside it.
In 3d sketch Edit mode, is there a way to retrieve the block instance name like "BLOCKNAME-instance number" from the selection of single point from the above mentioned block?
I am able to do it from a selected segment from the block which is named like "line00-blockname-01" in which 01 is the instance number of the block...
Re: select a specific sketch block instance via API
Posted: Wed Jul 05, 2023 9:41 am
by AlexB
In looking at the GetSelectedObject6 method and the types returned by GetSelectedObjectType3, I don't believe there's an easy way to get the instance related to the selection.
Re: select a specific sketch block instance via API
Posted: Wed Jul 05, 2023 3:20 pm
by josh
I can’t figure out any way to get this info. Apparently, the 3D sketch which owns the block instances reports that it contains zero sketchpoints. The sketchpoints do not have a unique ID within the 3D sketch, but they report that they belong to the 3D sketch.
Dim swApp As SldWorks.SldWorks
Dim swSels As SldWorks.SelectionMgr
Dim swDoc As SldWorks.ModelDoc2
Dim swPt As SldWorks.SketchPoint
Dim vID As Variant
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swSels = swDoc.SelectionManager
Set swPt = swSels.GetSelectedObject6(1, -1)
vID = swPt.GetID
Debug.Print "Name of sketch with point: " & swPt.GetSketch.Name & ". This sketch has " & swPt.GetSketch.GetSketchPointsCount2 & " points."
Debug.Print "Point ID: ", vID(0), vID(1)
Re: select a specific sketch block instance via API
Posted: Wed Jul 05, 2023 10:58 pm
by mp3-250
I noticed if I select sketch segment point from the graphic window and look In "select other" list the point and the sketch point (probably a temporary ID like "point 6")and its instance are there.
If I could get that list from the API I would manipulate the name string to extract the block name and instance and select it. I did something sImilar with segments, but I was able to get the segment name at least.
with those points I see their full name in select others only...
Re: select a specific sketch block instance via API
Posted: Sat Jul 22, 2023 5:05 pm
by JeromeP
A bit late but I think GetSelectByIdSpecification should do the trick
and works with points and segments, in or out of the 3DSketch.
Results: Point5/Block1-3 -Or- Point5/Block1-3@3DSketch1
Code: Select all
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swObj As Object
Dim selectByString As String
Dim objectTypeStr As String
Dim objectTypeInt As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swObj = swSelMgr.GetSelectedObject6(1, -1)
If swObj Is Nothing Then MsgBox "Select a Point or Segment": Exit Sub
swSelMgr.GetSelectByIdSpecification swObj, selectByString, objectTypeStr, objectTypeInt
Debug.Print "Name of selected feature: " & selectByString
Debug.Print "Type of object: " & objectTypeStr
Debug.Print "Type of object as defined in swSelectType_e: " & objectTypeInt
End Sub