Call Lisp from Modeless Dialog or Help Converting LiSP Functions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
OK, So I have routine that runs a bunch of stuff on a drawing file. I am doing 95% of the work via the API. Due to the restrictions of the Burst command I am forced to do 5% via lisp. The problem I have is the Lisp does not fire until after the dialog is closed. But it needs to run in the middle of other things. Meaning I need this part (the Lisp) to run before the rest of the routine or I do not get the desired results.
The Lisp is Here:
(defun C:LSPMCTELTRANS()
(vl-load-com)
;;; This section will make all blocks explode-able!
(vlax-for b (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
(or
(wcmatch (vla-get-Name b) "`**_Space*")
(vla-put-explodable b :vlax-true)
)
) ;end vlax-for
;;; This section will switch to each layout and burst all blocks
(foreach layout (layoutlist)
(setvar "ctab" layout)
(setq burstrc 0)
(while
(and
(setq compare1 (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'ctab)))))
(<= burstrc 5)
)
(sssetfirst nil compare1)
(c:burst)
(if
(setq compare2 (ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar 'ctab)))))
(if (= (sslength compare1) (sslength compare2))
(setq burstrc (+ burstrc 1))
(setq burstrc 0)
)
)
) ;end while
(princ)
(command "zoom" "e")
(command "regenall")
) ; end for each
(princ)
;;; This section will set the first layout tab active!
(vlax-for layt
(vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (= (vla-get-TabOrder layt) 1)
(setvar 'CTAB (vla-get-Name layt))
)
) ;end vlax-for
) ;end defun LSPMCTELTRANS
It basically goes to each tab and bursts all blocks. Because it literally switches tabs the form must be modeless. I tried as Modal with no luck.
I have tried calling it many different ways as shown on the forums. From Send string to execute to loading it first then calling the command but I just cant get it to work.
curDoc.SendStringToExecute("(load ""M:\\Utilities\\LISP Routines\\Modify Routines\\Drawing Prep\\MCTELTRANSLSP.lsp"") ", False, False, False)
'I have tried loading that on form load. then calling this when needed but with no luck. Neither worked.
curDoc.SendStringToExecute("LSPMCTELTRANS" + " ", True, False, False)
docEd.Command("LSPMCTELTRANS ")
I have used a different way in the past. With some help from @_gile but the problem with the below code is it is recursive and the drawing size increases from 9MG to 44MG. (There are other functions and subs that go with this)
And the other thing with the below code is that in VS2019 ent.OpenAs throws an error. Not a member of ObjectId
Public Sub BurstAllBlocks() Implements IExplodeServices.BurstAllBlocks
Dim curDb As Database = Active.Database
Try
Using tr As Transaction = curDb.TransactionManager.StartTransaction()
Dim layoutDbDictionary As DBDictionary = tr.GetObject(curDb.LayoutDictionaryId, OpenMode.ForRead)
For Each layoutDbDictionaryEntry As DBDictionaryEntry In layoutDbDictionary
Dim layout As Layout = CType(layoutDbDictionaryEntry.Value.GetObject(OpenMode.ForRead), Layout)
Dim blkTblRec As BlockTableRecord = tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite)
Dim rxClass = RXObject.GetClass(GetType(BlockReference))
Dim blocks = blkTblRec.Cast(Of ObjectId).Where(Function(ent) ent.ObjectClass.IsDerivedFrom(rxClass)) _
.Select(Function(ent) ent.OpenAs(Of BlockReference)(tr, OpenMode.ForRead))
For Each block As BlockReference In blocks
BurstBlocks(tr, block, blkTblRec)
Next
Next
tr.Commit()
End Using
Catch ex As Exception
End Try
I am not particular in the answer what ever will work I am fine with. Any help would be greatly appreciated.