katto01 Posted August 17, 2017 Posted August 17, 2017 Hello, Q1: How do I get the number of entities in a selection using VBA? Q2: What is the command/method to find the type of each entity in a selection using VBA? Thank you Quote
RICVBA Posted August 17, 2017 Posted August 17, 2017 A1: use .Count method of SelectionSet object A2: you could use typeOf() like: If typeOf acEnt Is AcadLine then ... and the likes where acEnt is some AcadEntity type variable you're looping through SelectionSet with Quote
Grrr Posted August 17, 2017 Posted August 17, 2017 Heres my example-attempt: Sub test() 'define a named function 'Filter for circles - I don't know how to implement this type of filtering: 'Dim gpCode(0) As Integer 'Dim dataValue(0) As Variant 'gpCode(0) = 0 'dataValue(0) = "Circle" Dim SS As AcadSelectionSet 'Declare "SS" variable as local Set SS = ThisDrawing.SelectionSets.Add("NewSS") 'create a new selection set object [include it in the "SelectionSets" collection] SS.SelectOnScreen 'select the objects to change (invoke the "SelectOnScreen" method) For Each Entity In SS 'iterate over the selection set If Entity.ObjectName = "AcDbCircle" Then 'Filter for circles by objectname Entity.color = 1 'change entity's colour End If Next 'process the next entity MsgBox SS.Count 'alert the total selected amount of objects SS.Delete 'delete the selection set object [exclude it from the "SelectionSets" collection] End Sub I'm just starting to learn about VBA, so any inputs are appreciated. Quote
BIGAL Posted August 18, 2017 Posted August 18, 2017 Grr this may be usefull Dim FilterDXFCode(0) As Integer Dim FilterDXFVal(0) As Variant FilterDXFCode(0) = 0 FilterDXFVal(0) = "INSERT" 'FilterDXFCode(1) = 2 'FilterDXFVal(1) = "SCHEDTEXT" Set SS = ThisDrawing.SelectionSets.Add("pit1sel") SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal for circle FilterDXFVal(0) = "CIRCLE" lisp (0 . "Insert") Quote
Grrr Posted August 18, 2017 Posted August 18, 2017 Thanks BIGAL! This second shot worked: Sub test() 'define a named function Dim FilterDXFCode(0) As Integer Dim FilterDXFVal(0) As Variant FilterDXFCode(0) = 0 FilterDXFVal(0) = "CIRCLE" Dim SS As AcadSelectionSet 'Declare "SS" variable as local Set SS = ThisDrawing.SelectionSets.Add("NewSS") 'create a new selection set object [include it in the "SelectionSets" collection] 'SS.Select acSelectionSetWindow , , , FilterDXFCode, FilterDXFVal '<<< BIGAL's example SS.SelectOnScreen FilterDXFCode, FilterDXFVal 'select the objects to change (invoke the "SelectOnScreen" method) and include filters For Each Entity In SS 'iterate over the selection set Entity.color = 1 'change entity's colour Next 'process the next entity MsgBox SS.Count 'alert the total selected amount of objects SS.Delete 'delete the selection set object [exclude it from the "SelectionSets" collection] End Sub It seems hard for me to get use with VBA, from lisp (since the lack of syntaxes). First Impressions are that VBA and Visual Lisp (not Vanilla) are related, you have to, create a Selection Set Object, invoke a method and iterate thru it - instead of a single ssget function, that would be enough in vanilla lisp (altho still requires iteration). With Visual Lisp it would wook like this: ( (lambda ( / SS ) (vla-SelectOnScreen (setq SS (vla-Add (vla-get-SelectionSets (vla-get-ActiveDocument (vlax-get-acad-object))) "NewSS")) (vlax-safearray-fill (vlax-make-safearray vlax-vbinteger '(0 . 0)) '(0)) (vlax-safearray-fill (vlax-make-safearray vlax-vbvariant '(0 . 0)) '("CIRCLE")) ) (vlax-for o SS (vla-put-Color o 1)) (vla-Delete SS) ) ) P.S. Sorry for late reply - I'm busy with other kind of work (computerless). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.