Toolbar macro for block with attribute

Dear forum members,

I'm trying to create a macro to insert a block with one attribute. After the block has been inserted I want to run a lisp-function.

This works:

^C^C^C_-INSERT;ArrowInfo;\100;;0;\

This produces errors:

^C^C^C_-INSERT;ArrowInfo;\100;;0;\(princ "\nA lisp-function will follow")(princ)

This also produces errors:

^C^C^C_-INSERT;ArrowInfo;\100;;0;\_-INSERT;ArrowInfo;\100;;0;\

I've tried playing around with attdia. But that doesn't solve the problem. Though a different error occurs depending on attdia.

What am I doing wrong?

Regards, Roy.

(note: I still use BC7)

Comments

  • It doesn't work in v9 either. There's no error code, but it doesn't pause for the input of the attribute. Maybe you're not supposed to mix macro & lisp code? I don't know. I rarely use macro code. Maybe it would work if you defined the lisp function in your on_start.lsp file, making it a custom command, and then include that command at the end of the macro.

    It does work as a menu item in v9 if you change it to all lisp:

    (command "_-INSERT" "ArrowInfo" pause "100" "" "0")(while (> (getvar "cmdactive") 0)(command pause))(princ "\nA lisp-function will follow")(princ)

  • Roy's first line works in my V9, when I cut off past the last ; - ^C^C^C_-INSERT;xxx;\100;;0; - xxx being any block with one attribute within the dwg or from the disk.

    Attdia just brings up the attribute prompt box if it's on.

  • Instead of running a macro and then a lisp-function, I would run only a LISP command, and insert the block etc. from within that command,

    so you've got only the lisp-function to deal with in the toolbar, maybe this eases things a bit.

  • Dear forum members,

    Thank you for your answers.

    To give you some idea of what I'm trying to achieve  I'll paste my code below.

    THE PLAN: to create 2 simple and versatile lisp functions that can be used in macros for drawing arrows, sewers etc.

    THE RESULT: The lisp functions are simple but the macros are anything but!

     

    ;;; 2PPInit creates these global variables:
    ;;; 2PP-P1
    ;;; 2PP-P2
    ;;; 2PP-midP1P2
    ;;; 2PP-angP1P2
    ;;; 2PP-angP2P1
    ;;; 2PPInit also stores a number of dwg-variables.
    ;;; 2PPExit resets all global variables and all dwg-variables.

    ;;; The variables listed above can be used in macros:
    ;;; ^C^C^C2PPInit;\\_LINE;!2PP-P1;!2PP-P2;;2PPExit
    ;;; ^C^C^C2PPInit;\\_LINE;!2PP-P1;!2PP-P2;;_-INSERT;ArrowHead;!2PP-P1;100;;!2PP-angP1P2;2PPExit
    ;;; ^C^C^C2PPInit;\\_LINE;!2PP-P1;!2PP-P2;;_-INSERT;ArrowHead;!2PP-P1;100;;!2PP-angP1P2;_-INSERT;ArrowHead;!2PP-P2;100;;!2PP-angP2P1;2PPExit
    ;;; ^C^C^C2PPInit;\\_LINE;!2PP-P1;!2PP-P2;;_-INSERT;ArrowHead;!2PP-P1;100;;!2PP-angP1P2;_-INSERT;ArrowDot;!2PP-P2;100;;!2PP-angP1P2;2PPExit
    ;;; ^C^C^C2PPInit;\\_LINE;!2PP-P1;!2PP-P2;;_-INSERT;ArrowHead;!2PP-P1;100;;!2PP-angP1P2;_-INSERT;ArrowHead;!2PP-P2;100;;!2PP-angP2P1;_-INSERT;ArrowDot;!2PP-midP1P2;100;;!2PP-angP1P2;2PPExit

    ;;; ArrowInfo is a block with one attribute:
    ;;; ^C^C^C2PPInit;\\_LINE;!2PP-P1;!2PP-P2;;_-INSERT;ArrowHead;!2PP-P1;100;;!2PP-angP1P2;_-INSERT;ArrowHead;!2PP-P2;100;;!2PP-angP2P1;_-INSERT;ArrowInfo;!2PP-midP1P2;100;;!2PP-angP1P2;spanrichting;2PPExit
    ;;; ERROR: ^C^C^C2PPInit;\\_LINE;!2PP-P1;!2PP-P2;;_-INSERT;ArrowHead;!2PP-P1;100;;!2PP-angP1P2;_-INSERT;ArrowHead;!2PP-P2;100;;!2PP-angP2P1;_-INSERT;ArrowInfo;!2PP-midP1P2;100;;!2PP-angP1P2;\2PPExit
    ;;; ERROR: ^C^C^C_-INSERT;ArrowInfo;\100;;0;\(princ "\nA lisp-function will follow")(princ)
    ;;; ERROR: ^C^C^C2PPInit;\\_LINE;!2PP-P1;!2PP-P2;;_-INSERT;ArrowHead;!2PP-P1;100;;!2PP-angP1P2;_-INSERT;ArrowHead;!2PP-P2;100;;!2PP-angP2P1;_-INSERT;ArrowInfo;!2PP-midP1P2;100;;!2PP-angP1P2;'(nth 0 attInfo);2PPExit

    (defun c:2PPInit ( / )
    (setq
    2PP-oldAttdia (getvar "attdia")
    2PP-oldCecolor (getvar "cecolor")
    2PP-oldClayer (getvar "clayer")
    2PP-oldOsmode (getvar "osmode")
    2PP-P1 (getpoint "\nFirst point: ")
    2PP-P2 (getpoint 2PP-P1 "\nSecond point: ")
    2PP-midP1P2 (mapcar '/ (mapcar '+ 2PP-P1 2PP-P2) '(2.0 2.0 2.0))
    2PP-angP1P2 (* (/ (angle 2PP-P1 2PP-P2) pi) 180.0)
    2PP-angP2P1 (* (/ (angle 2PP-P2 2PP-P1) pi) 180.0)
    )
    (setvar "attdia" 0)
    (setvar "osmode" 0)
    (princ)
    )

    (defun c:2PPExit ( / )
    (setvar "attdia" 2PP-oldAttdia)
    (setvar "cecolor" 2PP-oldCecolor)
    (setvar "clayer" 2PP-oldClayer)
    (setvar "osmode" 2PP-oldOsmode)
    (setq
    2PP-oldCecolor nil
    2PP-oldClayer nil
    2PP-oldOsmode nil
    2PP-P1 nil
    2PP-P2 nil
    2PP-midP1P2 nil
    2PP-angP1P2 nil
    2PP-angP2P1 nil
    )
    (redraw)
    (princ)
    )

    (princ "\n2PP.lsp for macros loaded. ")
    (princ)

     

    I think Jörg has a good point. I'll try using his advice and Anthony's code.

    Thanks again everybody!

    Regards, Roy.

This discussion has been closed.