Selecting by Attributes in ArcGIS for AutoCAD
It probably isn’t too convincing from my blog picture, but I look just enough like NBA all-star Dirk Newitzki in-person that I am frequently mistaken for him in airports, hotels and restaurants. It’s a dubious honor to simply look like someone famous, since in the end everyone is disappointed when they learn I am just me.At a food court in San Antonio I was unable to convince a 10 year old “fan” that I wasn’t Dirk, and he forced me to sign an autograph. I have posed for a number of photos with strangers, who didn’t care if I was him or not, they just wanted to say he/I was there in the picture.
My brother-from-another-mother is 6 inches taller and shoots better free throws than me. These are just a couple of the attributes that distinguish us one from another.
Here is an AutoLISP routine that selects features by feature-attribute values in ArcGIS for AutoCAD. It uses a combination of standard AutoLISP and the ArcGIS for AutoCAD AutoLISP API. It has a simple command line interface that allows me to click through the schema of feature classes in my drawing to build a simple equality-query for the selected feature class.
(ie This = That)
You can use this AutoLISP file, as is… if it works for you, or you can use it as an example of how to build your own query tool that could make more sophisticated comparisons.
The AutoLISP code snippet below is that part that does the work… Look here for the complete AutoLISP routine that includes the command line interface.…
;Select All The Entities In the Target FC
(esri_SelectFC TargetFC)
(setq ss (ssget "P"))
(setq NextEntity 0)
;Create New Empty Selection Set
(setq newSS (ssadd))
(setq SelectionCount 0)
;Check each entity in the selected set of features
(while (setq ent (ssname ss NextEntity))
;Use the ArcGIS for AutoCAD routine to get the MSD attribute values
(if (setq ValuePair (esri_GetAttribute ent TargetField))
(progn
(setq EntityValue (cdr ValuePair))
;Compare to this entity’s MSD Attribute Value to the Target Search
Value
(if (= SearchValue EntityValue)
(progn
(setq newSS (ssadd ent newSS))
(setq SelectionCount
(+
SelectionCount 1))
)
)
)
)
(setq NextEntity (+ NextEntity 1))
);End While Entities
;Set/Grip Selection Set
(setq ss (sssetfirst nil newSS))


0 Comments:
Post a Comment
<< Home