Jump to content

VBA - Selection Sets


-KarL-

Recommended Posts

Maybe he want like this

Sub sss()

Dim SS As AcadSelectionSet

Set SS = ThisDrawing.SelectionSets.Add("SS")
SS.SelectOnScreen

Dim Ent As AcadEntity
Dim EntName As String

For Each Ent In SS
EntName = Ent.ObjectName
EntName = Mid(EntName, 5, 10)
MsgBox "This object selected is = " & EntName
Next Ent

SS.Delete ' to delete selection set exist
End Sub

 

How do I go about creating a selection set of devices in vba?

 

Thanks in advance

 

KarL

Link to comment
Share on other sites

I have this code that creates a selection set of blocks named SYSNODE

 

Sub getSelectionSet(ssName As String, ssetobj As AcadSelectionSet)
   On Error Resume Next
   ThisDrawing.SelectionSets.Item(ssName).Delete
   On Error GoTo 0

   Set ssetobj = ThisDrawing.SelectionSets.Add(ssName)
   Dim gpCode(1) As Integer
   Dim dataValue(1) As Variant
   gpCode(0) = 0
   dataValue(0) = "INSERT"
   gpCode(1) = 2
   dataValue(1) = "SYSNODE"
   ssetobj.Select acSelectionSetAll, , , gpCode, dataValue
End Sub

I would like to modify it to select devices instead of blocks but I cant firgure out how.

 

 

Selection set of devices?

Karl, what do you mean by devices?

 

ML

Not sure how to define them except for smart blocks. For Example, one of the devices we use is a receptacle. It stores all the electrical information of the device (panel, circuit, voltage, amps, wire size, etc.) and then we use tags to display certain information. I think devices are only available in MEP/ABS versions of acad.
Link to comment
Share on other sites

Oh, that would explain it then

So, they are not block references then; otherwise the other code would work.

 

In The VBAIDE (VBA Environment), if you go to Tools-References,

Scroll down, you may see a type library specific to that app.

When I was using LDD, there was a type library, specific to those objects.

 

So, if you see a type library for MEP, then check the box, then you should be able to access those objects for programming.

When you find out what this object (device) is called in VBA, then you will be able to include it in your code. Then if there is still a problem, we can help you more.

 

ML

Link to comment
Share on other sites

  • 2 weeks later...
basically create a filter for the blocks

 

That is where I am having problems, I can't figure out how to set up the filters.

Link to comment
Share on other sites

      Set objSelSet = objSelCol.Add("SSName")
     intType(0) = 0: varData(0) = "INSERT"
     intType(1) = 2: varData(1) = "BlkName"
     objSelSet.Select Mode:=acSelectionSetAll, filtertype:=intType, filterdata:=varData

Link to comment
Share on other sites

varData(0) = "INSERT"

 

I have tried that but it only selects one of the dynamic blocks (the only one I dont need) but not the other 2 dynamic blocks in the drawing.

Link to comment
Share on other sites

  • 5 months later...
      Set objSelSet = objSelCol.Add("SSName")
     intType(0) = 0: varData(0) = "INSERT"
     intType(1) = 2: varData(1) = "BlkName"
     objSelSet.Select Mode:=acSelectionSetAll, filtertype:=intType, filterdata:=varData

 

This thread has been very useful; but I have a follow up question.

 

If you have various of block names that you want to include in the filter, do you have to include a corresponding "2" in the Filter Type?

 

In other words, do both the Filter Type and Filter Data arrays have to be of equal size or can one (usually the filter Data) be larger?

 

Thanks.

Link to comment
Share on other sites

  • 2 weeks later...
Olhado,

One array can indeed be larger then the other.

 

What "precisely" are you trying to do with the selected blocks?

 

Thanks for the reply

 

That is good news because now I may not need the communication via "USER" system variables between LISP AND VBA.

 

This is what I am doing right now:

 


Dim LowerLeft As Variant
Dim UpperRight As Variant

' Get the Title Block Name defined from LISP routine
blkName = Application.ActiveDocument.GetVariable("USERS1")

On Error Resume Next
   ThisDrawing.SelectionSets("GetTitleBlock").Delete
   If Err.Number > 0 Then Err.Clear

   Set ssetobj = ThisDrawing.SelectionSets.Add("GetTitleBlock")
   gpCode(0) = 0
   dataValue(0) = "INSERT"
   gpCode(1) = 2
   dataValue(1) = blkName
   ssetobj.Select Mode:=acSelectionSetAll, FilterType:=gpCode, FilterData:=dataValue

   For Each acEnt In ssetobj
       acEnt.GetBoundingBox LowerLeft, UpperRight
   Next acEnt

   ReDim Preserve LowerLeft(0 To 1)
   ReDim Preserve UpperRight(0 To 1)

 

So, according to what you just said I can make "Datavalue" the following:

 


dataValue(1) = "TitleBlock1":dataValue(2) = "TitleBlock2":dataValue(3) = "TitleBlock2": etc

I need to do this because I am trying to insert a block on lower right corner of the title block, then print it, and then delete the inserted block. This is to signify that these drawings are final.

Link to comment
Share on other sites

You're welcome.

 

I think that I understand what you are trying to do, however, I have a feeling that you are over complicating it a bit.

 

There is no need to use The Users variable, or to have VBA communicate with LISP, in this case.

 

Do you already have an existing LISP routine written that you are trying to tie into The VBA Module?

 

ML

Link to comment
Share on other sites

Sorry,

I missed this comment..

'Get the Title Block Name defined from LISP routine
blkName = Application.ActiveDocument.GetVariable("USERS1")

 

OK, let's start from the beginning; using VBA, you can insert the block, have the selection set grab the last inserted object, which in this case would be the inserted block, on the lower left on your title block; then we can step into the print part, after we get that part worked out for you.

 

Then, after the print, you can then delete the block from the selection set; then, in the end, we will delete the selection set.

 

If you would like further help, I will need the name of your title block, is it already existing in the drawing? Is the title block at 0,0, and will it remain there? Also, what is the name of the block that you are trying to insert at the lower left of your title block?

 

If we can get that much to work, we can then move onto the printing, and that is where you will prompt the user to pick points.

 

ML

Link to comment
Share on other sites

  • 4 weeks later...

Sorry, about not getting back to you; but yeah I think I believe I have a version of the code, in both LISP and VBA.

For the record, I cannot just use "last inserted object" because the title block is usually one of the first objects to be inserted.

Also, I ended up using VBA to set up the print options only, again mostly because I understand LISP a bit better and was able to find the blocks and boundaries much easier. :)

Thanks for the offer. I am sorry I could not take you up on it.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...