adding xdata to a line

Discussion in 'AutoCAD' started by kemp, Dec 29, 2003.

  1. kemp

    kemp Guest

    I've been playing with xdata but I am having trouble getting it to do what I
    want:

    add a 2d point as xdata to a line.

    Here is a snippet of what I've tried, but fails:

    (setq lastent (entget (entlast)))
    (regapp "NEWDATA")
    (setq exdata
    '((-3 ("NEWDATA"
    (1010 . p1) ;;original is (1000 . "This is a new thing!")
    )))
    )
    (setq newent
    (append lastent exdata))
    (entmod newent)

    One issue is the ' is keeping p1 from being evaluated.

    Hope someone sees a simple error I can fix. This lisp is only very slightly
    modified from autocad's reference.

    Later I plan to add a reactor that will modify the line based on this point
    in xdata, but that is a whole nother issue I will cross when I get there :)

    Thanks a bunch, kemp
     
    kemp, Dec 29, 2003
    #1
  2. kemp

    Rudy Tovar Guest

    (cons 1010 <value>)

    Here's a easier method.

    ;(Xdata-add Data App String Appname Layer Handle 3D Real Int)

    (defun Xdata-add (Data Part String Appname Layer Handle 3D Real Int /)

    (if (not (tblsearch "appid" Part))
    (regapp (strcat "YourPart_" Part))
    )
    (setq XDlist (list (strcat "YourPart_" Part)))
    (if String (setq XDlist (append XDlist (list (cons 1000 String)))))
    (if Appname (setq XDlist (append XDlist (list (cons 1001 Appname)))))
    (if Layer (setq XDlist (append XDlist (list (cons 1003 Layer)))))
    (if Handle (setq XDlist (append XDlist (list (cons 1005 Handle)))))
    (if 3D (setq XDlist (append XDlist (list (cons 1010 3D)))))
    (if Real (setq XDlist (append XDlist (list (cons 1040 Real)))))
    (if Int (setq XDlist (append XDlist (list (cons 1070 Int)))))
    (entmod (append Data (list (list -3 Xdlist))))
    )
    --

    AUTODESK
    Authorized Developer
    www.Cadentity.com
    MASi



    But then again you'll have to construct the entire list or set the ' in the
    a proper locations.
     
    Rudy Tovar, Dec 30, 2003
    #2
  3. kemp

    David Bethel Guest

    If it just 1 string only you want to add;

    (defun add_xdata_str (e a v);;;EName APPID String_value
    (and (not (tblsearch "APPID" a))
    (regapp a))
    (and (= (type e) 'ENAME)
    (= (type v) 'STR)
    (= (type a) 'STR)
    (entmod
    (append (entget e)
    (list
    (cons -3
    (list
    (cons a
    (list (cons 1000 v))))))))))


    -David
     
    David Bethel, Dec 30, 2003
    #3
  4. kemp

    kemp Guest

    Both of these functions will be useful to me (especially in understanding
    what I'm doing). Thanks Rudy and David!

    kemp
     
    kemp, Dec 30, 2003
    #4
  5. kemp

    Thomas Smith Guest

    Here is the function I wrote & use...
    In many cases I like to store a lot of info in an entity...
    You just call this function immediately after creating the item...
    Give it a "Program Name" (Identifier) and a list of data... (lists, strings,
    numbers, whatever...)


    ;;######################################3
    ; Add XData to Last entity created
    (defun AddXdata (progNam xdatalist / xdlist pre)

    (setq lastent (entget (entlast)))
    (setq xdlist nil)

    (regapp progNam)

    (foreach Item xdatalist
    (cond
    ((= (type Item) 'INT)
    (setq pre 1070))
    ((= (type Item) 'REAL)
    (setq pre 1040))
    ((= (type Item) 'LIST)
    (setq pre 1010))
    ((= (type Item) 'STR)
    (setq pre 1000)))

    (setq wtoadd (cons pre Item))
    (if (/= Item nil)
    (setq xdlist (append xdlist (list wtoadd))))
    )

    (setq myexdata (list (list -3 (append (list progNam) xdlist))))

    (setq newent
    (append lastent myexdata))
    (entmod newent)

    (princ)
    )
    ;;########################################
     
    Thomas Smith, Dec 31, 2003
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.