Results 1 to 2 of 2

Thread: Write XData to an entity

  1. #1
    Active Member
    Join Date
    2005-02
    Posts
    95
    Login to Give a bone
    0

    Default Write XData to an entity

    I have a some object to create new. I want to write xdata to an entity. like...

    member size, part no. and member length etc...

    When I am creating a new member (angle) I have to give the member no. and part no. and lenght of member is calculating automatically when the first time intoduce new member.

    when I want to create that member detail drawing in separate. at that time I select object and all three (as above) data will take automatically.

    some one have any idea. how to do it or can anyone give me code.

    Thanx.

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Write XData to an entity

    Here is some code that will attach a list of sublists to an entity or vla-object

    ;Create a list of sublists of your data

    (setq lstOfSublists (list (list "Partnumber" 1)(list "MemberNumber" 2)))

    ;Attach the data using the setxdata funtion

    (setxdata entSelection lstOfSublists)

    ;retrieve the xdata using the getxdata function

    (setq lstOfSublists (getxdata entSelection))

    See routine code below

    Peter

    Code:
    ; The setxadata function will add a list of sublists to an object as xdata.
    ; The first item in each sublist is a unique string application name
    (defun SetXData (objSelection lstOfSubLists / DataItem lstData
                     intDataType lstOfSublistsDXFCodes lstOfSublistsValues 
                     safDXFCodes safDataValues)                
     (if (= (type objSelection) 'ENAME)
      (setq objSelection (vlax-ename->vla-object objSelection))
     )
     (foreach lstData lstOfSublists
      (setq lstOfSublistsDXFCodes (cons 1001 lstOfSublistsDXFCodes)
            lstOfSublistsValues   (cons (car lstData) lstOfSublistsValues))
      (RegApp (car lstData))
      (foreach DataItem (cdr lstData)
       (cond    ; Determine the data type and corrusponding DXF Code
        ((= (type DataItem) 'INT) 
         (if (> DataItem 100000)
          (setq intDataType  1071)                          ; Long    Data Type 
          (setq intDataType  1070)                          ; Integer Data Type
         )
        )                                                   
        ((= (type DataItem) 'REAL)(setq intDataType  1040)) ; Real Data Type
        ((= (type DataItem) 'STR) 
         (if (or (= DataItem "{")(= DataItem "}"))          ; String Data Type     
          (setq intDataType  1002)
          (setq intDataType  1000)
         )
        )
       )
       (setq lstOfSublistsDXFCodes (cons intDataType lstOfSublistsDXFCodes)
             lstOfSublistsValues   (cons DataItem    lstOfSublistsValues)
       )
      )
     )
     (setq safDXFCodes   (listToSafearray vlax-vbinteger
                          (reverse lstOfSublistsDXFCodes))                     
           safDataValues (listToSafeArray vlax-vbvariant
                          (reverse lstOfSublistsValues)))
     (errortrap '(vla-setXData objSelection safDXFCodes safDataValues)))
    
    ; Returns a list of sublists that include a application name as the first
    ; Item in every sublist and data for the remaining members
    
    (defun C:GetXdata ()
     (getxdata (car (entsel "\nSelect object with Xdata: ")))
    )
    
    (defun GetXdata (objSelection / intCount lstAll lstSub safDXFValues safDXFValues)
     (if (= (type objSelection) 'ENAME)
      (setq objSelection (vlax-ename->vla-object objSelection))
     )
     (vla-getxdata objSelection "" 'safDXFCodes 'safDXFValues) 
     (if (and safDXFCodes
              safDXFValues
         )
      (progn
       (setq lstDXFCodes  (vlax-safearray->list safDXFCodes)  
             lstDXFValues (mapcar 'variant-value (vlax-safearray->list safDXFValues))  
             intCount 0
       )
       (foreach intDXFCode lstDXFCodes
        (if (= intDXFCode 1001)
         (if lstSub
          (setq lstAll (cons (reverse lstSub) lstAll)
                lstSub (list (nth intCount lstDXFValues))
          )
          (setq lstSub (list (nth intCount lstDXFValues)))  
         )
         (setq lstSub (cons (nth intCount lstDXFValues) lstSub))   
        )
        (setq intCount (1+ intCount))
       )
       (if lstSub (reverse (cons (reverse lstSub) lstAll)))
      )
     )
    )
    ; Convert list to Safearray
    (defun ListToSafearray (symVariableType lstValues / safValues)
     (setq safValues (vlax-make-safearray symVariableType (cons 0 (1- (length lstValues)))))
     (vlax-safearray-fill safValues lstValues)
    )
    
    Last edited by peter; 2007-08-23 at 10:08 AM.

Similar Threads

  1. Replies: 6
    Last Post: 2015-08-31, 04:05 PM
  2. Delete XData with a specified application name from a selected entity
    By peter in forum Bridging the Gap: LISP -> .NET -> LISP
    Replies: 6
    Last Post: 2015-06-09, 03:10 PM
  3. Help me with xdata
    By rdogomes in forum AutoLISP
    Replies: 13
    Last Post: 2010-09-16, 06:42 PM
  4. How can I write a Xdata to a new fresh entity
    By avinash00002002 in forum AutoLISP
    Replies: 1
    Last Post: 2007-04-13, 03:38 AM
  5. Proxy Entity Code 310 to Normal Entity
    By KevinBarnett in forum AutoCAD General
    Replies: 2
    Last Post: 2005-05-26, 07:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •