ObjectDBX Wrapper

Function Syntax (LM:ODBX <fun> [lst] [sav])
Current Version 1.2
Download ObjectDBXWrapperV1-2.lsp
View HTML Version ObjectDBXWrapperV1-2.html
Arguments
Symbol Type Description
fun Symbol A function requiring a single argument (the VLA Document Object)
lst List [Optional] A list of DWG filenames to process, if nil, BrowseForFolder dialog is displayed.
sav Boolean [Optional] Boolean flag controlling whether drawings are saved following function evaluation.
Returns
Type Description
List List of: ((<Drawing Filename> . <Result>) ... )

Program Description

Provides a shell through which a user may evaluate a supplied function on every drawing in a given list of drawing filenames or on all drawings residing within a selected directory.

Notes on Function Parameters

fun

A function requiring a single argument (the VLA Document Object)

The supplied function should take a single argument (the VLA Document Object for each drawing processed), and follow the 'rules' of ObjectDBX, that is:

  • No Selection Sets (use of ssget, ssname, ssdel etc)
  • No Command calls (command "_.line" ... etc)
  • No ent* methods (entmod, entupd etc)
  • No access to System Variables (getvar, setvar, vla-getvariable, vla-setvariable etc)

lst [Optional]

A list of drawing filenames to process, if nil, BrowseForFolder dialog is displayed

This optional parameter is a list of drawing filenames to be processed by the program. If this parameter is nil the user is presented with a dialog interface through which a folder of drawings may be selected to be processed.

sav [Optional]

Boolean flag controlling whether drawings are saved following function evaluation

This optional parameter determines whether drawings are saved after the supplied function is evaluated. If this parameter is t the drawing will be saved.

Note 1: this parameter must be t if the supplied function is modifying the drawing and such changes are to be saved.

Note 2: When saving drawings using ObjectDBX, drawing thumbnails will be lost until the next manual save.

Example Functions

The following examples demonstrate various ways to utilise the above ObjectDBX Wrapper function. When testing the examples below, the ObjectDBX Wrapper must be loaded.

Example 1

This example will construct a line from (0,0) to (3,5) in every drawing in a selected directory.

Select all
(defun c:test1 ( / )
    (LM:ODBX
        (function
            (lambda ( doc )
                (vla-addline (vla-get-modelspace doc)
                    (vlax-3D-point '(0.0 0.0))
                    (vlax-3D-point '(3.0 5.0))
                )
            )
        )
        nil t
    )
    (princ)
)

Example 2

This example will lock all layers in every drawing in a directory.

Select all
(defun c:test2 ( / _lockalllayers )

    (defun _lockalllayers ( doc )
        (vlax-for layer (vla-get-layers doc)
            (vla-put-lock layer :vlax-true)
        )
    )

    (LM:ODBX '_lockalllayers nil t)
    (princ)
)

Example 3

This example will return the number of Layout Tabs (including the Model Tab) in each drawing in a directory. Note that the _save parameter is nil since no changes are being made to the drawings.

Select all
(defun c:test3 ( / )
    (LM:ODBX
      '(lambda ( doc ) (vla-get-count (vla-get-layouts doc)))
       nil
       nil
    )
)

Example 4

This rather more complex example will extract the attribute values for every attributed block in every drawing in a directory and write these values to a Text File.

Select all
(defun c:test4 ( / _getattributes data file name )

    (defun _getattributes ( doc / data item name values )
        (vlax-for layout (vla-get-layouts doc)
            (vlax-for object (vla-get-block layout)
                (if
                    (and
                        (eq "AcDbBlockReference" (vla-get-objectname object))
                        (eq :vlax-true (vla-get-hasattributes object))
                        (setq values
                            (mapcar
                                (function
                                    (lambda ( att )
                                        (cons
                                            (vla-get-tagstring att)
                                            (vla-get-textstring att)
                                        )
                                    )
                                )
                                (vlax-invoke object 'getattributes)
                            )
                        )
                    )
                    (if (setq item (assoc (setq name (vla-get-effectivename object)) data))
                        (setq data
                            (subst
                                (append item (list values))
                                item
                                data
                            )
                        )
                        (setq data (cons (list name values) data))
                    )
                )
            )
        )
        data
    )

    (if
        (and
            (setq data (LM:ODBX '_getattributes nil nil))
            (setq name (vl-filename-mktemp nil (getvar 'dwgprefix) ".txt"))
            (setq file (open name "w"))
        )
        (progn
            (foreach dwgitem data
                (write-line (car dwgitem) file)
                (princ "\n" file)
                (foreach item (cdr dwgitem)
                    (write-line (car item) file)
                    (foreach subitem (cdr item)
                        (princ subitem file)
                        (princ "\n" file)
                    )
                    (princ "\n" file)
                )
            )
            (close file)
            (startapp "notepad" name)
        )
    )
    (princ)
)

textsize

increase · reset · decrease

Designed & Created by Lee Mac © 2010