Author Topic: adding a list to xdata  (Read 2236 times)

0 Members and 1 Guest are viewing this topic.

whdjr

  • Guest
adding a list to xdata
« on: December 29, 2004, 01:00:48 PM »
Is it possible to add a list as an entry for xdata to an object.  My thought was to make it into a string, but I couldn't for the life of me figure how to do that.  Is it possible to turn a list into a string or is there a better way to add a list to xdata?

SMadsen

  • Guest
adding a list to xdata
« Reply #1 on: December 29, 2004, 01:39:05 PM »
No lists as the list data type goes. But you can use the 1002 code to nest bunches of data. Check out the help file for use of the 1002 control strings.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
adding a list to xdata
« Reply #2 on: December 29, 2004, 02:00:41 PM »
Also, have you seen this thread?
http://theswamp.org/phpBB2/viewtopic.php?t=1691
TheSwamp.org  (serving the CAD community since 2003)

whdjr

  • Guest
adding a list to xdata
« Reply #3 on: December 29, 2004, 02:35:21 PM »
Stig, Do you mean then control codes "{" and "}".  That seems like it would be too difficult and cumbersome to break up and recreate the list.

Mark, I read the posts and it looks interesting, but I didn't see how you would apply this to a specific object.  Plus I've already gotten the groud work code written for xdata.  

I just ran into a situation where I might like to put more than one (assoc -3) with an object, but I see that is not possible.  I may have to break down and do it Stig's way.

Any more advice would be helpful.

Anonymous

  • Guest
adding a list to xdata
« Reply #4 on: December 30, 2004, 09:58:30 AM »
Here is my solution for xdata

The syntax is:

(setxdata objSelection (list (list "test1" "1" 1 1.5)(list "test2" "a")))

where objSelection is the object accepting the xdata and the list of sublists include the application name as the first item in each sublist and then the additional data for each application.

(getxdata objSelection) will return the original list of sublists plus a sublist for other xdata that might be on the object.

Peter Jamtgaard


Code: [Select]

; The setxadatalist 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 debug (princ "\nSetXdata: "))
 (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) (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)))
 (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)
;  (print strXdata)  (if DEBUG (print "GetXdata"))
 (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))  
   )
   (print lstDXFCodes)
   (print lstDXFValues)  
   (setq 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)))
  )
 )
)
[/code]