Hi everyone,
Can you please help me with my problem? I'm still new in AutoCAD Mechanical VBA and I am not yet so familiar with its fucntionalities.
I have this code below and all I want is to output the number of selected items. The concept is just simple, select items and store the number of objects or items found in the selection. I think i'm doint it wrong. Any help is much appreciated! Thanks in advance.
Solved! Go to Solution.
Solved by RICVBA. Go to Solution.
In my "Autocad ActiveX and VBA Reference" I see that "acSelectionSetFence" mode is available only for "SelectByPolygon" method of SelectionSet object, not for "Select" mode as I see from your code
Furthermore the "SelectByPolygon" method's format is "object.SelectByPolygon Mode, PointsList, FilterType, FilterData", where:
- Object = SelectionSet
- Mode = acSelectionSetFence (one of 3 possibilities)
- PointsList = Variant (array of doubles); input-only. An array of 3D WCS coordinates specifying the selection fence.
- FilterType = Integer; input-only; optional - A DXF group code specifying the type of filter to use.
- FilterData = Variant; input-only; optional - The value to filter on.
If all what above applies to AutoCAD Mechanical VBA too, then you're missing the right method ("SelectByPoligon") for using "acSelectionSetFence" mode and also you can't use AcadPoints variables for passing the points delimiting your fence but you need to pass a Variant (array of doubles).
Here follows the example from my "Autocad ActiveX and VBA Reference":
Sub Example_SelectByPolygon() ' This example adds objects to a selection set by defining a polygon. Dim ssetObj As AcadSelectionSet Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET2") ' Add to the selection set all the objects that lie within a fence Dim mode As Integer Dim pointsArray(0 To 11) As Double mode = acSelectionSetFence pointsArray(0) = 28.2: pointsArray(1) = 17.2: pointsArray(2) = 0 pointsArray(3) = -5: pointsArray(4) = 13: pointsArray(5) = 0 pointsArray(6) = -3.3: pointsArray(7) = -3.6: pointsArray(8) = 0 pointsArray(9) = 28: pointsArray(10) = -3: pointsArray(11) = 0 ssetObj.SelectByPolygon mode, pointsArray ' Add to the selection set all the Circles that lie within fence ReDim gpCode(0 To 1) As Integer gpCode(0) = 0 gpCode(1) = 10 Dim pnt(0 To 2) As Double pnt(0) = 3: pnt(1) = 6: pnt(2) = 0 ReDim dataValue(0 To 1) As Variant dataValue(0) = "Circle" dataValue(1) = pnt Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue ssetObj.SelectByPolygon mode, pointsArray, groupCode, dataCode End Sub
hope this helps
bye
Hi RICVBA,
Can please give me some hints on how to use the pointsArray properly? I think i'm lost again. Correct me if I am wrong
Does pointsArray 0 to 2 represent the XYZ location of the first point of the polygon?
pointsArray(0) = 28.2: pointsArray(1) = 17.2: pointsArray(2) = 0
@RICVBA wrote:In my "Autocad ActiveX and VBA Reference" I see that "acSelectionSetFence" mode is available only for "SelectByPolygon" method of SelectionSet object, not for "Select" mode as I see from your code
Furthermore the "SelectByPolygon" method's format is "object.SelectByPolygon Mode, PointsList, FilterType, FilterData", where:
- Object = SelectionSet
- Mode = acSelectionSetFence (one of 3 possibilities)- PointsList = Variant (array of doubles); input-only. An array of 3D WCS coordinates specifying the selection fence.
- FilterType = Integer; input-only; optional - A DXF group code specifying the type of filter to use.
- FilterData = Variant; input-only; optional - The value to filter on.
If all what above applies to AutoCAD Mechanical VBA too, then you're missing the right method ("SelectByPoligon") for using "acSelectionSetFence" mode and also you can't use AcadPoints variables for passing the points delimiting your fence but you need to pass a Variant (array of doubles).
Here follows the example from my "Autocad ActiveX and VBA Reference":
Sub Example_SelectByPolygon() ' This example adds objects to a selection set by defining a polygon. Dim ssetObj As AcadSelectionSet Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET2") ' Add to the selection set all the objects that lie within a fence Dim mode As Integer Dim pointsArray(0 To 11) As Double mode = acSelectionSetFence pointsArray(0) = 28.2: pointsArray(1) = 17.2: pointsArray(2) = 0 pointsArray(3) = -5: pointsArray(4) = 13: pointsArray(5) = 0 pointsArray(6) = -3.3: pointsArray(7) = -3.6: pointsArray(8) = 0 pointsArray(9) = 28: pointsArray(10) = -3: pointsArray(11) = 0 ssetObj.SelectByPolygon mode, pointsArray ' Add to the selection set all the Circles that lie within fence ReDim gpCode(0 To 1) As Integer gpCode(0) = 0 gpCode(1) = 10 Dim pnt(0 To 2) As Double pnt(0) = 3: pnt(1) = 6: pnt(2) = 0 ReDim dataValue(0 To 1) As Variant dataValue(0) = "Circle" dataValue(1) = pnt Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue ssetObj.SelectByPolygon mode, pointsArray, groupCode, dataCode End Subhope this helps
bye
yes
the pointsArray must contain the coordinates of all points marking the fence
since this example fence has 4 points and every point has three coordinates (X, Y , Z), there come out 12 coordinates whose definition, just for readability purposes, have been divided into 4 lines of code, one for every point, each with the three stataments required (one for every coordinate, separated by ":" character)
for a n-point fence you must use a 3*n array whose declaration, having to be zero-based (i.e.: the first element must have index = 0), would be something like "Dim pointsArray(0 To 3*n-1) As Double", where you have to type the actual literal value (for instance: "11") in lieu of "3*n-1".
please take note that with "acSelectionSetFence" mode you'll select all objects "crossing" a selection fence defined by coordinates in pointsArray.
if you want to select objects that "lie within" a fence then you'd use "acSelectionSetWindowPolygon" mode.
in any case, all these methods are affected by the current zoom. so it's safer to write a "Application.ZoomAll" code line just before the one calling the selectionset selection method. otherwise the selectionset will contain only those objects that both match your selection criteria (fence/window etc., and possibly filtering ones also) and are visible in your application current zoom.