Author Topic: wblock out of closed dwg  (Read 11153 times)

0 Members and 1 Guest are viewing this topic.

Amsterdammed

  • Guest
wblock out of closed dwg
« on: September 21, 2005, 04:32:11 AM »
Hello Experts,

What I need to do is to get a wblock into an open drawing; the problem is that the wblock isn’t made yet. So what I wonder is if there is a way to select a dwg with the getfiled function and then get a selection set in that drawing with a  preset filter. But I don’t want to open the dwg visible where the wblock must come from. Is there any activex miracle that t does the trick? Or can I run a hidden 2nd Acad session doing the wblock work there?

Thanks in Advance

Bernd

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: wblock out of closed dwg
« Reply #1 on: September 21, 2005, 05:06:19 AM »
To the best of my knowledge, not as you describe it. Selections <as such> are not possible with DBX. You could however import a block record from the unopened drawing.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #2 on: September 21, 2005, 08:37:00 AM »
Try the design center ... you can open it with ADCENTER and then browse to the DWG you want to grab something from, then select "blocks" then select the block you want .... pretty easy ...
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

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #3 on: September 21, 2005, 09:07:47 AM »
Keith,
It is for you and me. But I need to get this into an application done for my co workers here, so the ss should show up on a certain moment in the lisp.

Bernd
 

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #4 on: September 21, 2005, 01:35:47 PM »
Ok .. this works ... but it does not have alot of error checking.

Code: [Select]
;;;   IFF.LSP
;;;   Copyright ©2005 by K.E. Blackie
;;;
;;;   http://www.resourcecad.com
;;;   kblackie@resourcecad.com
;;;
;;;   AutoCAD 2000+  VisualLISP / ObjectDBX
;;;
;;;   Permission to use, copy, modify, and distribute this software
;;;   for any purpose and without fee is hereby granted, provided
;;;   that the above copyright notice appears in all copies and that
;;;   both that copyright notice and this permission notice appear in
;;;   all supporting documentation.
;;;
;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
;;;
;;;
;;;
;;;
;;;
;;;----------------------------------------------------------------------------
;;;   DESCRIPTION
;;;----------------------------------------------------------------------------
;;;   C:IFF
;;;
;;; This program uses ObjectDBX in VisualLISP to import a block defined in any
;;; closed drawing file.
;;; There is limited error checking. It is presumed the user will modify this
;;; code to some degree to obtain the desired results.
;;;
;;;----------------------------------------------------------------------------
;;;----------------------------------------------------------------------------

;;; main function

(defun C:IFF (/ *acad*   block_list       block
      blocks dbxDwg   dcl_id    done      Dwgfn
      ins_block
     )
  ;; load the com object
  (vl-load-com)
  ;; get the AutoCAD reference
  (setq *acad* (vlax-get-acad-object))
 
  ;; save our dialog file (saves us from having more than one file to deploy)
  (write_dialog)
  ;; get a drawing name
  (setq Dwgfn (getfiled "Open File" "*.DWG" "DWG" 8))
  ;; initialize our insert block to the first element in the list
  ;; just in case the user does not click on the drop down control
  (setq ins_block "0")
  ;; determine what version of AutoCAD we are running then open the appropriate
  ;; ObjectDBX interface version
  ;; We will register the ObjectDBX interface JUST IN CASE it already is not
  ;; Thanks goes to Kerry Brown at www.TheSwamp.org for putting the idea in my head
  (if (= (atoi (getvar "AcadVer")) 16)
    (progn
      (setq DBXserver (findfile "AxDb16.dll"))
      (startapp "regsvr32.exe" (strcat "/s \"" DBXserver "\""))
      (setq dbxDwg
   (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument.16")
      )
    )
    (progn
      (setq DBXserver (findfile "AxDb15.dll"))
      (startapp "regsvr32.exe" (strcat "/s \"" DBXserver "\""))
      (setq dbxDwg
   (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument")
      )
    ) 
  )
  ;; open the drawing
  (vla-open dbxDwg Dwgfn)
  ;; grab the blocks collection
  (setq blocks (vla-get-blocks dbxDwg))
  ;; for each block in the drawing .. grab it's name and make it into a list
  ;; filter for anonymous blocks, modelspace, paperspace and dimensions
  (vlax-for block blocks
    (if (/= "*" (substr (vlax-get-property block 'Name) 1 1))
      (setq block_list
     (append block_list
     (list (vlax-get-property block 'Name))
     )
      )
    )
  )
  ;; load our dialog definition
  (setq dcl_id (load_dialog "iff"))
  ;; our new dialog
  (new_dialog "bl_filter" dcl_id)
  ;; start our list of blocks
  (start_list "bl_names")
  ;; add them to the control
  (mapcar 'add_list block_list)
  ;; end the list
  (end_list)
  ;; define actions for our DCL controls
  (action_tile "bl_names" "(setq ins_block $value)")
  (action_tile "accept" "(done_dialog 1)")
  ;; start our dialog
  (setq done (start_dialog))
  ;; if we closed the dialog with the insert button
  (if (= done 1)
    (progn
      ;; copy the block from the drawing header in the closed drawing
      (vla-CopyObjects
dbxDwg
(vlax-safearray-fill
  (vlax-make-safearray
    vlax-vbObject
    '(0 . 0)
  )
  (list
    (vla-item
      (vla-get-blocks dbxDwg)
      (nth (atoi ins_block) block_list)
    )
  )
)
;; and put it in the current drawing
(vla-get-blocks
  (vla-get-ActiveDocument *acad*)
)
      )
    )
  )
  ;; release our ObjectDBX drawing
  (vlax-release-object dbxDwg)
  ;; if we closed with the Insert button, then insert it
  (if (= done 1)
    (command "insert" (nth (atoi ins_block) block_list))
  )
)

;;; dialog definition
(defun write_dialog (/ fn)
  (if (setq fn (open "iff.dcl" "w"))
    (progn
      (write-line "bl_filter : dialog {" fn)
      (write-line "       aspect_ratio = 0;" fn)
      (write-line "       label        = \"Block Insert Tool\";" fn)
      (write-line "     : popup_list {" fn)
      (write-line "       key               = \"bl_names\";" fn)
      (write-line "     }" fn)
      (write-line "     : row {" fn)
      (write-line "     spacer;" fn)
      (write-line "     : ok_button {" fn)
      (write-line "       label       = \"Insert\";" fn)
      (write-line "       width       = 12;" fn)
      (write-line "       fixed_width = true;" fn)
      (write-line "       alignment   = right;" fn)
      (write-line "     }" fn)
      (write-line "     : cancel_button {" fn)
      (write-line "       width       = 12;" fn)
      (write-line "       fixed_width = true;" fn)
      (write-line "       alignment   = left;" fn)
      (write-line "     }" fn)
      (write-line "     spacer;" fn)
      (write-line "     }" fn)
      (write-line " }" fn)
    )
  )
  (close fn)
)

Forgot to mention, this uses a technique employed by Tony Tanzilla to copy the block from one drawing to another.
« Last Edit: September 22, 2005, 09:15:20 AM by Keith »
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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: wblock out of closed dwg
« Reply #5 on: September 21, 2005, 05:22:43 PM »
As I posted, blocks are simple ..

Didn't Amsterdammed's original post and his reply #3 ask for a selection set .. which can't be done with DBX.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Chuck Gabriel

  • Guest
Re: wblock out of closed dwg
« Reply #6 on: September 21, 2005, 05:38:06 PM »
He couldn't do a selection set, but he could iterate over the database applying his filter criteria and use CopyObjects to get the accumulated objects into his active drawing.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: wblock out of closed dwg
« Reply #7 on: September 21, 2005, 05:38:59 PM »
Sure could.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: wblock out of closed dwg
« Reply #8 on: September 21, 2005, 05:47:14 PM »
Yep, certainly .. 

:whistle:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Chuck Gabriel

  • Guest
Re: wblock out of closed dwg
« Reply #9 on: September 21, 2005, 06:35:04 PM »
Hmm.  I'm much more proficient in VB(A) then visual lisp so I'll post this VBA example and leave up to others to translate it into vlisp.  It is a little oversimplified, but it should get you going in the right direction.

Code: [Select]
Option Explicit

Const ERR_SUBSCRIPT_OUT_OF_RANGE = 9

Sub test()
  On Error GoTo ERROR_HANDLER
  ' Uses CommonDialog.cls from www.acadx.com
  Dim fileDialog As CommonDialog
  Dim fileName As String
  Set fileDialog = New CommonDialog
  With fileDialog
    .DialogTitle = "Select files:"
    .Filter = "Drawing files (*.dwg)|*.dwg"
    .DefaultExt = "dwg"
    .Flags = OFN_EXPLORER Or OFN_HIDEREADONLY
    .InitDir = ThisDrawing.Path
    If .ShowOpen Then
      fileName = .fileName
    Else
      Exit Sub
    End If
  End With
  Set fileDialog = Nothing
 
  Dim doc As AxDbDocument
  Dim ent As AcadEntity
  Dim index As Long
  Dim entities() As AcadEntity
  Set doc = New AxDbDocument
  doc.Open fileName
  index = 0
  For Each ent In doc.ModelSpace
    If TypeOf ent Is AcadText Then
      ReDim Preserve entities(0 To index) As AcadEntity
      Set entities(index) = ent
      index = index + 1
    End If
  Next ent
  Set ent = Nothing
 
  ' We will get a runtime error here if the array has not been redimmed
  ' That should be our cue to exit if it occurs
  Dim upper As Long
  upper = UBound(entities)
 
  Dim pairs As Variant
  doc.CopyObjects entities, ThisDrawing.ModelSpace, pairs

  Exit Sub

ERROR_HANDLER:

  Select Case Err
    Case ERR_SUBSCRIPT_OUT_OF_RANGE
      ' The entity array is empty
      Exit Sub
    Case Else
      Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
  End Select
End Sub

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #10 on: September 22, 2005, 04:57:37 AM »
Keith,
if i run the IFF function i get tHis error msg
Quote
Automation Error. Problem in loading application



on this line of code
Code: [Select]
(setq dbxDwg
   (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument")
    )

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: wblock out of closed dwg
« Reply #11 on: September 22, 2005, 05:40:23 AM »
Which Version Of AutoCAD ?

What does This return ?
(substr (getvar "ACADVER") 1 5)

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #12 on: September 22, 2005, 07:32:03 AM »
Sorry Kerry,

I bit stupid from me not to post earlier:  "15.06"

Bernd

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: wblock out of closed dwg
« Reply #13 on: September 22, 2005, 07:41:38 AM »
Try this then :
Code: [Select]
         (cond
           ((vl-registry-read "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID"
            )
           )
           ((not (setq DBXserver (findfile "AxDb15.dll")))
            (alert "Error: Can't locate ObjectDBX Library (AxDb15.dll)")
           )
           (t
            (startapp "regsvr32.exe" (strcat "/s \"" DBXserver "\""))
            (or
              (vl-registry-read
                "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID"
              )
              (alert
                "Error: Failed to register ObjectDBX ActiveX services for AutoCAD2002."
              )
            )
           )
         )         
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #14 on: September 22, 2005, 08:00:27 AM »
Code: [Select]
"Error: Failed to register ObjectDBX ActiveX services for AutoCAD2002."

Chuck Gabriel

  • Guest
Re: wblock out of closed dwg
« Reply #15 on: September 22, 2005, 08:06:25 AM »
Doh!  Now I see.  Sorry Keith.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: wblock out of closed dwg
« Reply #16 on: September 22, 2005, 08:11:30 AM »
What is returned from :-
This ;
(setq DBXserver (findfile "AxDb15.dll"))


Then this ;

(startapp "regsvr32.exe" (strcat "/s \"" DBXserver "\""))
         
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #17 on: September 22, 2005, 08:23:59 AM »
Try this:

Browsing to your AutoCAD directory
Find AxDb15.dll
Right click on AxDb15.dll
OpenWith -> Browse to regsvr32.exe

If the result is successful, then the proggie will work
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

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #18 on: September 22, 2005, 09:01:47 AM »
Kerry,

33

"C:\\Program Files\\AutoCAD 2002\\AxDb15.dll"

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: wblock out of closed dwg
« Reply #19 on: September 22, 2005, 09:05:55 AM »
Should work now, did you try?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #20 on: September 22, 2005, 09:06:25 AM »
Well you should work then ...
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

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #21 on: September 22, 2005, 09:14:57 AM »
Same error

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #22 on: September 22, 2005, 09:16:53 AM »
This error?
Quote
Automation Error. Problem in loading application
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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: wblock out of closed dwg
« Reply #23 on: September 22, 2005, 09:18:31 AM »
Hmmm ... Replace --

ObjectDBX.AxDbDocument

with

ObjectDBX.AxDbDocument.15

/guess
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #24 on: September 22, 2005, 09:24:38 AM »
Hmmm ... Replace --

ObjectDBX.AxDbDocument

with

ObjectDBX.AxDbDocument.15

/guess

Nope .. the ObjectDBX application class name is either:
ObjectDBX.AxDbDocument (versionless)
ObjectDBX.AxDbDocument.1 (R15 2000-2002)
ObjectDBX.AxDbDocument.16 (R16 2004-2006)

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

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #25 on: September 22, 2005, 09:25:05 AM »
No Michael

same error,
Quote
error: Automation Error. Problem in loading application

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #26 on: September 22, 2005, 09:33:16 AM »
Ok .. what does this return?

Code: [Select]
(vl-registry-read "HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID" )
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

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #27 on: September 22, 2005, 09:36:15 AM »
Quote
nil

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #28 on: September 22, 2005, 09:52:01 AM »
That means that for some reason ObjectDBX is not registered ...

Try browsing to the file like I said in this post
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

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #29 on: September 22, 2005, 10:47:48 AM »
Keith,

It fails.
It gives a code 0x800200009

I’m afraid it won’t work here in this environment.

The reason might be in the system here, we are locked on to a remote server, have no writing rights on c. The reason is that we van get to every PC in every office and will log on to our stuff.

Sorry for wasting you time

Bernd

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #30 on: September 22, 2005, 10:59:49 AM »
Indeed .. that is why ... you should request your IT staff enable this ..
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

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #31 on: September 23, 2005, 02:48:06 AM »
Keith,

I wish that was that easy. The are as flexible as concrete. Is there a way that i can open a 2nd acad session with visible = false and do simply with lisp the wblock work?

Bernd

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: wblock out of closed dwg
« Reply #32 on: September 23, 2005, 02:50:49 AM »
I am speechless.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #33 on: September 23, 2005, 03:04:56 AM »
What do you mean Kerry?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: wblock out of closed dwg
« Reply #34 on: September 23, 2005, 03:13:42 AM »
... if I understand you correctly ..

I find it incomprehensible that your IT people would not assist. DBX used properly is significantly productive.
 ..essentially, they are stopping you from doing your job.


added. : Can you talk to your Manager about this ? .. 'cause it's too important to ignore.
« Last Edit: September 23, 2005, 03:16:54 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #35 on: September 23, 2005, 03:51:05 AM »
Kerry,
You have no Idea how right you are. But although I’m working for a Dutch Company (thank God that I’m not Dutch), I’m tired of fighting Wind mills.

The good thing is that they reorganise the whole circus here and fire 800 of the 9000 people, and I pray that there will be my IT enemies among them.

And than I will give it a new try.

Bernd
 :evil:

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: wblock out of closed dwg
« Reply #36 on: September 23, 2005, 08:44:37 AM »
It might be able to be done by opening another AutoCAD session that is hidden ... only sometimes AutoCAD willl recognize that another session is running and then terminate the new application and open the drawing in the current session. The only way I would be able to tell you to verify this would be to actually try it.

Can you open AutoCAD 2 times on your computer? If so, then you should be able to do it, but the solution would be in VBA unless you could import the various type libraries into VLisp.
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

Amsterdammed

  • Guest
Re: wblock out of closed dwg
« Reply #37 on: September 23, 2005, 09:54:16 AM »
Keith,

yes, i can open Acad more than one toime on my PC. VBA should be ok, too.

Thanks,

Bernd