• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

create a selection based on a criterion

  • Thread starter Thread starter BuDuS
  • Start date Start date

BuDuS

Guest
I'm trying to do vba commands to create a selection based on a certain criterion.

for example "select according to a certain layer"; In particular, I would like the user to have the possibility to select the geometries according to the feature of the pre-selected one (or, if he has not selected anything, let him select it after ... a little like many of the autocad commands).

I can already create a "selectionset" with stuff like this:
Code:
' seleziona per layer
public sub selectlayer()
    dim acobject as object
    set acobject = udagetselection
    
    set objselcol = thisdrawing.selectionsets
    for each objselset in objselcol
      if objselset.name = "udapower" then
        objselcol.item("udapower").delete
        exit for
      end if
    next
    
    on error goto exit_sub
    
    dim objlayername as string
    objlayername = acobject.layer
    
    dim ssett as acadselectionset
    
    set ssett = thisdrawing.selectionsets.add("udapower")
    dim filtertype(0 to 1) as integer
    dim filterdata(0 to 1) as variant
    'filtertype(0) = 0: filterdata(0) = "line"
    filtertype(0) = 8: filterdata(0) = objlayername
    filtertype(1) = 8: filterdata(1) = objlayername
    ssett.select acselectionsetall, , , filtertype, filterdata
    
    if ssett.count < 1 then
        msgbox "errore: non è stato selezionato nulla.", vbcritical, "selection error"
    else
        ssett.highlight true
    end if
    
exit_sub:
end sub
the call to:
Code:
set acobject = udagetselection
it is necessary to return the pre-selected object (the one that exploits to create the next selection, according to its characteristics, in this case the layer name) or in any case select one to the user.
What's the problem?
had, the geometries are represented as selected but, in fact, they are not: any command I take - manually -successively is how I had not selected anything.
selection works if I use it with some vba routine and this indicates that the code above somehow creates a selection.
Does anyone have a right to give me to make sure that he can convert this "internal to vba" selection into something that can use the user?
 
Perhaps it is a little orthodox system, but a solution to the problem I found:
Code:
thisdrawing.sendcommand "_.pselect" & vbcr & "p" & vbcr
after I create the selection with the previous post method you can select it "as you must" with a "previous selection".

However, if you have a more elegant solution, I certainly do not offend you:finger:
 
to select and then make a filter we could also use groups! !
Code:
dim sset1 as acadselectionset
dim sset as acadselectionset

dim element as acadentity
dim element1 as acadentity

dim filtertype(0) as integer
dim filterdata(0) as variant

dim getprop as string

on error resume next
 ' delete the selection set if it exists
 if not isnull(thisdrawing.selectionsets.item("element")) then
    set sset = thisdrawing.selectionsets.item("element")
    sset.delete
 end if
 
 if not isnull(thisdrawing.selectionsets.item("element1")) then
    set sset1 = thisdrawing.selectionsets.item("element1")
    sset1.delete
 end if

set sset = thisdrawing.selectionsets.add("element")

set sset1 = thisdrawing.selectionsets.add("element1")



    dim groupcoll as acadgroups
    set groupcoll = thisdrawing.groups
    
    ' create a dimension style named "test" in current drawing
    dim testgroup as acadgroup
    set testgroup = groupcoll.add("filtro_selezione")
    

sset.selectonscreen

getprop = sset.item(0).layer

filtertype(0) = 8
filterdata(0) = getprop

set sset1 = thisdrawing.selectionsets.add("element1")
sset1.select acselectionsetall, , , filtertype, filterdata


    redim appendobjs(0 to sset1.count - 1) as acadentity
    dim i as integer
    for i = 0 to sset1.count - 1
        set appendobjs(i) = sset1.item(i)
    next
    
    ' add the array of objects to the group
    testgroup.appenditems appendobjs
    
   
    thisdrawing.setvariable "pickstyle", 1

'qui ovviamente devi selezionare un elemento del gruppo, anche quello precedentemente selezionato come matrice
It's a part of code taken and threw them...
it is to be settled but it could work. . .

just to give you the idea
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top