Jump to content

Recommended Posts

Posted

Hi All,

 

I need to copy block definitions between two active drawings (Both drawings are open in my AutoCAD). I know this can be done by objectdbx, but I don't know how to use it for two active drawings and that's why I need your help.

 

Regards,

Satish

Posted

Hello, can anyone help me on this? :cry:

Posted

The technique is the same. It doesn't matter how you access the two documents (source and target) via odbx or via the documents collection.

Posted

Recently (yesterday evening) I found this one on internet and it looks interesting

 

 




;___________________________________________________________________________________________________________|
;
; Written By: Peter Jamtgaard copyright 2017 All Rights Reserved
;___________________________________________________________________________________________________________|
;
; Any use by unauthorized person or business is strictly prohibited.
; Include Shorthand.lsp
;___________________________________________________________________________________________________________|
;___________________________________________________________________________________________________________|
;
; General Functions
;___________________________________________________________________________________________________________|
;* (BlockFromFile strFullName strBlockName)
;* Function to duplicate a block definition from an outside drawing
;* (CopyObjects2 objOwner lstObjects objCOllection)
;* Function to create a safearray of objects and run the copyobjects method
;* (DBXDocument strFullName)
;* Function to open a DBX Document
;* (DBXBlockDefinition objDBXDocument strBlockName)
;* Function to read a DBX document and return a specified block definition
;* (ErrorTrap symFunction)
;* Function to trap an error
;* (ListToSafeArray lstObjects symObjectType)
;* Function to create a safearray
;$ Header End
; Function Headers
;___________________________________________________________________________________________________________|
;
; Function to duplicate a block definition from an outside drawing
;___________________________________________________________________________________________________________|
(defun BlockFromFile (strFullName strBlockName / lstGlobalToRelease objBlocks objDBXDocument objDBXBlockDefinition)
(if (and (setq objDBXDocument         (DBXDocument strFullName))
         (setq objDBXBlockDefinition  (DBXBlockDefinition objDBXDocument strBlockName))
         (setq objBlocks              (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
         (not (errortrap '(vla-item objBlocks strBlockName)))
         (CopyObjects2 objDBXDocument (list objDBXBlockDefinition) objBlocks)
    )
 (setq objBlockDefinition (errortrap '(vla-item objDBXBlockDefinition strBlockName)))
 (princ (strcat "\nError copying block: " strBlockName " from drawing " strFullName "..."))
)
(mapcar '(lambda (X)(errortrap (quote (vlax-release-object X)))) lstGlobalToRelease);<- Must release objects in reverse order 
objDBXBlockDefinition
)
;___________________________________________________________________________________________________________|
;
; Function to create a safearray of objects and run the copyobjects method
;___________________________________________________________________________________________________________|
(defun CopyObjects2 (objOwner lstObjects objCOllection / lstObjects2 safObjects)
(if (setq safObjects (ListToSafeArray vlax-vbobject lstObjects))
 (or (errortrap '(vla-CopyObjects objOwner
                                  safObjects
                                  objCollection
                 )
     )
     (princ "\nError using copyobjects: ")
 )
)
)
;___________________________________________________________________________________________________________|
;
; Function to open a DBX Document
;___________________________________________________________________________________________________________|
(defun DBXDocument (strFullName / objDBXDocument strACADVersion strObjectDBX)
(if (and (= (type strFullName) 'STR)
         (= (strcase (vl-filename-extension strFullName)) ".DWG")
         (setq strFullName         (findfile strFullName))
         (setq strACADVersion      (getvar "acadver"))
         (setq strObjectDBX        (strcat "ObjectDBX.AxDbDocument." (substr strACADVersion 1 2)))
         (setq objDBXDocument      (vla-GetInterfaceObject (vlax-get-acad-object) strObjectDBX ))
         (setq lstGlobalToRelease  (list objDBXDocument))
         (errortrap '(vla-open objDBXDocument strFullName))
    )
 objDBXDocument
 (princ "\nError creating DBX File Object!: ")
)
)
;___________________________________________________________________________________________________________|
;
; Function to read a DBX document and return a specified block definition
;___________________________________________________________________________________________________________|
(defun DBXBlockDefinition (objDBXDocument strBlockName / objDBXBlockDefinition objDBXBlocks)
(if (and
     (= (type strBlockName) 'STR)
     (setq objDBXBlocks           (vla-get-blocks objDBXDocument))
     (setq lstGlobalToRelease     (cons objDBXBlocks lstGlobalToRelease))
     (setq objDBXBlockDefinition  (errortrap '(vla-item objDBXBlocks strBlockName)))
     (setq lstGlobalToRelease     (cons objDBXBlockDefinition lstGlobalToRelease))
    )
 objDBXBlockDefinition
 (progn (princ "\nError reading DBX block definition object: ") nil)
)
)
;___________________________________________________________________________________________________________|
;
; Function to trap an error
;___________________________________________________________________________________________________________|
(defun ErrorTrap (symFunction / objError result)
(if (vl-catch-all-error-p
     (setq objError (vl-catch-all-apply
                    '(lambda (XYZ)(set XYZ (eval symFunction)))
                     (list 'result))))
 nil
 (or result 
     'T
 )
)
)
symVariableType lstValues
;___________________________________________________________________________________________________________|
;
; Function to create a safearray
;___________________________________________________________________________________________________________|
(defun ListToSafeArray (symVariableType lstValues / safObjects)
(if (and (setq safValues (vlax-make-safearray symVariableType (cons 0 (1- (length lstValues)))))
         (errortrap      '(vlax-safearray-fill safValues lstValues))
    )
 safValues
)
)
(princ "!")
(vl-load-com)


and else there might be some usefull code in my RlxBlk routine somewhere on this forum

 

have you looked at Lee's site? http://www.lee-mac.com/copyblockdefinition.html

 

 

 

http://www.cadtutor.net/forum/showthread.php?100670-RlxBlk-Replace-Redefine-blocks-visibility-states-preview-and-link-attributes&highlight=rlxBlk

 

 

gr. Rlx

Posted

Design Center Open Drawings tab click Blocks of the drawing with the block you want and it displays images with names of every block in the drawing. Just offering a non-code alternative.

Posted
Design Center Open Drawings tab click Blocks of the drawing with the block you want and it displays images with names of every block in the drawing. Just offering a non

 

 

Have 2 buttons in my toolbar , copy (with basepoint ) and paste , simple but I use them every day...

Posted

I'm facing problem at VLA-OPEN for opening DBX document because my file is already open

(DEFUN OPEN:DBX (FL / D)
   (IF	(< (ATOI (SUBSTR (GETVAR "ACADVER") 1 2)) 16)
     (SETQ D (VLAX-CREATE-OBJECT "ObjectDBX.AxDbDocument"))
     (SETQ D (VLAX-CREATE-OBJECT
	(STRCAT	"ObjectDBX.AxDbDocument."
		(SUBSTR (GETVAR "ACADVER") 1 2)
	)
      )
     )
   )
   (VLA-OPEN D FL)
   D
 )

Posted

If you look at Master Lee's odbxwraper : http://www.lee-mac.com/lisp/html/ObjectDBXWrapperV1-2.html

 

 


[list=1]
[*](   t
[*]            (vlax-for doc (vla-get-documents app)
[*]                (setq dwl (cons (cons (strcase (vla-get-fullname doc)) doc) dwl))
[*]            )
[*]            (foreach dwg lst
[*]                (if (or (setq doc (cdr (assoc (strcase dwg) dwl)))
[*]                        (and (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list dbx dwg))))
[*]                             (setq doc dbx)
[*]                        )
[*]                    )
[*]                    (progn
[*]                        (setq rtn
[*]                            (cons
[*]                                (cons dwg
[*]                                    (if (vl-catch-all-error-p (setq err (vl-catch-all-apply fun (list doc))))
[*]                                        (prompt (strcat "\n" dwg "\t" (vl-catch-all-error-message err)))
[*]                                        err
[*]                                    )
[*]                                )
[*]                                rtn
[*]                            )
[*]                        )
[*]                        (if sav (vla-saveas doc dwg))
[*]                    )
[*]                    (princ (strcat "\nError opening file: " (vl-filename-base dwg) ".dwg"))
[*]                )
[*]            )
[*]            (if (= 'vla-object (type dbx))
[*]                (vlax-release-object dbx)
[*]            )
[*]            (reverse rtn)
[*]        )
[*]    )
[/list]

(sorry bad copy / paste)

 

 

Anyway , there you see in the beginning the building of variable dwl (drawing list). If drawing is in this list , get it there else use vla-open

 

 

gr. Rlx

Posted (edited)

I managed with this for two active documents :)

(defun copy:block (sourcedocument targetdocument blockname)
 (vla-copyobjects
   sourcedocument
   (vlax-safearray-fill
     (vlax-make-safearray vlax-vbobject '(0 . 0))
     (list (vla-item (vla-get-blocks sourcedocument) blockname))
   )
   (vla-get-blocks targetdocument)
 )
)

Edited by satishrajdev
Posted
Design Center Open Drawings tab click Blocks of the drawing with the block you want and it displays images with names of every block in the drawing. Just offering a non

 

 

Have 2 buttons in my toolbar , copy (with basepoint ) and paste , simple but I use them every day...

 

Have 2 drop-downs in my ribbon the Paste one has Paste to Original Coordinates, &Paste Ctrl+V, Paste as Bloc&k Ctrl+Shift+V, Paste as Group, Paste Special, and Paste as Hyperlink. All macros and only Paste as Group has any code at all.

Posted

You'll get there! smilie.png

 

 

Almost weekend (but no rest thanx to the wife...)

 

 

gr. Rlx

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