Author Topic: aliases loaded from LISP - problem  (Read 5486 times)

0 Members and 1 Guest are viewing this topic.

jackson5

  • Guest
aliases loaded from LISP - problem
« on: August 05, 2013, 04:59:53 PM »
Hi, I want to load all my aliases from a simple LISP file -
instead of typing it into PGP file. It's more convenient for me
(I often migrate to different machines).

My LISP file looks like

(defun c:u () (command "_ucs"))
(defun c:v () (command "_view"))
(defun c:r () (command "_extend"))
(defun c:w () (command "_matchprop"))

the problem is, when I load my lisp and type the shortcut for my
commands what I get is "nil" - and nothing happens,

OR

my command is recognized properly, but I don't get "the windows mode"
- for example for "_bhatch" command there supposed to be a window, and
what I get is a text line in my history window with the options for this
command for typing manually... why is that?

ribarm

  • Gator
  • Posts: 3293
  • Marko Ribar, architect
Re: aliases loaded from LISP - problem
« Reply #1 on: August 05, 2013, 06:03:25 PM »
All I can say is that you are messing with already defined aliases by default installation of ACAD... My opinion ab this is that you should better get used to CAD standards rather then redefine already working things so that when new release comes you quickly adapt to new features... "U" alias is defined as standard command - UNDO and not UCS, and if you really want to set alias for UCS why not use icon - for me extra letters U+C+S doesn't slow my working too much... As for _bhatch, you should consider putting line (initdia) before (command "_bhatch"), but I am not sure weather it will help you as when (command) function is called from within lisp or script CAD assumes that command should be provided with extra parameters like you called "-bhatch" from Command: prompt...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: aliases loaded from LISP - problem
« Reply #2 on: August 06, 2013, 08:03:15 AM »
They should work as you have them, but the nil will go away if you close your lisp macro with a (princ).

eg.
Code: [Select]
(defun c:w () (command "_matchprop") (princ))
Now, for dialog vs. commandline, you need to place (initdia) before the (comand ...) to initiate the dialog. (initcommandversion) is another that can be needed, but I don't recall of a particular command that requires it.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

jackson5

  • Guest
Re: aliases loaded from LISP - problem
« Reply #3 on: August 06, 2013, 04:54:28 PM »
alanjt thanks, (initdia) solved the second problem.
As for the first problem I found that different commands used in my scripts
works either in English version (with "_" before the command) or in my native language
version (at work I don't have English version) - that's strange, I thought that every
command used un English with "_" mark before the word should be enough to make
it work in any language version...
ribarm I wouldn't call such basic thing as using your own aliases messing around.
See, I don't use icons and I don't need to look at the keyboard using my shortcuts
and that's what I would like to stick to in the future releases too :)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: aliases loaded from LISP - problem
« Reply #4 on: August 06, 2013, 04:56:24 PM »
Best practice is to always prefix all command names with "_."

eg.

Code: [Select]
(command "_.line")
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: aliases loaded from LISP - problem
« Reply #5 on: August 07, 2013, 04:20:15 AM »
The problem with code like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:w () (command "_matchprop"))
is that Lisp function returns before the command is finished and the return value (nil) is used as input for the command.

I suggest using something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun RunCommand (ComStr)
  2.   (command ComStr)
  3.   (while (/= (getvar 'cmdactive) 0)
  4.     (command pause)
  5.   )
  6.   (princ)
  7. )
  8.  
  9. (defun c:w () (RunCommand "_matchprop"))

Lee Mac

  • Seagull
  • Posts: 12917
  • London, England
Re: aliases loaded from LISP - problem
« Reply #6 on: August 07, 2013, 07:06:41 AM »
I suggest using something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun RunCommand (ComStr)
  2.   (command ComStr)
  3.   (while (/= (getvar 'cmdactive) 0)
  4.     (command pause)
  5.   )
  6.   (princ)
  7. )

Just be careful if calling commands requiring MText input.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: aliases loaded from LISP - problem
« Reply #7 on: August 07, 2013, 07:56:55 AM »
All I can say is that you are messing with already defined aliases by default installation of ACAD...

That is not considered a problem.
In fact, using a lisp function in your own custom file (acaddoc.lsp) is the right way to do this since lisp definitions always win over PGP shortcut definitions.

Lee Mac

  • Seagull
  • Posts: 12917
  • London, England
Re: aliases loaded from LISP - problem
« Reply #8 on: August 07, 2013, 08:09:12 AM »
I want to load all my aliases from a simple LISP file - instead of typing it into PGP file.
It's more convenient for me (I often migrate to different machines).

Could you not migrate the PGP file?

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: aliases loaded from LISP - problem
« Reply #9 on: August 07, 2013, 08:19:45 AM »
I want to load all my aliases from a simple LISP file - instead of typing it into PGP file.
It's more convenient for me (I often migrate to different machines).

Could you not migrate the PGP file?
Or have all aliases stored in a LISP that can easily be written to the acad.pgp...

Code: [Select]
(defun c:EditPGP (/ f o)
  (if (and (setq f (findfile "acad.pgp"))
           (setq o (open f "a"))
      )
    (progn
      (foreach alias '("U,  *UCS"
                       "V,  *VIEW"
                       "R,  *EXTEND"
                       "W,  *MATCHPROP"
                      )
        (write-line alias o)
      )
      (close o)
      (setvar 'RE-INIT 16)
    )
  )
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: aliases loaded from LISP - problem
« Reply #10 on: August 08, 2013, 02:34:01 AM »
I think you guys suggesting migrating and/or modifying the PGP didn't read the OP fully
Hi, I want to load all my aliases from a simple LISP file -
instead of typing it into PGP file. It's more convenient for me
(I often migrate to different machines).
Now, if migration happens the PGP needs to be changed. Then if moving to the next PC, the original PGP needs to be restored (so you needed a backup in order to restore it).

The OP's idea is a lot simpler: When sitting down at a new PC, load your "special alias" LSP file and you're done. When you're finished, there's nothing you need to do to clean up after yourself, just close ACad and the next time it starts the original settings are back where they were. IMO the LSP way is much better for such a temporary adjustment, for a permanent change the PGP route is preferred.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

jackson5

  • Guest
Re: aliases loaded from LISP - problem
« Reply #11 on: August 08, 2013, 05:22:38 PM »
Yes, that's true. I need to have the machine in the default settings when I leave it, and loading
the LISP's seems to be the best way to have it.

I'm still having some problems with
(defun c:12 () (initdia)(command "_.open")(princ))
(defun c:ds () (initdia)(command "_.dimstyle")(princ))

the "runcommand " doesn't help...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: aliases loaded from LISP - problem
« Reply #12 on: August 08, 2013, 05:53:53 PM »
You are right (RunCommand) does not solve the issue with dialogs.

Try this instead (works OK on BricsCAD):
Code - Auto/Visual Lisp: [Select]

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: aliases loaded from LISP - problem
« Reply #13 on: August 08, 2013, 05:58:30 PM »
Or:
Code - Auto/Visual Lisp: [Select]
  1. (setq *SendCommandActiveDocument* (vla-get-activedocument (vlax-get-acad-object)))
  2.  
  3. (defun SendCommand (comStr)
  4.     *SendCommandActiveDocument*
  5.     (strcat comStr " ")
  6.   )
  7.   (princ)
  8. )
  9.  
  10. (defun c:MyOpen () (SendCommand "_.open"))
  11. (defun c:MyDimstyle () (SendCommand "_.dimstyle"))

jackson5

  • Guest
Re: aliases loaded from LISP - problem
« Reply #14 on: August 10, 2013, 05:27:47 AM »
OK, is there a way to put in that lisp also some keys combination? At the moment
I need to modify mu CUI file to get some useful shortcuts for variables, like this

orto (F2)
=====
^P'_.orthomode $M=$(if,$(and,$(getvar,orthomode),1),$(-,$(getvar,orthomode),1),$(+,$(getvar,orthomode),1))

pickstyle (Ctrl+R)
============
'_setvar;pickstyle;$M=$(if,$(eq,$(getvar,pickstyle),0),1,$(if,$(eq,$(getvar,pickstyle),1),0,$(if,$(eq,$(getvar,pickstyle),2),3,2)))

osnap 675  (Ctrl+T)
==============
^P'_setvar;osmode;675

prompt history window (Shift+F2)
========================
$M=$(if,$(and,$(>,$(getvar,WNDLTEXT),0)),^c^c_GraphScr,^c^c_TextScr)