TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Serge J. Gianolla on July 13, 2004, 07:32:16 PM
-
Hi,
Anyone here aware of a way to add a block to a drawing that is not open!! I am thinking perhaps via dbx!
Ta
-
So no takers! How about a good soul that can translate the Opening a drawing with ObjectDBX part into VLisp?:
Registering the ObjectDBX environment
Sub regObjectDBX()
Shell "REGSVR32 /s " + Chr$(34) + Tools.findfile("AXDB15.DLL", True) + Chr$(34), 0
End Sub
Opening a drawing with ObjectDBX
Function dbxOpen(fn As String) As AXDB15Lib.AxDbDocument
If Dir(fn) <> "" Then
Dim dwgX As New AXDB15Lib.AxDbDocument
dwgX.Open (fn)
If Err.Number <> 0 Then
If Err.Number <> -2147467259 Then 'Invalid filename
regObjectDBX
dwgX.Open (fn)
End If
End If
Set dbxOpen = dwgX
End If
End Function
-
Shame on me but I haven't gotten around to mess with ObjectDBX yet. I know Peter Jamtsgaard and Robert R. Bell are pretty good with it so .. if you can get them to pop in here I'm sure you'll have some takers.
-
Example for using ObjectDBX. (http://www.cadvault.com/forums/showthread.php?t=9070)
Once you have the DBXdoc open, you can use most any vla/vlax properties & methods on it. Selection sets are NOT allowed, but pretty much everything else goes.......One minor problem, when saving a drawing that is edited through ObjectDBX the drawing thumbnail is lost.
HTH,
Jeff
-
Interesting... I'll have to check that out in more detail
-
Thanks Jeff, but in the meantime I found this short routine from TT.
;; COPYBLOCK.LSP Copyright ©1999 Tony Tanzillo
;;
;; AutoCAD 2000 Visual LISP / ObjectDBX Example
;;
;; http://www.caddzone.com
;; tony.tanzillo@caddzone.com
;;
;; This example demonstrates how to use ObjectDBX in
;; Visual LISP to directly add blocks defined in any
;; drawing file, to the current drawing.
;;
;; (CopyBlock <FileName> <BlockName>)
;;
;;This function copies the definition of the block whose name is <BlockName> (a string), from the .DWG
;;file whose name is <FileName> (a string), into the current drawing's block table.
;;
;; CopyBlock returns the new copy of the block
;; object in the current drawing's block table.
;;
;; Note that this example performs none of the
;; error checking that is required, and does not
;; attempt to determine what actually happened
;; within the deep clone operation.
(vl-load-com)
(setq *acad* (vlax-get-acad-object))
(defun CopyBlock (DwgName BlkName / blocks dbxDoc)
(setq blocks
(vla-get-blocks
(vla-get-ActiveDocument *acad*)
)
)
(setq dbxDoc
(vla-GetInterfaceObject
*acad*
"ObjectDBX.AxDbDocument"
)
)
(vla-open dbxDoc DwgName)
(vla-CopyObjects
dbxDoc
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbObject
'(0 . 0)
)
(list
(vla-item
(vla-get-blocks dbxDoc)
BlkName
)
)
)
blocks
)
(vlax-release-object dbxDoc)
(vla-item blocks BlkName)
)
(princ "\n(CopyBlock <DrawingFileName> <BlockName>)")
(princ)
;;;;;;;;;;;;;;;;; CopyBlock.lsp ;;;;;;;;;;;;;;;;;;;;
It takes from unopen dwg a block to add to current drawing. The reverse of what I want, but funny enough I am stumped. [it is probably too obvious] I have not been able to modify the code to make it work my way! Anyone?
-
Shame on me but I haven't gotten around to mess with ObjectDBX yet. I know Peter Jamtsgaard and Robert R. Bell are pretty good with it so .. if you can get them to pop in here I'm sure you'll have some takers.
We do need to get them to come here.
-
I have not been able to modify the code to make it work my way! Anyone?
Hera ya go, Serge.
;;**** MODIFIED to perform reverse of the original
;;**** takes a block def. in current drawing and adds it to the
;;**** block table of a remote drawing, by Jeff Mishler
;;**** all comments below this line are the original comments
;; COPYBLOCK.LSP Copyright ©1999 Tony Tanzillo
;;
;; AutoCAD 2000 Visual LISP / ObjectDBX Example
;;
;; http://www.caddzone.com
;; tony.tanzillo@caddzone.com
;;
;; This example demonstrates how to use ObjectDBX in
;; Visual LISP to directly add blocks defined in any
;; drawing file, to the current drawing.
;;
;; (CopyBlock <FileName> <BlockName>)
;;
;;This function copies the definition of the block whose name is <BlockName> (a string), from the .DWG
;;file whose name is <FileName> (a string), into the current drawing's block table.
;;
;; CopyBlock returns the new copy of the block
;; object in the current drawing's block table.
;;
;; Note that this example performs none of the
;; error checking that is required, and does not
;; attempt to determine what actually happened
;; within the deep clone operation.
(vl-load-com)
(setq *acad* (vlax-get-acad-object))
(defun CopyBlock (DwgName BlkName / blocks dbxDoc)
(setq blocks
(vla-get-blocks
(vla-get-ActiveDocument *acad*)
)
)
(setq dbxDoc
(vla-GetInterfaceObject
*acad*
"ObjectDBX.AxDbDocument"
)
)
(vla-open dbxDoc DwgName)
(vla-CopyObjects
(vla-get-activedocument *acad*)
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbObject
'(0 . 0)
)
(list
(vla-item
blocks
BlkName
)
)
)
(vla-get-blocks dbxDoc)
)
(vlax-invoke dbxDoc 'SaveAs DwgName)
(vlax-release-object dbxDoc)
(princ "\nDone!")
)
(princ "\n(CopyBlock <DrawingFileName> <BlockName>)")
(princ)
;;;;;;;;;;;;;;;;; CopyBlock.lsp ;;;;;;;;;;;;;;;;;;;;
-
Bewuudifuul Jeff, it works wonderfully. As you mentioned, the thumbnail preview disappears! Odd!
Thank you very much.
-
Jeff,
Thinking aloud here! I've no use for thumbnail, but perhaps someone does. Was at first thinking about BLOCKICON when old blocks do not have a preview, but doubt that affects it, on the other hand; is there a way to capture the current thumbnail, run the routine then restore the preview?
Would you know of a way to delete [or should I say purge] a block from an unopen dwg - via dbx? Assuming that the block exist. Thanks
-
Serge,
The thumbnail is just a bad implementation on Adesk's part when the y wrote the ObjectDBX code. I understand that Tony Tanzillo's AcadX has a fix/workaround, but I haven't tried it.
Yes, you can use ObjectDBX to remove a block from a drawing. BUT, you must verify that it is not inserted anywhere in the drawing...including other blocks.
I am in the middle of moving to a new house this week, so I don't have time (or energy....) to give you an example, but it really shouldn't be too difficult for you.
Jeff