Author Topic: In need of a handout. Please.  (Read 11740 times)

0 Members and 2 Guests are viewing this topic.

daron

  • Guest
In need of a handout. Please.
« 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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
In need of a handout. Please.
« Reply #1 on: March 17, 2005, 09:24:11 AM »
Could you wrap it ?

defun new-command
 
trap variables

call old-defunct-crappy0command

restore vars'
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
In need of a handout. Please.
« Reply #2 on: March 17, 2005, 10:12:28 AM »
can you un-encrypt it?, also, what does it do, can we replicate it fairly easily
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

daron

  • Guest
In need of a handout. Please.
« Reply #3 on: March 17, 2005, 10:48:53 AM »
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
In need of a handout. Please.
« Reply #4 on: March 17, 2005, 11:05:56 AM »
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?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

daron

  • Guest
In need of a handout. Please.
« Reply #5 on: March 17, 2005, 11:16:48 AM »
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
In need of a handout. Please.
« Reply #6 on: March 17, 2005, 11:20:04 AM »
Am I oversimplifying it by suggesting (command ".layerp")?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

daron

  • Guest
In need of a handout. Please.
« Reply #7 on: March 17, 2005, 11:21:19 AM »
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?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
In need of a handout. Please.
« Reply #8 on: March 17, 2005, 11:21:46 AM »
After?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

daron

  • Guest
In need of a handout. Please.
« Reply #9 on: March 17, 2005, 11:24:32 AM »
Was in process of editing last post as you posted. See previous post.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
In need of a handout. Please.
« Reply #10 on: March 17, 2005, 11:26:11 AM »
Charging for code does not a professional make?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

daron

  • Guest
In need of a handout. Please.
« Reply #11 on: March 17, 2005, 11:39:25 AM »
Very true. Can a vba wrapper be created for this problem?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
In need of a handout. Please.
« Reply #12 on: March 17, 2005, 11:48:47 AM »
I was under the impression it was a lisp program?

Perhaps something like ...

Code: [Select]
(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)

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
In need of a handout. Please.
« Reply #13 on: March 17, 2005, 12:09:54 PM »
If the code runs on load you could do something like this ...

Code: [Select]
(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)

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

daron

  • Guest
In need of a handout. Please.
« Reply #14 on: March 17, 2005, 12:12:41 PM »
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.

daron

  • Guest
In need of a handout. Please.
« Reply #15 on: March 17, 2005, 12:15:50 PM »
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
In need of a handout. Please.
« Reply #16 on: March 17, 2005, 12:22:00 PM »
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:

Code: [Select]
(defun safecall ( quotedStatement )

    ;; save vars per previous post

    ;; vl-catch-all-apply the quoted statement

    ;; safely restore vars per previous post

    ;; shhhh

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

daron

  • Guest
In need of a handout. Please.
« Reply #17 on: March 17, 2005, 12:35:58 PM »
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.
Code: [Select]
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.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
In need of a handout. Please.
« Reply #18 on: March 17, 2005, 12:39:17 PM »
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.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

daron

  • Guest
In need of a handout. Please.
« Reply #19 on: March 17, 2005, 12:41:15 PM »
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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
In need of a handout. Please.
« Reply #20 on: March 17, 2005, 02:56:00 PM »
Daron, use a "BeginLisp" event to grab the current layer and EndLisp event to reset the current layer.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
In need of a handout. Please.
« Reply #21 on: March 17, 2005, 03:00:23 PM »
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?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
In need of a handout. Please.
« Reply #22 on: March 17, 2005, 03:23:09 PM »
Code: [Select]

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 ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
In need of a handout. Please.
« Reply #23 on: March 17, 2005, 04:21:39 PM »
Thank you Keith. I appreciate it.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
In need of a handout. Please.
« Reply #24 on: March 18, 2005, 04:43:19 AM »
Quote from: Daron
<<< 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.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

daron

  • Guest
In need of a handout. Please.
« Reply #25 on: March 18, 2005, 07:47:38 AM »
Thanks everybody. Keith, the beginlisp etc works beautifully. The help file makes it seem more complicated than that.