Replacing extended data

Replacing extended data

saitoib
Advocate Advocate
1,315 Views
11 Replies
Message 1 of 12

Replacing extended data

saitoib
Advocate
Advocate
Hi all
 
I have added the following extended data to the polyline data.
(-3 ("Xdata" (1040 . 90.0) (1040 . 4.1) (1070 . 1))))
Change this data to (-3 ("Xdata" (1040 . 135.0) (1040 . 2.5) (1070 . 1)))).
Currently, I am deleting the extended data, and then creating each new item of the extended data and adding it to the original data.
Is it possible to directly replace an item?
 
thank you.
 
Saitoib
0 Likes
Accepted solutions (2)
1,316 Views
11 Replies
Replies (11)
Message 2 of 12

john.uhden
Mentor
Mentor
Accepted solution

Note that -3 is the identifying code for all xdata.

Let's beak it down so see it differently.

(-3 ("Xdata" (1040 . 135.0) (1040 . 2.5) (1070 . 1))))
Hmm, that last paren is in excess, unless you meant...
(setq allxdata '(-3 ("Xdata" (1040 . 135.0) (1040 . 2.5) (1070 . 1))))
Then,
(setq myxdata (assoc "Xdata" allxdata))...
("Xdata" (1040 . 135.0) (1040 . 2.5) (1070 . 1))
Now you have a list in which you can subst all you want, e.g.
(setq newxdata (subst '(1040 . 90)'(1040 . 135) myxdata))
and
(setq newxdata (subst '(1070 . 2)'(1070 . 1) newxdata))
Then,
(setq allxdata (subst newxdata myxdata allxdata))
Then, if ent is the symbol for all the entity data...
(setq ent (subst allxdata (assoc -3 ent) ent))
(entmod ent)

Note:  My AutoCAD isn't working so I can't test my theory, but not to worry as there are plenty of brainiacs around here from all over the world who would love to correct me.

I think that's the way I used to do it, but I think I found using ActiveX was easier.  I would have to look at one of my files to see 'cause I don't remember how.

John F. Uhden

Message 3 of 12

Sea-Haven
Mentor
Mentor

Like John have a look at this and part2.

 

Extended Entity Data - Part 1 | AfraLISP

 

Pretty sure had xdata vl somewhere, starting with something like this not tested. Need to add get xdata name.

; tests for object with xdata and trys to get values.
; By AlanH Jan 2020 

(defun c:testxdata ( / ent val vals x codes datas)
(while (setq ent  (car (entsel "\nSelect an object Enter to exit")))
(if (= (vla-get-HasExtensionDictionary (vlax-ename->vla-object  ent )):vlax-true)
  (progn
    (vla-GetXData (vlax-ename->vla-object (cdr (assoc -1 (entget ent)))) "TrimbleName" 'codes 'datas)
    (if (/= datas nil) 
      (progn
      (setq val '())
      (setq vals (vlax-safearray->list datas))
      (repeat (setq x (length vals))
        (setq val (cons (vlax-variant-value (nth (setq x (- x 1)) vals)) val))
		(princ val)
      )
      )
	  (alert "Object has xdata set but contains no data")
    )
  )
(alert "Please pick again object has no xdata")
)
)
(princ)
)

It is always a good idea to post a sample dwg.

0 Likes
Message 4 of 12

saitoib
Advocate
Advocate

@john.uhden 

Your explanation was very, very helpful.
Thank you very much.

Saitoib
0 Likes
Message 5 of 12

saitoib
Advocate
Advocate

@Sea-Haven 

Thank you your reply

 

I tried to check the code you posted, but I get vlax-false for the following entity.
Is this entity not good for extended data?

((-1 . <Entity name: 292d111ad60>) (0 . "LWPOLYLINE") (330 . <Entity name: 292d111b9f0>) (5 . "686") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "2D") (100 . "AcDbPolyline") (90 . 4) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 150.0 150.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 350.0 150.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 350.0 50.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 150.0 50.0) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0) (-3 ("Xdata" (1040 . 90.0) (1040 . 4.1) (1070 . 1))))
Saitoib
0 Likes
Message 6 of 12

hak_vz
Advisor
Advisor

Apart from explanations from @john.uhden  and @Sea-Haven  you can check this link

about using vl function for working with xdata.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 12

АлексЮстасу
Advisor
Advisor

Hi, saitoib,  Sea-Haven, hak_vz,

 

Since you are engaged in XData, I invite you to the XDTOOLS project. You may want to participate if you are interested.

You can offer already ready-made programs or write specifically for the project.

 

saitoib, I have already assembled a fairly representative collection of programs for XData in the forums. Perhaps you will find some of them useful.

Now there are 33 programs in the collection.


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

0 Likes
Message 8 of 12

john.uhden
Mentor
Mentor
Accepted solution

@Sea-Haven & @saitoib 

I found my code to get/set xdata via ActiveX.

It's very old, so I'm not sure it will still work, but it smells okay.

;;------------------------------------
;; Function to get Xdata via ActiveX.
;; Taken from work on Spot_reactor and
;; added (02-15-03)
(defun @GetXdata (Object Appid / Types Data XData)
  (vl-catch-all-apply
    (function
      (lambda ()
        (or
          (= (type Object) 'VLA-Object)
          (setq Object (vlax-ename->vla-object Object))
        )
        (vla-getxdata Object Appid 'Types 'Data)
        (setq Types (vlax-safearray->list Types))
        (setq Data  (mapcar 'vlax-variant-value (vlax-safearray->list Data)))
        (setq Data
          (mapcar
            (function
              (lambda (x)
                (if (= (type x) 'Safearray)
                  (vlax-safearray->list x)
                  x
                )
              )
            )
            Data
          )
        )
        (setq Xdata (mapcar 'cons Types Data))
      )
    )
  )
  (cdr Xdata)
)
;;--------------------------------------
;; Function to set Xdata via ActiveX.
;; Adapted from work on Spot_reactor and
;; added (02-15-03)
(defun @SetXData (Object Appid XData / Types Data N Var)
  (not
    (vl-catch-all-error-p
      (vl-catch-all-apply
        (function
          (lambda ()
            (or
              (= (type Object) 'VLA-Object)
              (setq Object (vlax-ename->vla-object Object))
            )
            (setq Xdata (cons (cons 1001 Appid) Xdata)
                  Types (mapcar 'car XData)
                  Data  (mapcar 'cdr XData)
                  N     (1- (length Xdata))
            )
            (setq Types
              (progn
                (setq Var (vlax-make-safearray vlax-vbInteger (cons 0 N)))
                (vlax-safearray-fill Var Types)
                (vlax-make-variant Var 8194)
              )
            )
            (setq Data
              (mapcar
                (function
                  (lambda (x)
                    (if (listp x)
                      (vlax-make-safearray vlax-vbDouble (cons 0 (1- (length x))))
                      x
                    )
                  )
                )
                Data
              )
            )
            (setq Data
              (progn
                (setq Var (vlax-make-safearray vlax-vbVariant (cons 0 N)))
                (vlax-safearray-fill Var Data)
                (vlax-make-variant Var 8204)
              )
            )
            (vla-setxdata Object Types Data)
          )
        )
      )
    )
  )
)

 

John F. Uhden

0 Likes
Message 9 of 12

АлексЮстасу
Advisor
Advisor

... For example, if we talk about replacing XData.
A common task is to replace one App with another. Suppose the polyline has an App for an oil pipeline, and need to replace it with an App for a gas pipeline. Etc.
And such a program is definitely needed for the use of XData.


But there is also a special critical task - for Apps with the same names, but with a different set and/or sequence of data field codes. Such apps can be created due to inattention, when copying from other files, when working with some applications, etc.
Similar different, but eponymous Apps need to be able to find and correct.
To find them, there is already a function.
Сan create a program that requests a sample object with "correct" fields-codes, finds objects with the same name but different fields-codes, and replaces them with "correct" ones, transferring data if possible.

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

0 Likes
Message 10 of 12

saitoib
Advocate
Advocate

Thank you all for your guidance and support.
I know it will take some time, but I will try to learn.

Saitoib
0 Likes
Message 11 of 12

АлексЮстасу
Advisor
Advisor

Now my friend also said that entmod [after entsel...] for non-existent RegApps may not write XData.
There is no such problem for existing RegApps.
He tried to check for different names, registers, encodings, different conditions, etc.

So it turns out that entmod can respond to existing/non-existing RegApps?
True, he's new to Lisp.

 


-- Alexander, private person, pacifist, english only with translator 🙂 --

Object-modeling _ odclass-odedit.com _ Help

0 Likes
Message 12 of 12

john.uhden
Mentor
Mentor
I am pretty sure that if the app is not yet registered you must regapp it
first.

John F. Uhden