Jump to content

Copy all object from another drawing to the current drawing


Recommended Posts

Posted

Hi guys,

 

How do you do an ssget X from another drawing and copying all those into the current drawing?

 

Notes:

 

  • There's only one layer in there and it's unlocked
  • Only lines are present in that drawing.
  • The reference point to be copied is the same and does not need to be altered.

 

So it's a pretty simple drawing where I just want to copy those lines from the drawing.

 

Thanks,

Jonathan Handojo

Posted (edited)

What is wrong with Copy/Paste to original coordinates? Or Copy with base point/Paste

Edited by Stefan BMR
Posted

Because there are so many other drawings instead of just one.

Posted

Try this. It doesn't account for any reference point, if the position is not correct you might need to move the objects.

(defun c:cpl ( / acobj acdoc model docs dbx acver file path doc l)
  (setq acobj (vlax-get-acad-object)
        acdoc (vla-get-activedocument acobj)
        model (vla-get-modelspace acdoc)
        docs  (vla-get-documents acobj)
  )
  (setq dbx
    (vla-GetInterfaceObject acobj
      (if
        (< (setq acver (atoi (getvar "ACADVER"))) 16)
        "ObjectDBX.AxDbDocument"
        (strcat "ObjectDBX.AxDbDocument." (itoa acver))
      )
    )
  )
;;;  (setq reference_point (vlax-3d-point 0.0 0.0 0.0))
  (while
;;;    (and
      (progn
        (princ)
        (setq file (getfiled "Select file to import lines" (cond (path) ((getvar 'dwgprefix))) "dwg" 2))
      )
;;;      (setq insertion_point (getpoint "\nSpecify insertion point: "))
;;;      (setq insertion_point (vlax-3d-point insertion_point))
;;;    )
    (setq path (strcat (vl-filename-directory file) "\\")
          doc nil
          l nil
    )
    (vlax-for x docs
      (if
        (eq (vla-get-fullname x) file)
        (setq doc x)
      )
    )
    (or doc (vla-open dbx file :vlax-true))
    (vlax-for obj (vla-get-modelspace (cond (doc) (dbx)))
      (if
        (eq (vla-get-objectname obj) "AcDbLine")
        (setq l (cons obj l))
      )
    )
    (if l
;;;      (foreach x
        (vlax-invoke (cond (doc) (dbx)) 'copyobjects l model)
;;;        (vla-move x reference_point insertion_point)
;;;      )
    )
    (princ (strcat "\n" (itoa (length l)) " lines imported from " (strcase (vl-filename-base file))))
  )
  (vlax-release-object dbx)
  (princ)
)

 

Posted
1 hour ago, Stefan BMR said:

Try this. It doesn't account for any reference point, if the position is not correct you might need to move the objects.


(defun c:cpl ( / acobj acdoc model docs dbx acver file path doc l)
  (setq acobj (vlax-get-acad-object)
        acdoc (vla-get-activedocument acobj)
        model (vla-get-modelspace acdoc)
        docs  (vla-get-documents acobj)
  )
  (setq dbx
    (vla-GetInterfaceObject acobj
      (if
        (< (setq acver (atoi (getvar "ACADVER"))) 16)
        "ObjectDBX.AxDbDocument"
        (strcat "ObjectDBX.AxDbDocument." (itoa acver))
      )
    )
  )
;;;  (setq reference_point (vlax-3d-point 0.0 0.0 0.0))
  (while
;;;    (and
      (progn
        (princ)
        (setq file (getfiled "Select file to import lines" (cond (path) ((getvar 'dwgprefix))) "dwg" 2))
      )
;;;      (setq insertion_point (getpoint "\nSpecify insertion point: "))
;;;      (setq insertion_point (vlax-3d-point insertion_point))
;;;    )
    (setq path (strcat (vl-filename-directory file) "\\")
          doc nil
          l nil
    )
    (vlax-for x docs
      (if
        (eq (vla-get-fullname x) file)
        (setq doc x)
      )
    )
    (or doc (vla-open dbx file :vlax-true))
    (vlax-for obj (vla-get-modelspace (cond (doc) (dbx)))
      (if
        (eq (vla-get-objectname obj) "AcDbLine")
        (setq l (cons obj l))
      )
    )
    (if l
;;;      (foreach x
        (vlax-invoke (cond (doc) (dbx)) 'copyobjects l model)
;;;        (vla-move x reference_point insertion_point)
;;;      )
    )
    (princ (strcat "\n" (itoa (length l)) " lines imported from " (strcase (vl-filename-base file))))
  )
  (vlax-release-object dbx)
  (princ)
)

 

 

Wow! It actually works! I'll have to study this code in detail. I was thinking so hard how to get objects from the other drawing. Nice one!

 

The points works as expected. It's exactly where I want the lines to go.

 

I'll just replace the while loop with foreach and a list of filenames to go with. Thanks a bunch man!

Posted

have you check Leemac's Copy To Drawing?

http://www.lee-mac.com/copytodrawing.html

 

Quote

This program enables the user to copy a selection of objects to a selected set of drawings, without opening the drawings in the AutoCAD Editor.

 

Posted
2 minutes ago, Jonathan Handojo said:

Yes, I did. That copies object FROM the current drawing instead of TO the current drawing.

 

Oh i misread your post sorry...

 

Posted

Insert dwg at 0,0 explode once then purge block other dwg name, not much simpler.

  • Like 1
Posted

Then do reverse, open all (or part of its-you said it is a lots) dwgs you need to copy from, select destination dwg in Lee dialog box...

Posted
17 hours ago, Jonathan Handojo said:

Yes, I did. That copies object FROM the current drawing instead of TO the current drawing.

OK Try Lee Acs Steal routine:

http://www.lee-mac.com/steal.html

Posted
7 hours ago, Steven P said:

OK Try Lee Acs Steal routine:

http://www.lee-mac.com/steal.html

Yeah, and as a matter of fact,I use it everyday at work. It imports every dictionary fine on that drawing. I want to copy the entity itself into the drawing (the lines). Stefan solved my enquiry.

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