Solved

Automating AutoCAD SelectionSets...

Posted on 2009-04-08
12
2,073 Views
Last Modified: 2013-12-04
I am trying to automate AutoCAD Selection Sets and I've got the code working to make the selection sets with a filter.. but it's returning a count of "0" for the items in the set when it should be returning a count of 1 for the drawing I'm working with.  Does anyone know why this code is having issues:
V_AutoCadInterfaceObject.Open(V_FilePathAutoCad)
 

            Dim V_StartBorderSelectionSet As AcadSelectionSet
 

            Try

                V_StartBorderSelectionSet = V_AutoCad.ActiveDocument.SelectionSets.Add("StartBorders")

            Catch ex As Exception

                V_StartBorderSelectionSet = V_AutoCad.ActiveDocument.SelectionSets.Item("StartBorders")

                V_StartBorderSelectionSet.Clear()

            End Try
 

            Dim FilterType(2) As Int16

            Dim FilterData(2) As Object
 

            FilterType(0) = 100

            FilterData(0) = "AcDbBlockReference"
 

            FilterType(1) = 0

            FilterData(1) = "START"
 

            Dim FilterTypeObject As Object

            Dim FilterDataObject As Object
 

            FilterTypeObject = FilterType

            FilterDataObject = FilterData
 

            V_StartBorderSelectionSet.Select(acSelectionSetAll, , , FilterTypeObject, FilterDataObject)
 

            MsgBox(V_StartBorderSelectionSet.Count)

Open in new window

0
Comment
Question by:LittleOleMeDesigns
  • 6
  • 4
  • 2
12 Comments
 
LVL 11

Accepted Solution

by:
darrenmcwi earned 250 total points
Comment Utility
FilterType(1) = 0
FilterData(1) = "INSERT"
0
 
LVL 10

Assisted Solution

by:borgunit
borgunit earned 250 total points
Comment Utility
By the same token, the second filter would be:

FilterType(1) = 2
FilterData(1) = "START"

I am assuming a search for a block named START
0
 
LVL 10

Expert Comment

by:borgunit
Comment Utility
OOPs, correction

By the same token, the second filter would be:

FilterType(0) = 2
FilterData(0) = "START"

I am assuming a search for a block named START
0
 
LVL 4

Author Comment

by:LittleOleMeDesigns
Comment Utility
I've tried it with these set like this:

 FilterType(1) = 0
 FilterData(1) = "Insert"

 FilterType(0) = 0
 FilterData(0) = "START"

Like This:
 FilterType(0) = 0
 FilterData(0) = "Insert"

 FilterType(1) = 2
 FilterData(1) = "START"

And like this:
 FilterType(1) = 0
 FilterData(1) = "Insert"

 FilterType(0) = 2
 FilterData(0) = "START"

And same result on all of them... every time it tells me that there is a count of 0 and there is 1 START block in that drawing so it should be telling me 1
0
 
LVL 4

Author Comment

by:LittleOleMeDesigns
Comment Utility
I am using this to open drawings without "opening" them... would this make a difference:

Dim V_AutoCadInterfaceObject As AxDbDocument
V_AutoCadInterfaceObject = V_AutoCad.GetInterfaceObject("ObjectDBX.AxDbDocument")
V_AutoCad = GetObject(, "AutoCad.Application.15")
0
 
LVL 10

Expert Comment

by:borgunit
Comment Utility
I use a snippet that just "grabs" the selection set by the block name as shown. Plug this into your code and see what happens.
Dim FilterType(0) As Int16

Dim FilterData(0) As Object

 

FilterType(0) = 2

FilterData(0) = "START"

 

Dim FilterTypeObject As Object

Dim FilterDataObject As Object

 

FilterTypeObject = FilterType

FilterDataObject = FilterData

Open in new window

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Author Comment

by:LittleOleMeDesigns
Comment Utility
Nope... same result.

I'm using Visual Studio 2005 and AutoCAD 2002 if that makes a difference as well.
0
 
LVL 4

Author Comment

by:LittleOleMeDesigns
Comment Utility
I also should not that I can run this manually on that drawing it finds the one START block... so it's got to be something with the code

in AutoCAD command line and filter dialog box:
select
'filter
block name
START
add to list
apply

I've also just tried opening the file both in the background like I mentioned previously as well as opening it where the user can see it, and I still got the same result.

Man.. this is annoying... lol
0
 
LVL 10

Expert Comment

by:borgunit
Comment Utility
Miss-timed my reply. Yes, the selection set will not work on ObjectDBX. You will have to interate all objects in modelspace (lets say) until you get to a blockreference and then check its name.
0
 
LVL 4

Author Comment

by:LittleOleMeDesigns
Comment Utility
@borgunit
Isn't the purposes of ObjectDBX to be able to read block attribute data without opening the drawing.. if you can't use selectionsets with it.. what would you use?

Also, as I mentioned previously,  I've tried it both using ObjectDBX as well as without it and I still get the same result.

Also, I just tried this without filtering at all and got the same result:
V_StartBorderSelectionSet.Select(acSelectionSetAll, , , , )
0
 
LVL 11

Expert Comment

by:darrenmcwi
Comment Utility
Borgunit is correct.

To anser your followup, SelectionSets are based on graphical coordinates as they relate to screen pixels. That's why you can't typically hatch an area that's not entirely within the drawing editor. That's why you can't perform a "window" or "crossing" selection set in a part of the drawing that's currently zoomed/panned outside the drawing editor.

Because ObjectDBX opens the drawing in memory without loading the graphical data, it has no basis for determining those sorts of things.  It doesn't use raw coordinates either as that would kill performance having to sift through the entire coordinate system for the purposes fo selection sets, which is why a screen pixel to drawing coordinat conversion in done behind the scenes.

Even thgough your selection isn't specifying a wondow or selection using coordinates, the Selection Set infastructure needs the graphical data loaded to be able to work which is why, unfortunately, you're left iterating through all the objects in the drawing.

On the plus side, because there's no graphics loaded into memory, iteration through the drawing database is very fast and efficient where it typically wouldn't be,
0
 
LVL 4

Author Closing Comment

by:LittleOleMeDesigns
Comment Utility
Ok.. I finally got this figured out thanks to your suggestions.. I'm still stuck on one part, but since it's no longer related to selectionsets, I started a new question for it located at:
http://www.experts-exchange.com/Software/Photos_Graphics/CAD_Architecture/AutoCAD/Q_24307097.html

Thank-You both for your help on this!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now