Author Topic: Startup Priority  (Read 11590 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Startup Priority
« Reply #15 on: August 01, 2006, 01:45:36 PM »
T Willey,

You lost me :-o.

What steps do you take to ensure that the PGP file takes priority over externally defined commands?

I feel like this should be alot easier than I'm making it out to be.

Thanks for all the input,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Startup Priority
« Reply #16 on: August 01, 2006, 01:50:00 PM »
I didn't.  I opened the pgp file, made a list of all the command alias's and the commands.  Then I read all the lisp files that are loaded, and compaired them.  Now I'm trying to convert the ones that overlap, to the commands that are defined in the pgp file.

So I have a list of lists, that I need to make defuns out of.  One example (on my computer) would be
("ATE" . "DDATTE")
Trying to do something like
(defun c:ate () (command ".ddatte"))
But can't get it to work right yet.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Startup Priority
« Reply #17 on: August 01, 2006, 02:00:33 PM »
Ron, as I see it Tim may be on to the only way around this situation, without telling your users to use alias's that don't conflict with your lisp functions.

Tim, here's a quick example to write/load/run/remove a lisp from a lisp:
Code: [Select]
(defun c:comments (/ file1 file2 t1 t2 timer1-end
   timer1-start timer2-end timer2-start)
  (setq file1 (open "c:\\testlisp1.lsp" "w")
file2 (open "c:\\testlisp2.lsp" "w"))
  (write-line "(defun c:test2 (/ mytest2)" file2)
  (write-line "  (setq mytest2 \"mytest2\")" file2)
  (write-line "  (princ)" file2)
  (write-line ")" file2)
  (close file2)
  ;;
  (write-line "(defun c:test1 (/ mytest1)" file1)
  (write-line "  (setq mytest1 \"mytest1\")" file1)
  (repeat 100000
    (write-line ";;;;this is a standard comment" file1)
    )
  (write-line "  (princ)" file1)
  (write-line ")" file1)
  (close file1)
  (setq timer1-start (getvar "millisecs"))
  (load "c:\\testlisp1.lsp")
  (setq timer1-end (getvar "millisecs"))
  (setq timer2-start (getvar "millisecs"))
  (load "c:\\testlisp2.lsp")
  (setq timer2-end (getvar "millisecs"))
  (setq t1 (strcat (rtos (/ (- timer1-end timer1-start) 1000.0) 2 5) " seconds."))
  (setq t2 (strcat (rtos (/ (- timer2-end timer2-start) 1000.0) 2 5) " seconds."))
  (princ (strcat "\nTime to load Testlisp1: " t1))
  (princ (strcat "\nTime to load Testlisp2: " t2))
  (princ (strcat "\nTestlisp1 file size = "
(rtos (vl-file-size "c:\\testlisp1.lsp") 2 0) " bytes."))
  (princ (strcat "\nTestlisp2 file size = "
(rtos (vl-file-size "c:\\testlisp2.lsp") 2 0) " bytes."))
  (vl-file-delete "c:\\testlisp1.lsp")
  (vl-file-delete "c:\\testlisp2.lsp")
  (princ)
  )

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Startup Priority
« Reply #18 on: August 01, 2006, 02:07:12 PM »
Is there no other way, than to write it to a lisp file, then load it, then delete the file?  I was hoping to do it from the command line, kind of behind the scenes.

Thanks Jeff.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Startup Priority
« Reply #19 on: August 01, 2006, 02:09:57 PM »
Yeah......this will load it:
Code: [Select]
(eval (read "(defun c:test () (alert \"TEST\"))"))

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Startup Priority
« Reply #20 on: August 01, 2006, 02:17:14 PM »
Yeah......this will load it:
Code: [Select]
(eval (read "(defun c:test () (alert \"TEST\"))"))
I tried that, and it didn't work, now I try it, and it does.  I must have typed something wrong.  Thanks Jeff.

Ron,
Here is the code I did, let me know if it works for you.  Right now it prompts you with how to call the lisp funtion that won't work anymore.
Code: [Select]
(defun c:ResetPgp (/ pgpFile Opened TextLine ComamndList LispRoutine)

(if (setq pgpFile (findfile "acad.pgp"))
 (progn
  (setq Opened (open pgpFile "r"))
  (while (setq TextLine (read-line Opened))
   (if
    (and
     (/= (substr TextLine 1 1) ";")
     (vl-string-search "," TextLine)
     (vl-string-search "*" TextLine)
    )
    (setq CommandList
     (cons
      (cons
       (strcase (substr TextLine 1 (vl-string-search "," TextLine)))
       (strcat "." (substr TextLine (+ 2 (vl-string-search "*" TextLine))))
      )
      CommandList
     )
    )
   )
  )
  (close Opened)
  (foreach LispRoutine (vl-remove-if-not '(lambda (x) (= (strcase (substr x 1 2)) "C:")) (atoms-family 1))
   (if (setq tmpList (assoc (strcase (substr LispRoutine 3)) CommandList))
    (progn
     (eval (read (strcat "(defun c:" (car tmpList) " () (command \"." (cdr tmpList) "\") (princ) )")))
     (prompt (strcat "\n Lisp routine \"" (substr LispRoutine 3) "\" is repalced with acad.pgp command alias."))
    )
   )
  )
 )
)
(princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Startup Priority
« Reply #21 on: August 01, 2006, 02:25:19 PM »
I'm with Bob on this one.

But is this what you wanted Tim?
Code: [Select]
(defun test (key)
  (cond
    ((= key "prg1")
     (defun c:newprg ()
       (c:prg1) ; call the routine
     )
    )
    ((= key "prg2")
     (defun c:newprg ()
       (c:prg2) ; call the routine
     )
    )
    ((= key "prg3")
     (defun c:newprg ()
       (c:prg3) ; call the routine
     )
    )
  )
  (c:newprg)
)


(defun c:prg1()
  (print "You are here, prg1")
  (princ)
  )
(defun c:prg2()
  (print "You are here, prg2")
  (princ)
  )
(defun c:prg3()
  (print "You are here, prg3")
  (princ)
  )

(test "prg3")
(test "prg2")
(test "prg1")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Startup Priority
« Reply #22 on: August 01, 2006, 02:35:07 PM »
Not really Alan, Jeff showed me the right way.  Thanks though.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Startup Priority
« Reply #23 on: August 01, 2006, 02:41:36 PM »
What do they say? "Don't dive in if you cant see the bottom."  :oops:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Startup Priority
« Reply #24 on: August 01, 2006, 02:44:06 PM »
What do they say? "Don't dive in if you cant see the bottom."  :oops:
You have helped me before, so no big deal.  :-)  You can post to help me out anytime.  :wink:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CADaver

  • Guest
Re: Startup Priority
« Reply #25 on: August 01, 2006, 02:50:28 PM »
I don't have all the autoload lines in the mnl...I have a line that looks for an external file with all the lisp definitions in it and loads it if found. I know I need to do some cleanup but what i don't understand here is why reinit doesn't recognize my command aliases when manually initialized after startup.

If you have code to this affect:
Code: [Select]
(AUTOLOAD "bb" '("bb"))
when you enter bb it will autoload the function regardless of the pgp setting, won't it?.

CADaver

  • Guest
Re: Startup Priority
« Reply #26 on: August 01, 2006, 02:55:51 PM »
Gotta go with Bob on this one.  It's a lot easier to avoid the conflicts outright than to program around them.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Startup Priority
« Reply #27 on: August 01, 2006, 02:56:58 PM »
One thing we do here when creatin new functions is to give them 3 letter call instead of 2 so they do not conflict with acad and if you are a keyboard junkie you know what your lisps are.

ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

GDF

  • Water Moccasin
  • Posts: 2081
Re: Startup Priority
« Reply #28 on: August 01, 2006, 02:58:06 PM »

Ron,
Here is the code I did, let me know if it works for you.  Right now it prompts you with how to call the lisp funtion that won't work anymore.
Code: [Select]

(defun c:ResetPgp (/ pgpFile Opened TextLine ComamndList LispRoutine)

(if (setq pgpFile (findfile "acad.pgp"))
 (progn
  (setq Opened (open pgpFile "r"))
  (while (setq TextLine (read-line Opened))
   (if
    (and
     (/= (substr TextLine 1 1) ";")
     (vl-string-search "," TextLine)
     (vl-string-search "*" TextLine)
    )
    (setq CommandList
     (cons
      (cons
       (strcase (substr TextLine 1 (vl-string-search "," TextLine)))
       (strcat "." (substr TextLine (+ 2 (vl-string-search "*" TextLine))))
      )
      CommandList
     )
    )
   )
  )
  (close Opened)
  (foreach LispRoutine (vl-remove-if-not '(lambda (x) (= (strcase (substr x 1 2)) "C:")) (atoms-family 1))
   (if (setq tmpList (assoc (strcase (substr LispRoutine 3)) CommandList))
    (progn
     (eval (read (strcat "(defun c:" (car tmpList) " () (command \"." (cdr tmpList) "\") (princ) )")))
     (prompt (strcat "\n Lisp routine \"" (substr LispRoutine 3) "\" is repalced with acad.pgp command alias."))
    )
   )
  )
 )
)
(princ)
)
[/quote]


Tim

Thanks for sharing this one, I see now that I have some cleanup to do.

Gary
« Last Edit: August 01, 2006, 02:59:14 PM by Gary Fowler »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Startup Priority
« Reply #29 on: August 01, 2006, 02:59:41 PM »
forgot to add that we usually use double first letter i.e. la for the Layer command lla for the label command

Clear as mud?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016