.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VB .NET Select entities glitch

2 REPLIES 2
Reply
Message 1 of 3
gjurkaitisU5KVU
174 Views, 2 Replies

VB .NET Select entities glitch

Hello All,

 

I am exporting entities properties to excel. A key command to get entities in a region. 

It all works well at first, but then as the code loops through deferent regions (Move UCS), the selection return nothing at random times.

 

Here's my code to select all objects under a certain layer within a range, please help why would it glitch to works

 

Public Function GetObjectsLayer(objType As String, layerName As String) As SelectionSet
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim edt As Editor = doc.Editor

 

'Selection Criteria
'Additional typed value to include filter; now totaling = 2
Dim tv As TypedValue() = New TypedValue(2) {}
tv.SetValue(New TypedValue(CInt(DxfCode.Start), objType), 0) ' object type
tv.SetValue(New TypedValue(67, 0), 1) 'Select only from model space
tv.SetValue(New TypedValue(CInt(DxfCode.LayerName), layerName), 2) 'layer name

'Selection Range
' Define the corners of the selection window
Dim pt1 As Point3d = New Point3d(0, 4000, 0)
Dim pt2 As Point3d = New Point3d(5000, 0, 0)

'Convert points to WCS (world coordinate system)
Dim ucs As Matrix3d = edt.CurrentUserCoordinateSystem
' Transform points from UCS to WCS
Dim pt1Wcs As Point3d = pt1.TransformBy(ucs)
Dim pt2Wcs As Point3d = pt2.TransformBy(ucs)


Dim filter As SelectionFilter = New SelectionFilter(tv)
Dim psr As PromptSelectionResult = edt.SelectCrossingWindow(pt2, pt1, filter)
Dim ss As SelectionSet = psr.Value

Return ss

 

End Function

Labels (1)
2 REPLIES 2
Message 2 of 3
_gile
in reply to: gjurkaitisU5KVU

Hi,

The Editor.SelectWindow method (as other Editor methods) works with UCS coordinates. So, if you "move the UCS", you should not transform the pt1 and pt2 points to WCS.

That said, most of the time when using code in AutoCAD, we do not "move UCS" as do end users. In this case, I'd prefer "moving pt1 ans pt2".



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
norman.yuan
in reply to: _gile

Besides what @_gile has said, since you call Editor.SelectCrossing[Window/Polygon...], you MUST MAKE SURE the window/polygon is WITHIN the current view. If the point defining the window/polygon is beyond current view, the selection would not be done as expected. 

Norman Yuan

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


AutoCAD Beta