ObjectDBX allows you to create your own 'ObjectDBX Host Application' a standalone application that can load and manipulate drawings. ObjectDBX is a subset of ObjectARX and a C++ object‐oriented API for manipulating AutoCAD and its related objects, collections, properties, methods. This is perfect for batch processing of dwgs, especially for looking up information. Editing drawings is trickier because it's limited, using accoreconsole.exe is complementary.
- No access to System Variables (getvar ...)
- No Selection sets (ssget ...)
- No ent fonctions (entmod ...)
- No Application Methodes (vla-zoomextents ...)
- Argument: String, The complet path of the dwg.
- Return: a VLA object, drawing object
(defun getaxdbdoc (filename / axdbdoc release)
(setq axdbdoc
(vlax-create-object
(if (< (setq release (atoi (getvar "ACADVER"))) 16)
"ObjectDBX.AxDbDocument"
(strcat "ObjectDBX.AxDbDocument." (itoa release))
)
)
)
(if (vl-catch-all-apply 'vla-open (list axdbdoc filename))
(not (vlax-release-object axdbdoc))
axdbdoc
)
)
Need getdir function in odbx_fct.lsp
(defun c:<foo> (/ axdoc lfil dir)
; Choose folder.
(if (and (setq dir (getdir))
(setq lfil (vl-directory-files dir "*.dwg" 1)))
(foreach f lfil
(if (setq axdoc (getaxdbdoc (strcat dir f)))
(progn
; This is where you do what you want.
(<dofoo> axdoc)
; If you modify the document.
(vla-saveas axdoc (strcat dir f))
; Releases a drawing object
(vlax-release-object axdoc)
)
)
)
)
(princ)
)
With (vlax-dump-object axdoc t)
, you know the applicable properties and methods ObjectDBX.
; IAxDbDocument: IAxDbDocument Interface
; Property values:
; Application (RO) = Exception occurred
; Blocks (RO) = #<VLA-OBJECT IAcadBlocks 0000016a1a216918>
; Database (RO) = #<VLA-OBJECT IAcadDatabase 0000016a2b9483d8>
; Dictionaries (RO) = #<VLA-OBJECT IAcadDictionaries 0000016a1a2167f8>
; DimStyles (RO) = #<VLA-OBJECT IAcadDimStyles 0000016a1a215cb8>
; ElevationModelSpace = 0.0
; ElevationPaperSpace = 0.0
; FileDependencies (RO) = #<VLA-OBJECT IAcadFileDependencies 0000016a29b20728>
; Groups (RO) = #<VLA-OBJECT IAcadGroups 0000016a1a2169a8>
; Layers (RO) = #<VLA-OBJECT IAcadLayers 0000016a1a216ac8>
; Layouts (RO) = #<VLA-OBJECT IAcadLayouts 0000016a1a2172a8>
; Limits = (0.0 0.0 420.0 297.0)
; Linetypes (RO) = #<VLA-OBJECT IAcadLineTypes 0000016a1a216d98>
; Materials (RO) = #<VLA-OBJECT IAcadMaterials 0000016a1a2173c8>
; ModelSpace (RO) = #<VLA-OBJECT IAcadModelSpace 0000016a29c2d378>
; Name = "C:\\Data\\TMP\\dwg\\test.dwg"
; PaperSpace (RO) = #<VLA-OBJECT IAcadPaperSpace 0000016a29c2c658>
; PlotConfigurations (RO) = #<VLA-OBJECT IAcadPlotConfigurations 0000016a1a2186e8>
; Preferences (RO) = #<VLA-OBJECT IAcadDatabasePreferences 0000016a29b206a8>
; RegisteredApplications (RO) = #<VLA-OBJECT IAcadRegisteredApplications 0000016a1a217698>
; SectionManager (RO) = Exception occurred
; SummaryInfo (RO) = #<VLA-OBJECT IAcadSummaryInfo 0000016a2b70fe08>
; TextStyles (RO) = #<VLA-OBJECT IAcadTextStyles 0000016a1a2184a8>
; UserCoordinateSystems (RO) = #<VLA-OBJECT IAcadUCSs 0000016a1a218268>
; Viewports (RO) = #<VLA-OBJECT IAcadViewports 0000016a1a217728>
; Views (RO) = #<VLA-OBJECT IAcadViews 0000016a1a217b18>
; Methods supported:
; CopyObjects (3)
; DxfIn (2)
; DxfOut (3)
; HandleToObject (1)
; ObjectIdToObject (1)
; Open (2)
; Save ()
; SaveAs (2)
There are far fewer Methods supported than with an open document.
You can see that an exception has occurred at Application and SectionManager.
I remind you that there is no possible return, and that it is advisable to save your work beforehand.
-
Geters
odbx_getmodel , Copy all objects in Model space, and paste in current dwg.
odbx_getpolinlay, Copy all Polylines in a layer, and paste in current dwg.
odbx_getnbblock, Count the number of blocks.
odbx_getdwgpolxdata, Returns the list of DWGs that contains a polyline with XDATA.
odbx_getlengpolinlay, Get the length of Polylines in a layer.
odbx_getnamelayout, Get the name of layouts.
odbx_getlistlayer, Get the name of layers.
odbx_odbx_getcustominfo, Get custom infos.
-
Senders
odbx_sendlayers, Sends the layers of a current drawing to a drawing folder.
odbx_sendsel, Sends the selection to a drawing folder.
odbx_sendlinetype, Sends the line types to a drawing folder.
odbx_sendTextStyle, Sends the text styles to a drawing folder.
odbx_sendviews, Sends the views to a drawing folder.
odbx_senducs, Sends the UCS to a drawing folder.
odbx_senddimstyles, Sends the dimension styles to a drawing folder.
-
Seters
odbx_setlayerfreeze, Freeze all layer (not the current layer).
odbx_setlayerlock, All layers are locked.
odbx_setlayeroff, All layers off.
odbx_setlayeron, All layers on.
odbx_setlayerthaw, All layers are thawed.
odbx_setlayerunlock, All layers are unlocked.
odbx_setblocbybloclay0, Place all block objects in layer "0" and force color, linetype and thickness to "byblock".
-
Substitutes
odbx_substtext , Replace a text in a TEXT in the model space.
odbx_substmtext , Replace a text in a MTEXT in the model space.
odbx_substmlead , Replace a text in a MLEADER in the model space.
odbx_substatt , Replace a text in a ATTRIBUT in the model space.
odbx_substbloc , Replace a block with another with the same name.
-
Deletes
odbx_delobjinlay , Delete all objects in a layer and purge layers.
odbx_delgroup , Delete all groups (not objects in groups).
odbx_delfilterlayer , Delete filter and state layers.
-
Detachs
odbx_dtcloud , Detach point Clouds in the model space.
odbx_dtdgn , Detach .dgn in the model space.
odbx_dtdwf , Detach .dwf in the model space.
odbx_dtimg , Detach images in the model space.
odbx_dtimgnoref , Detach images not referenced from drawings contained in a folder (in all layouts).
odbx_dtole , Detach OLE object in the model space.
odbx_dtpdf , Detach .pdf in the model space.
To detach xrefs you must use accoreconsole.exe.
-
Purges
odbx_purgebloc , Purge blocks.
odbx_purgeDimStyle , Purge Dimension Styles.
odbx_purgelayer , Purge layers.
odbx_purgelinetype , Purge line types.
odbx_purgeMLeaderStyle , Purge MLeader Styles.
odbx_purgeTableStyle , Purge Table Styles.
odbx_purgeTextStyle , Purge Text Style.
To purge properly you must use accoreconsole.exe.
The Visual LISP Devepors Bible - 2011 Edition Chapter 14 By David M.Stein.
An experience of Michael_Puckett
Special thanks for Patrick_35, Gile and Lee Mac.