Author Topic: Block Adding  (Read 10864 times)

0 Members and 1 Guest are viewing this topic.

Serge J. Gianolla

  • Guest
Block Adding
« 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

Serge J. Gianolla

  • Guest
Block Adding
« Reply #1 on: July 15, 2004, 12:20:58 AM »
So no takers! How about a good soul that can translate the Opening a drawing with ObjectDBX part into VLisp?:

Registering the ObjectDBX environment
Code: [Select]
Sub regObjectDBX()
    Shell "REGSVR32 /s " + Chr$(34) + Tools.findfile("AXDB15.DLL", True) + Chr$(34), 0
End Sub

Opening a drawing with ObjectDBX
Code: [Select]
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

SMadsen

  • Guest
Block Adding
« Reply #2 on: July 15, 2004, 03:50:15 AM »
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.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Block Adding
« Reply #3 on: July 15, 2004, 12:18:11 PM »
Example for using ObjectDBX.
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

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Block Adding
« Reply #4 on: July 15, 2004, 12:57:01 PM »
Interesting... I'll have to check that out in more detail
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Serge J. Gianolla

  • Guest
Block Adding
« Reply #5 on: July 15, 2004, 11:58:28 PM »
Thanks Jeff, but in the meantime I found this short routine from TT.
Code: [Select]
;; 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?

daron

  • Guest
Block Adding
« Reply #6 on: July 16, 2004, 08:59:24 AM »
Quote from: SMadsen
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.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Block Adding
« Reply #7 on: July 16, 2004, 04:44:49 PM »
Quote from: Serge J. Gianolla
I have not been able to modify the code to make it work my way! Anyone?

Hera ya go, Serge.
Code: [Select]

;;**** 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 ;;;;;;;;;;;;;;;;;;;;

Serge J. Gianolla

  • Guest
Block Adding
« Reply #8 on: July 17, 2004, 02:04:13 AM »
Bewuudifuul Jeff, it works wonderfully. As you mentioned, the thumbnail preview disappears! Odd!
Thank you very much.

Serge J. Gianolla

  • Guest
Block Adding
« Reply #9 on: July 20, 2004, 07:27:54 PM »
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

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Block Adding
« Reply #10 on: July 22, 2004, 03:33:52 PM »
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