March 24, 2015

Hyperlinks in ArcGIS for AutoCAD

Go figure. The morning after my daughter returned from a week-long class field trip to a winter camp she announced that she was a "vegetarian".  I was intrigued as I fished frying up a pan of bacon for breakfast and asked her to explain.  She said that she doesn't eat meat anymore.  As the bacon came out of the pan she was quick to add that she was a vegetarian; except for bacon…. and hotdogs… and …cheeseburgers.  I then asked if there was anything else, she said no, she doesn't eat any meat like fish, or other gross things.  But added, actually fish sticks are ok.
Sometimes the full meaning of GIS data is better found in another place and format, and a hyperlink on an AutoCAD entity is a good way to associate that data in ArcGIS for AutoCAD
If I have hyperlink locations already included in my ArcGIS feature attributes I can employ an advanced use of the ESRI_CALCULATEFIELD bonus tool to quickly associate the URL of my hyperlinks found in the attributes of my ArcGIS features and apply them to the associated entities as AutoCAD hyperlinks.  The ArcGIS field name containing my hyperlink is called URL in my example.  I am not actually changing the value of a field when I am using the ESRI_CALCULATEFIELD bonus tool (which is why I call this an "advanced" use of the tool, since it primary use IS to modify a field.)  I am arbitrarily specifying the "URL" field as the field I am modifying with the ESRI_CALCULATEFIELD command.  I am supplying the value of the [URL] field as the last statement in my expression so the URL field remains unchanged. 
What my AutoLISP expression does before that is to establish and AutoCAD hyperlink on each entity in my feature class because my expression invokes  the –HYPERLINK command and supplies the value of the ArcGIS attribute field value [URL] (from the URL field on each entity). 
My AutoLISP expression actually has four parts.  First it runs the PROG function that simply allows me to perform more than one AutoLISP statement as a single
expression.  Then the ESRI_CLEARSELECTION command to ensure the –HYPERLINK command processes one entity at a time.  Typically I don't need to clear the selection set to perform other AutoCAD commands in my expression, however in this case the AutoCAD –HYPERLINK command exhibits a different behavior/syntax when an existing selection set is active.
Next I include the –HYPERLINK command with its parameters that include the value of my url field designated with square brackets, [URL].  
Then finally the value of the [URL] field again all by itself.  Because this is the last statement of the AutoLISP expression, the current value of the [URL] will be returned by the overall expression which allows me to use the ESRI_CALCULATEFIELD to access and process entities using their feature attribute values, and still leave those field values unchanged.
This example assumes you are working with ArcGIS for AutoCAD and have downloaded and installed the ArcGIS for AutoCAD bonus tools.  It assumes you have valid hyperlink text values in a field called "URL" in the current ArcGIS for AutoCAD feature class :
I am not sure if there is an official classification for a bacon/burger/hotdog-eating vegetarian, perhaps someone could provide a link.
Example:
>Command: (load "afa_utilities")
AFA_ATTRIBUTE_SETVALUE

>Command: ESRI_CACULATEFIELD
("ANGLE" "REFNAME" "XSCALE" “URL”)
Enter the field name: URL
Enter a valid Expression (see documentation for syntax): (progn (command "ESRI_CLEARSELECTION") (command "-HYPERLINK" "Insert"  "Object" ESRI_CALC_ENT "" [URL] "" [URL] ) [URL])



FREE hit counter and Internet traffic statistics from freestats.com