Consider the following, which is the OnInitialize event - fired when a dialog is opened:
(defun c:jb06_00_OnInitialize ( / path)
(Odcl_Tree_AddParent
jb06_00_TreeControl1
(list (list "3/8\"" "00")
(list "1/2\"" "01")
(list "3/4\"" "02")
(list "1\"" "03")
(list "1 1/2\"" "04")
(list "3\"" "05")))
;load 00 details
(jb:loaddetails "00")
(jb:loaddetails "01")
(jb:loaddetails "02")
(jb:loaddetails "03")
(jb:loaddetails "04")
(jb:loaddetails "05")
)
I'm using the arx function "Odcl_Tree_AddParent" to poulate the tree view im my detail manager form. Here's the lisp jb:loaddetails:
(defun jb:loaddetails(num / file00 path)
(setq path(strcat(vl-filename-directory(findfile "KB.dws"))"\\Details"))
(if (findfile(strcat path "\\" num ".dwg"))
(setq file00(jb:ReturnDBXBlocks(findfile(strcat path "\\" num ".dwg")))))
(if file00
(foreach i file00
(if (=(substr i 1 2)"D_")
(Odcl_Tree_AddChild jb06_00_TreeControl1
num
i)))))
Now the files are loaded in the tree view and sorted by scale - that's it - that's all the code required! Now take a look at what happens when the tree view selection changes:
(defun c:jb06_00_TreeControl1_OnSelChanged (sSelText SelKey / path)
(setq path(strcat(vl-filename-directory(findfile "KB.dws"))"\\Details"))
(Odcl_BlockView_PreLoadDwg jb06_00_BlockView1
(strcat path "\\" SelKey ".dwg"))
(Odcl_Control_SetCaption jb06_00_path (strcat path "\\" SelKey ".dwg"))
)
This pre-load the bitmaps for all the blocks in the selected drawing using the arx defined function: Odcl_BlockView_PreLoadDwg.
Now when a detail is selected this happens:
(defun c:jb06_00_TreeControl1_OnClicked (/ sSelText SelKey file path)
(setq path(strcat(vl-filename-directory(findfile "KB.dws"))"\\Details")
sSelText (Odcl_Tree_GetItemText
jb06_00_TreeControl1
(Odcl_Tree_GetSelectedItem jb06_00_TreeControl1))
SelKey (Odcl_Tree_GetParent
jb06_00_TreeControl1
(Odcl_Tree_GetSelectedItem jb06_00_TreeControl1)))
;if the right drawing isn't pre-loaded, load it
(if SelKey
(if (/= (strcat path "\\" SelKey ".dwg")
(Odcl_Control_GetCaption jb06_00_path))
(progn
(setq file (strcat path "\\" SelKey ".dwg"))
(Odcl_Control_SetCaption jb06_00_path file)
(Odcl_BlockView_PreLoadDwg jb06_00_BlockView1 file))))
;display block
(Odcl_BlockView_DisplayBlock jb06_00_BlockView1 sSelText 1 1.25))
The above bit of code displays the blocks preview where the user can zoom and pan to see the block. No slides required and as has been mentioned if you revise the block the image is automatically updated.
That's it for this project: a few lines of code!!!
To import a block is a bit more complicated - but really not much.