Jump to content

Copy and paste xdata from objects (polylines). Help Needed Please


ghostware

Recommended Posts

This may help you:

 

(defun CopyAndPasteXData( RegisteredApplicationName / Entity1st Entity2nd XDataToCopy )
(setq Entity1st (car (entsel "\nSelect entity to copy from: ")))

(setq XDataToCopy (assoc -3 (entget Entity1st (list RegisteredApplicationName))))
(if (not XDataToCopy) (exit))

(setq Entity2nd (car (entsel "\nSelect entity to paste on: ")))

(entmod (append (entget Entity2nd) (list XDataToCopy)))
)

 

Regards,

Link to comment
Share on other sites

Nice one Msasu :)

 

An alternative approach:

 

(defun c:CpyX (/ ss typ val dss sel)
 (vl-load-com)

 (prompt "\nSelect Source Polyline...")
 (while
   (progn
     (setq ss (ssget "_:S:E" '((0 . "*LINE"))))
     (cond ((not ss)
            (princ "\n** Nothing Selected **"))
           ((progn
              (vla-getXData
                (setq Obj
                  (vlax-ename->vla-object
                    (ssname ss 0))) "" 'typ 'val)
              (or (not typ) (not val)))
            (princ "\n** No XData Found **")))))

 (if (setq dss (ssget '((0 . "*LINE"))))
   (progn
     (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet
                               (vla-get-ActiveDocument
                                 (vlax-get-acad-object))))
       (vla-SetXdata Obj typ val))
     (vla-delete sel)))

 (princ))

Link to comment
Share on other sites

No problem - to answer your original question, this will get all XData associated with an object:

 

(defun c:getX (/ ent obj typ val)
 (vl-load-com)

 (while
   (progn
     (setq ent (car (entsel "\nSelect Object: ")))
     (cond ((not ent) (princ "\n** Nothing Selected **"))
           ((progn
              (vla-getXData
                (setq Obj (vlax-ename->vla-object ent)) "" 'typ 'val)
              (or (not typ) (not val)))
            (princ "\n** No XData Found **")))))

 (print (apply 'mapcar (cons 'cons (list (vlax-safearray->list typ)
                                         (mapcar 'vlax-variant-value
                                                 (vlax-safearray->list val))))))

 (princ))

Link to comment
Share on other sites

  • 2 months later...

Lee Mac

 

This is great. how can I modify the c:CpyX so that I can copy XDATA from any object to another object.

 

Specifically, I am trying to copy XDATA from one AutoCAD Block to another.

Link to comment
Share on other sites

Thanks, here are the generic Functions:

 

(defun c:getX (/ ent obj typ val)
 (vl-load-com)

 (while
   (progn
     (setq ent (car (entsel "\nSelect Object: ")))
     (cond ((not ent) (princ "\n** Nothing Selected **"))
           ((progn
              (vla-getXData
                (setq Obj (vlax-ename->vla-object ent)) "" 'typ 'val)
              (or (not typ) (not val)))
            (princ "\n** No XData Found **")))))

 (print (apply 'mapcar (cons 'cons (list (vlax-safearray->list typ)
                                         (mapcar 'vlax-variant-value
                                                 (vlax-safearray->list val))))))

 (princ))


(defun c:CpyX (/ ent obj ss sel)
 (vl-load-com)

 (while
   (progn
     (setq ent (car (entsel "\nSelect Object: ")))
     (cond ((not ent) (princ "\n** Nothing Selected **"))
           ((progn
              (vla-getXData
                (setq Obj (vlax-ename->vla-object ent)) "" 'typ 'val)
              (or (not typ) (not val)))
            (princ "\n** No XData Found **")))))

 (if (setq ss (ssget))
   (progn
     (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet
                               (vla-get-ActiveDocument
                                 (vlax-get-acad-object))))
       (vla-SetXdata Obj typ val))
     (vla-delete sel)))

 (princ))


Originally posted here:

 

http://www.theswamp.org/index.php?topic=30445.0

Link to comment
Share on other sites

Actually I think by just playing around I got it...

See any problems with this?

 

(defun c:CyX (/ ss typ val dss sel)

(vl-load-com)

(prompt "\nSelect Source Block...")

(while

(progn

(setq ss (ssget "_:S:E" '((0 . "INSERT"))))

(cond ((not ss)

(princ "\n** Nothing Selected **"))

((progn

(vla-getXData

(setq Obj

(vlax-ename->vla-object

(ssname ss 0))) "" 'typ 'val)

(or (not typ) (not val)))

(princ "\n** No XData Found **")))))

 

(prompt "\nSelect Destination Block...")

(if (setq dss (ssget '((0 . "INSERT"))))

(progn

(vlax-for Obj (setq sel (vla-get-ActiveSelectionSet

(vla-get-ActiveDocument

(vlax-get-acad-object))))

(vla-SetXdata Obj typ val))

(vla-delete sel)))

(princ))

Link to comment
Share on other sites

Actually I think by just playing around I got it...

See any problems with this?

 

 
(defun c:CyX (/ ss typ val dss sel)
 (vl-load-com)
 (prompt "\nSelect Source Block...")
 (while
   (progn
     (setq ss (ssget "_:S:E" '((0 . "INSERT"))))
     (cond ((not ss)
            (princ "\n** Nothing Selected **"))
           ((progn
              (vla-getXData
                (setq Obj
                  (vlax-ename->vla-object
                    (ssname ss 0))) "" 'typ 'val)
              (or (not typ) (not val)))
            (princ "\n** No XData Found **")))))
 
 (prompt "\nSelect Destination Block...")
 (if (setq dss (ssget '((0 . "INSERT"))))
   (progn
     (vlax-for Obj (setq sel (vla-get-ActiveSelectionSet
                               (vla-get-ActiveDocument
                                 (vlax-get-acad-object))))
       (vla-SetXdata Obj typ val))
     (vla-delete sel)))
 (princ))

Link to comment
Share on other sites

Any body can help me to get the area of any object directl to excel sheet? It means, How to get the Object area directly to excel sheet? Is there any Lisp program for this? If any body has,please help me. Thank you.

Link to comment
Share on other sites

Any body can help me to get the area of any object directl to excel sheet? It means, How to get the Object area directly to excel sheet? Is there any Lisp program for this? If any body has,please help me. Thank you.

 

This question is unrelated to the thread in which it is posted, please ask a mod to move it to a new thread, or delete it if a new thread has been made.

Link to comment
Share on other sites

  • 5 years later...

Bringing this thread back from the dead.

Lee... I have searched around and couldn't find what I was looking for. I have a block that reads the xdata of a polyline from civil 3d. How would I be able to copy that block around and edit the xdata for each block to a given polyline? The other routine you posted copies all the data to the new block. I would just need it to copy the second line and leave all other parts of the data untouched.

 

xdlist gives me this:

* Code 1000, ASCII string: Polyline

* Code 1000, ASCII string: 19CEE

* Code 1000, ASCII string:

* Code 1000, ASCII string: None

* Code 1000, ASCII string: 0

* Code 1000, ASCII string: 2

* Code 1000, ASCII string: 2

* Code 1040, Real number: 0.00

* Code 1000, ASCII string: 0

* Code 1000, ASCII string: 2

* Code 1000, ASCII string: 0

* Code 1000, ASCII string: 2

* Code 1040, Real number: 0.00

* Code 1000, ASCII string: 0.00

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...