Jump to content

DBX Copy and Move - move doesn't work


Vladimir74

Recommended Posts

Hi,

this code should copy only the lines from file dwg2 to file dwg1, and then move the new lines in file dwg1 by 5 along the x-axis.

Files dwg1 and dwg2 can be open or closed, and the function can be called from a third file.

 

If the files are placed in MYDOCUMENTS and called "Drawing1.dwg" and "Drawing2.dwg" the function is called with:

(DBX_copy (strcat (getvar 'MYDOCUMENTSPREFIX) "\\Drawing1.dwg") (strcat (getvar 'MYDOCUMENTSPREFIX) "\\Drawing2.dwg"))

 

For me, copying lines works fine but moving by 5 on the x-axis using "vla-move" doesn't work.

Should "vlax-invoke" be used?

 

Quote

(defun DBX_copy (dwg1 dwg2 / doc _odbx doc1 doc2 dbx1 dbx2 toCopyObjects)

  (setq doc (vlax-get-acad-object))

  (defun _odbx (/ v)

    (if (< (setq v (substr (getvar 'acadver) 1 2)) "16")

      (vla-getinterfaceobject doc "ObjectDBX.AxDbDocument")

      (vla-getinterfaceobject doc (strcat "ObjectDBX.AxDbDocument." v))

    )

  )

  (vlax-for openDoc (vla-get-documents doc)

            (setq currPath (strcase (strcat (vla-get-path openDoc) "\\" (vla-get-name openDoc))))

            (if (equal (strcase dwg1) currPath)(setq doc1 openDoc))

  )

  (if (or (setq dbx1 doc1) (and (setq dbx1 (_odbx)) (not (vl-catch-all-apply 'vla-open (list dbx1 dwg1)))))

    (progn

      (vlax-for openDoc (vla-get-documents doc)

          (setq currPath (strcase (strcat (vla-get-path openDoc) "\\" (vla-get-name openDoc))))

          (if (equal (strcase dwg2) currPath)(setq doc2 openDoc))

      )

      (if (or (setq dbx2 doc2) (and (setq dbx2 (_odbx)) (not (vl-catch-all-apply 'vla-open (list dbx2 dwg2)))))

        (progn

          (vlax-for a (vla-get-modelspace dbx2)

            (if (eq (vla-get-objectname a) "AcDbLine")

              (setq toCopyObjects (cons a toCopyObjects))

            )

          )          

          (if toCopyObjects (setq ss (vlax-invoke dbx2 'copyobjects toCopyObjects (vla-get-modelspace dbx1))))

         

          ; !!!!!!!!!!!!!!!!!!!!!!!!! doesn't work !!!!!!!!!!!!!!!!!!!!!!!!!!!!

          (setq base_point (vlax-3d-point 0.0 0.0 0.0) insertion_point (vlax-3d-point 5.0 0.0 0.0))

          (foreach x ss

            (vla-move x base_point insertion_point)

          )

         

          (if (not doc2)

            (progn

              (vl-catch-all-apply 'vla-close (list dbx2 :vlax-false))

              (vlax-release-object dbx2)

              (setq doc2 nil dbx2 nil)

            )

          )

        )

      )

      (if (not doc1)

        (progn

          (vl-catch-all-apply 'vla-saveas (list dbx1 dwg1))

          (vlax-release-object dbx1)

          (setq doc1 nil dbx1 nil)

        )

        (progn

          (vl-catch-all-apply 'vla-save (list dbx1))

          (vlax-release-object dbx1)

          (setq doc1 nil dbx1 nil)

        )

      )

    )

    (print "Something went wrong ;(")

  )

)

 

Regards,

Vladimir

 

Drawing1.dwg Drawing2.dwg

Link to comment
Share on other sites

Everything works as it should. A shift of 5 was too small to notice. I didn't notice that I drew lines that were much longer than 5 units

Morning is wiser than evening.

 

Regards,

Vladimir

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...