Newsgroups: alt.cad.autocad
Subject: Extended data in ADS: Answers and Questions
From: rrenzett@zeus.calpoly.edu (Roberto Bertini Renzetti)
Date: Tue, 21 Jul 1992 23:56:38 GMT
Organization: California Polytechnic State University, San Luis Obispo

Hi!

	I while ago I asked if anyone knew how to create extended data using
the ADS in AutoCAD. No one answered.... :-(  ......
	So, after reading again and again the ADS manual and trying different
approaches, I finally figured out one way. Maybe there are easier ways, so if
you know any, please let me know. This is what I do:
	- I use ads_command to create a pline;
	- then I select the entity and get its data;
	- I append my XDATA (just a integer value);
	- finally I ask ACAD to modify the data in its database.

	The trick that took I while to find out is that the ads_buildlist
command accepts the flag -3 (to indicate the presence of extended data) 
WITHOUT a pair!!!! (Even though the manual specifies that ads_buildlist requires
PAIRS of data!!!!)
	So, the following code does what I described above. I tested it and
it works. I used the XDATA.LSP lisp program (that comes in the Bonus disk)
to verify if the extended data was being created, and it was!

    .
    .
    .
    struct resbuf *entlist, *objrb, *temprb;
    int status;
    ads_name entname;
    struct resbuf *eb;

    .
    .
    .
    /* draws polyline */
    ads_command (RTSTR, "pline", RT3DPOINT, pt1, RTSTR, "w",
                         RTREAL, THICK,
                         RTREAL, THICK,
                         RT3DPOINT, pt2, RTSTR, "", 0);

    /* Constructs list with extended data to be attached in the PLINE data */
    /* application name was already registred before */
    entlist = ads_buildlist (
                             -3,
                             1001, APPNAME,
                             1070, CODE,
                             NULL);
    if (entlist == NULL)
      ads_fail("Unable to create result buffer list for obj...\n");

    /* get name of the last entity drawn, i.e., the obj */
    ads_entlast (entname);
    /* get obj (pline) data */
    objrb = ads_entget(entname);
    temprb = objrb;
    /* Traverse the list of obj data until you reach the last element */
    while (temprb->rbnext != NULL)
    {
      temprb = temprb->rbnext;
    }
    temprb->rbnext = entlist; /* this appends the XDATA into the obj data */

    /* Here I print out the xdata just to see if everything is OK */
 ads_printf("new objrb data:\n");
 for (eb=objrb; eb != NULL; eb=eb->rbnext)
  printdxf(eb);    /* this is the same as the example in the ADS manual,
                      but modified to display XDATA codes such as -3, etc */

    /* modify obj data (i.e., append new data to the ACAD database) */
    status = ads_entmod (objrb);
    if (status != RTNORM)
       ads_fail("Hooks: Unable to create obj entity...\n");

    .
    .
    .

------------------------------------------------------------------------

	So, the above code works and creates the extended data. The problem
that I have now is on how to retrieve this extended data from with ADS.
(I can retrieve from AutoLISP by using the XDLIST command defined in the
XDATA.LSP file).
	The example in the ADS manual (pg. 79) has typing mistakes in it...
(some where corrected in the readme file). But in the line where you see 
the ads_entgetx () command there is a variable, "work_ent_addr" that is not 
defined anywhere... and if look the the description of the ads_entgetx command
it says that you have to use a ads_name....
	I tried a lot to do a little ADS function that behaves in a similar
way to the XDLIST command, but it didn't work.
	Does anyone know how to use the ads_entgetx() command?


Any hints on ads_entgetx will help a lot!!!

thanks

Roberto Bertini Renzetti
(rrenzett@athena.calpoly.edu)


(the following code is my attempt to do a XDLIST in ADS... but it doesn't work.)
(Any comments and hints are helpful!!!! Thanks again)

/*-----------------------------------------------------------------------------
   list_dxf()

   Prints the DXF codes of a selected entity.
-----------------------------------------------------------------------------*/
void list_dxf()
{
  struct resbuf *objrb, *temprb, appnamerb;
  ads_name objname;
  ads_point pt;

  /* Create result buffer with application name. */
  appnamerb.restype = RTSTR;
  strsave (appnamerb.resval.rstring, APPNAME);

  /* select entity and print DXF codes, including extended data codes. */
  if (ads_entsel("Please select an object: \n", objname, pt) == RTNORM)
  {
    objrb = ads_entgetx (objname, &appnamerb); 

    temprb=objrb;

    for (temprb = objrb; temprb != NULL; temprb=temprb->rbnext)
      printdxf(temprb);  /* same as example in ADS manual, but modified to
                            handle XDATA codes such as -3, etc... */
  }
  ads_relrb(objrb);
  ads_relrb(temprb);
}