5 in 1

Discussion in 'AutoCAD' started by Adesu, Jun 25, 2004.

  1. Adesu

    Adesu Guest

    Dear Alls,
    How to combine 5 program become 1;
    1.(defun a:aa()
    bla..bla..bla)
    2.(defun b:bb()
    bla..bla.. bla)
    3.(defun c:cc()
    bla..bla..bla)
    4.(defun d:dd()
    bla..bla..)
    5.(defun e:ee()
    bla..bla..bla)
    I would only become 1 program,but alls program can it run,thanks for your help.
    Best regards
    Ade Suharna
     
    Adesu, Jun 25, 2004
    #1
  2. Adesu

    Barr Guest

    Add them all to your acad.lsp file.
    They then be available when acad.lsp is autoloaded at drawing startup.
    Or if you wish, combine them all in one other program, and (load
    "other_program").

    But note that every defun should read
    (defun c:name_of_command ( ) ...

    The " c: " indicates it will be a command available at the command line.

    (defun c:aa()
    bla..bla..bla)
    (defun c:bb()
    bla..bla.. bla)
     
    Barr, Jun 25, 2004
    #2
  3. Adesu

    BillZ Guest

    Dear Alls,
    Have them all in the same file, then when you load the base file, all defuns will be loaded and available for call.


    Bill
     
    BillZ, Jun 25, 2004
    #3
  4. Adesu

    zeha Guest

    I used mostly the follow:

    make lists of the variable something like
    (setq yourLst '(("apples" 25 1.49 "Delicious")("oranges" 42 1.39 "Valencia")("cherries" 250 2.99 "Bing")))

    The functions can combined to one with arguments

    (defun a:aa(key lst ) bla..bla..bla)

    A good example is the follow function dxf

    (defun dxf (code ename)
    (cdr (assoc code (if (= (type ename) 'ENAME)(entget ename) ename)))
    )

    (dxf 10 (car (entsel))) give's a point from the most entity's

    also (dxf 10 (entget (car (entsel)))) give's this code

    (dxf 0 (car (entsel))) give's the entity name

    (dxf "apples" yourLst) give's (25 1.49 "Delicious")

    (dxf "cherries" yourLst) give's (250 2.99 "Bing")


    Next function substitude

    (defun sDxf (num val lst /)
    (if (assoc num lst)(subst (cons num val)(assoc num lst) lst)(append lst (list (cons num val))))
    )

    (sDxf "cherries" '(12 10) yourLst) give's (("apples" 25 1.49 "Delicious") ("oranges" 42 1.39 "Valencia") ("cherries" 12 10))


    (sDxf "New" '("a" 12 10) yourLst) give's (("apples" 25 1.49 "Delicious") ("oranges" 42 1.39 "Valencia") ("cherries" 250 2.99 "Bing") ("New" "a" 12 10))


    Thus (setq newLst (sDxf "New" '("a" 12 10) yourLst)) sets the variable newLst to (("apples" 25 1.49 "Delicious") ("oranges" 42 1.39 "Valencia") ("cherries" 250 2.99 "Bing") ("New" "a" 12 10))

    Hope's this helps
     
    zeha, Jun 25, 2004
    #4
  5. Hi Zeha,
    obviously you're a code guru.
    No prob with that only Adesu asked something different.

    Nice weekend.

    Jan

    "Valencia")("cherries" 250 2.99 "Bing")))
    ("oranges" 42 1.39 "Valencia") ("cherries" 12 10))
    ("oranges" 42 1.39 "Valencia") ("cherries" 250 2.99 "Bing") ("New" "a" 12
    10))
    newLst to (("apples" 25 1.49 "Delicious") ("oranges" 42 1.39 "Valencia")
    ("cherries" 250 2.99 "Bing") ("New" "a" 12 10))
     
    Jan van de Poel, Jun 25, 2004
    #5
  6. Adesu

    Barr Guest

    How bout me? Did I get it right?
    Makin no claim to the title 'code guru' here.<g>
    -doug
     
    Barr, Jun 25, 2004
    #6
  7. You were close, I think. ;^)

    --
    R. Robert Bell


    How bout me? Did I get it right?
    Makin no claim to the title 'code guru' here.<g>
    -doug

    <snicker>
     
    R. Robert Bell, Jun 25, 2004
    #7
  8. Doug,

    Just quick note... every defun is *not* required start to with "C:" or ""
    (no prefix).

    ;;; AcadDoc.lsp (or other .lsp file)
    (defun I:MySubr1 ()
    ;|...|;)

    (defun My:Subr2 ()
    ;|...|;)

    (defun C:MyCommand ()
    (I:MySubr1)
    (My:Subr2)
    ;|...|;)
    ;;; end of AcadDoc.lsp

    Or, in Adesu's example, if he really wants all those function separate, but
    also needs one command to run them all in one shot also:

    (defun C:MyCombo ()
    (a:aa)
    (b:bb)
    (c:cc)
    (d:dd)
    (e:ee))

    Which is something you mentioned but did not demonstrate.

    --
    R. Robert Bell


    Add them all to your acad.lsp file.
    They then be available when acad.lsp is autoloaded at drawing startup.
    Or if you wish, combine them all in one other program, and (load
    "other_program").

    But note that every defun should read
    (defun c:name_of_command ( ) ...

    The " c: " indicates it will be a command available at the command line.

    (defun c:aa()
    bla..bla..bla)
    (defun c:bb()
    bla..bla.. bla)
     
    R. Robert Bell, Jun 25, 2004
    #8
  9. Adesu

    Barr Guest

    I gotcha. I certainly use
    (defun subroutine ( ) ...
    all over the place.

    I figured Ade was either misinterpreting the c: concept
    or had simply botched his typing with lightning-fast fingers:
    (a:aa b:bb c:cc d:dd <boy I did that fast!>

    Are there any other "(defun " modes I'm unaware of?
    (defun routine ( ) ....
    (defun c:routine ( ) ....

    Being hideously far from qualifying as a code guru.
    -doug
     
    Barr, Jun 25, 2004
    #9
  10. Not modes, necessarily, aside from S::Startup, of course.

    But I use regularly:
    (defun I:Routine () ... to indicate an internal subr (for article writing
    purposes)
    (defun rrbI:Routine () ... RRBI is my Autodesk registered developer's symbol


    As you can see, you can actually use anything for a prefix. Consistent use
    of a prefix such as I: might help you maintain your code library, because
    you can look at main code and see where you are using your own internal
    toolbox subrs.


    --
    R. Robert Bell


    I gotcha. I certainly use
    (defun subroutine ( ) ...
    all over the place.

    I figured Ade was either misinterpreting the c: concept
    or had simply botched his typing with lightning-fast fingers:
    (a:aa b:bb c:cc d:dd <boy I did that fast!>

    Are there any other "(defun " modes I'm unaware of?
    (defun routine ( ) ....
    (defun c:routine ( ) ....

    Being hideously far from qualifying as a code guru.
    -doug
     
    R. Robert Bell, Jun 25, 2004
    #10
  11. Adesu

    Barr Guest

    purposes)

    Are you saying you use I: just for your article, but convert it to c: for your
    code?

    I've always believed that the c: was a requirement.
    Guuhh-aaawwww-Leee!</vox Gomer>
     
    Barr, Jun 25, 2004
    #11
  12. No.

    Look carefully at my first post again, the one with the sample AcadDoc.lsp.

    Note that there are 3 functions defined there. One is a command-line
    function, C:MyCommand. C:MyCommand happens to use to subroutines. One of the
    subr's is I:MySubr1. It is called in C:MyCommand first by the statement
    (I:MySubr1). The other subr is My:Subr2, which shows that you can have
    various prefixes. It is called in C:MyCommand second by the statement
    (My:Subr2).

    This is somewhat abstract at the moment, so let's flesh my sample out a bit.
    ;;; start of .lsp
    (defun I:MySubr1 ()
    (princ "\nI'm subr number 1."))

    (defun My:Subr2 ()
    (princ "\nI'm subr number 2."))

    (defun C:MyCommand ()
    (I:MySubr1)
    (My:Subr2)
    (princ))
    ;;; end of .lsp

    Load the functions, then run Command: MyCommand. Note the results.


    --
    R. Robert Bell


    purposes)

    Are you saying you use I: just for your article, but convert it to c: for
    your
    code?

    I've always believed that the c: was a requirement.
    Guuhh-aaawwww-Leee!</vox Gomer>
     
    R. Robert Bell, Jun 25, 2004
    #12
  13. Adesu

    zeha Guest

    Jan,

    Aan je naam zou ik kunnen afleiden dat je uit Nederland komt
    Ik dus ook.
    Not a code guru

    Have a nice weekend

    Harrie
     
    zeha, Jun 25, 2004
    #13
  14. Adesu

    Barr Guest

    So what did you mean by
    "... to indicate an internal subr (for article writing purposes)"
    ?

    Don't grumble and take me for a maroon... I think my
    confusion after reading that is justified!
    -doug
     
    Barr, Jun 25, 2004
    #14
  15. No problem...

    When I write code for magazine articles, or to post somewhere on the
    Internet, I use the I: prefix to indicate a subr. So when I visually scan
    thru the main function, I can see where I'm using a subr that I need to be
    sure to include in the article/post.

    --
    R. Robert Bell


    So what did you mean by
    "... to indicate an internal subr (for article writing purposes)"
    ?

    Don't grumble and take me for a maroon... I think my
    confusion after reading that is justified!
    -doug
     
    R. Robert Bell, Jun 25, 2004
    #15
  16. Adesu

    Barr Guest

    Gotcha.
    And I'm not just taking your word for it (skeptic that I am).
    I just renamed a subr ==> I:subr, and natch, it still worked.

    So I guess the colon in a defun is treated just like any other
    character... except when defining a command-line routine call.
     
    Barr, Jun 25, 2004
    #16
  17. Adesu

    Adesu Guest

    Very sorry for you confuse,I mean this program
    1.(defun c:aa()
    bla..bla..bla)
    2.(defun c:bb()
    bla..bla.. bla)
    3.(defun c:cc()
    bla..bla..bla)
    4.(defun c:dd()
    bla..bla..)
    5.(defun c:ee()
    bla..bla..bla)
    Can anybody give me sample,yhanks
     
    Adesu, Jun 28, 2004
    #17
  18. Adesu

    zeha Guest

    Do you mean something like R Robert Bell wrote

    maybe this is an simple example

    (defun C:MyCombo (/ keywrd)
    (initget 6 "Aa Bb Cc Dd")
    (setq keywrd (getkword "\nAa/Bb/Cc/Dd Choose a program <Return> for none: "))
    (cond ((= keywrd "Aa") (c:aa))
    ((= keywrd "Aa") (c:aa))
    ((= keywrd "Bb") (c:bb))
    ((= keywrd "Cc") (c:cc))
    ((= keywrd "Dd") (c:dd))
    (T (princ "\nNot a program runned. "))
    )
    (princ)
    )
     
    zeha, Jun 28, 2004
    #18
  19. Adesu

    Adesu Guest

    No like that,but I want only one type (c:mycombo) in command prompt,alls
    program can execute,from program c:aa to continuous c:bb then
    c:cc.......etc,now I don't know how to combine it.
     
    Adesu, Jun 29, 2004
    #19
  20. Adesu

    Barr Guest

    (defun c:mycommand ()
    (aa)
    (bb) ; These are subroutines (no c: required)
    (cc)
    )

    (defun aa () ; These are the definitions of the subroutines
    (do stuff)
    )
    (defun bb ()
    (do stuff)
    )
    (defun cc ()
    (do stuff)
    )
     
    Barr, Jun 29, 2004
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...