TheSwamp
Code Red => VB(A) => Topic started by: daron on March 17, 2005, 09:18:51 AM
-
I am using a program in autocad that the original creator not only ecrypted the file but didn't collect any variables to return to their original state. What I'm in need of is an event module that collects the current layer when a lisp is called and restores that layer when the lisp is ended or cancelled. Will someone please throw out a bone with some meat on it. Thanks.
-
Could you wrap it ?
defun new-command
trap variables
call old-defunct-crappy0command
restore vars'
-
can you un-encrypt it?, also, what does it do, can we replicate it fairly easily
-
I have gotten it unencrypted. There are a bunch of functions without a c: prompt and a bunch of code without a defun. It's a HUGE file. My problem is I'm not sure about encryption. How does autocad differentiate between an encrypted file and an unencrypted file or does that matter? I'm in process of creating a whole new program for this job, but it's a slow process. I just was hoping for a bandage for what I'm currently using.
Kerry, what you mention about the wrapping it? Isn't that what beginlisp and endlisp / cancellisp do? It's the beginLisp event that I'm not sure how to write. It'd be nice if the event could be fired anytime any lisp is called.
-
I don't mean to be a snot, but decrypting a program? Generally speaking this is a no no even though it's easy to do. Can you get the original source code from the author?
-
I don't plan to update or even take from the original code. I just want something to keep it from setting me to layer 0 when I think I'm on a different layer.
-
Am I oversimplifying it by suggesting (command ".layerp")?
-
Where? Yes. I don't care what the previous layer was, I just want to not be left on a layer I wasn't on. Why can't people who charge for code write code that plays nice?
-
After?
-
Was in process of editing last post as you posted. See previous post.
-
Charging for code does not a professional make?
-
Very true. Can a vba wrapper be created for this problem?
-
I was under the impression it was a lisp program?
Perhaps something like ...
(defun c:Wrap ( / vars )
(setq vars
(mapcar
'(lambda (varname) (cons varname (getvar varname)))
'("cmdecho" "clayer" "cecolor" "celtype")
)
)
(c:CallTheOffendingProgram)
(foreach pair vars
(vl-catch-all-apply
'(lambda ()
(setvar (car pair) (cdr pair))
)
)
)
(princ)
)
-
If the code runs on load you could do something like this ...
(defun c:Wrap ( / vars )
(setq vars
(mapcar
'(lambda (varname) (cons varname (getvar varname)))
'("cmdecho" "clayer" "cecolor" "celtype")
)
)
(load "TheOffendingProgram" (princ "The load failed."))
(foreach pair vars
(vl-catch-all-apply
'(lambda ()
(setvar (car pair) (cdr pair))
)
)
)
(princ)
)
-
It is a lisp program that is the offender, but I was under the impression that vba could handle events better than lisp. Would I have to know each lisp name to watch for? Nice code by the way.
-
Didn't see that second one. I'll give that a try, because you are partly correct. To get the lisp loaded, they gave a toolbar that has to be pressed each time you intend to work with this program. Typing wrap, might work.
-
You could do it via event code but I generally avoid event based code unless it's absolutely essential. I don't see this as sporting such necessity.
But I don't pretend to fully appreciate your situation, I'm reading / posting rather quickly here (juggling writing two programs as we speak).
Thanks for your compliment. If I had more time I'd wrapper the wrapper as a generic function you merely pass an argument, like:
(defun safecall ( quotedStatement )
;; save vars per previous post
;; vl-catch-all-apply the quoted statement
;; safely restore vars per previous post
;; shhhh
)
-
The code is nice, but the lisp problem remains, because each successive button I have to use ruins my settings the same way. There are a lot of buttons. I do feel a neccesity for event handling. I am aware of the adverse effects.
Here's one I put together for an osmode problem, but the clayer problem needs to know what to set it to, previous to the event.
Private Sub AcadDocument_EndLisp()
Dim sysVarName As String
Dim sysVarData As Variant
Dim DataType As Integer
Dim intData As Integer
sysVarName = "osmode"
intData = 6175
sysVarData = intData
ThisDrawing.SetVariable sysVarName, sysVarData
End Sub
Private Sub AcadDocument_LispCancelled()
Dim sysVarName As String
Dim sysVarData As Variant
Dim DataType As Integer
Dim intData As Integer
sysVarName = "osmode"
intData = 6175
sysVarData = intData
ThisDrawing.SetVariable sysVarName, sysVarData
End Sub
It's the BeginLisp that I don't quite have a handle on.
-
Let me apoligize in advance - no time to post / write more code - but let me say be very careful how you implement this, lest it affect every lisp program.
-
Of course. This work isn't for anybody but myself to cure a headache until I can develop a better solution to do my job.
-
Daron, use a "BeginLisp" event to grab the current layer and EndLisp event to reset the current layer.
-
I got the EndLisp part. It's the BeginLisp that I can't seem to wade through. Will you show me how to get through that puddle?
-
Option Explicit
Dim CurrLayer As AcadLayer 'global layer variable
Private Sub AcadDocument_BeginLisp(ByVal FirstLine As String)
If CurrLayer Is Nothing Then 'if there is nothing in the variable now
'this solves the issue of nested lisp functions (not sure if they fire an event)
' but better safe than sorry
Set CurrLayer = ThisDrawing.ActiveLayer 'save something there
End If
End Sub
Private Sub AcadDocument_EndLisp()
If CurrLayer Is Nothing Then ' if there is nothing in the variable
' we do nothing (unusual caveat).... it is not easy to test if a value is
' FALSE when comparing to NOTHING .. VBA generates an error ..
Else
ThisDrawing.ActiveLayer = CurrLayer 'Set the layer current
Set CurrLayer = Nothing 'clear the variable
End If
End Sub
Private Sub AcadDocument_LispCancelled()
If CurrLayer Is Nothing Then' if there is nothing in the variable
' we do nothing (unusual caveat).... it is not easy to test if a value is
' FALSE when comparing to NOTHING .. VBA generates an error ..
Else
ThisDrawing.ActiveLayer = CurrLayer 'Set the layer current
Set CurrLayer = Nothing 'clear the variable
End If
End Sub
Ok, note that I used a global variable that I can set that will be active across several events. Now, please note that this WILL cause an error if you change the current drawing while in the middle of a lisp program. You could change the global variable to hold the drawing name and layer, then check for the drawing name and layer of the "current" drawing... but that was just a little more coding than I have time for tright now ...
-
Thank you Keith. I appreciate it.
-
<<< Kerry, what you mention about the wrapping it? Isn't that what beginlisp and endlisp / <<<<.
Sorry, I've been away most of the day .. I meant wrapped like Michaels post 13 an 14 show.
-
Thanks everybody. Keith, the beginlisp etc works beautifully. The help file makes it seem more complicated than that.