Author Topic: Macro doesn't work  (Read 966 times)

0 Members and 1 Guest are viewing this topic.

AKeng

  • Mosquito
  • Posts: 2
Macro doesn't work
« on: December 17, 2019, 11:30:53 AM »
625/5000
Hello I have found a macro with google, I want to use this because I am always working on the wrong layer.
The purpose of this macro is, when I click on LINE, for example, the "MyLayerToolbar" appears in which I have to choose a layer to continue, so far it all works.
After choosing the layer, pressing the spacebar would close the toolbar again and I can draw on the correct layer.
But why it doesn't work I don't know and can't figure it out, I've seen it work in AutoCad 2008 and I'm working with AutoCad 2017.
Does anyone have a tip to solve this.
Thanks in advance.

Code: [Select]
C^C^C_-TOOLBAR;MyLayerToolbar;_SHOW;\_-TOOLBAR;MyLayerToolbar;_HIDE;;_LINE


EDIT (John): Fixed subject line spelling.
« Last Edit: December 17, 2019, 12:38:28 PM by John Kaul (Se7en) »

BIGAL

  • Bull Frog
  • Posts: 474
  • 30 + years of using Autocad
Re: Macro doesn't work
« Reply #1 on: December 17, 2019, 08:01:15 PM »
This may be a better way pick an existing object and it sets layer and starts same object command. It has shortcut type zzz.

Sorry do not know author.

A man who never made a mistake never made anything

rayakmal

  • Newt
  • Posts: 35
Re: Macro doesn't work
« Reply #2 on: December 17, 2019, 09:53:14 PM »
625/5000
Hello I have found a macro with google, I want to use this because I am always working on the wrong layer.
The purpose of this macro is, when I click on LINE, for example, the "MyLayerToolbar" appears in which I have to choose a layer to continue, so far it all works.
After choosing the layer, pressing the spacebar would close the toolbar again and I can draw on the correct layer.
But why it doesn't work I don't know and can't figure it out, I've seen it work in AutoCad 2008 and I'm working with AutoCad 2017.
Does anyone have a tip to solve this.
Thanks in advance.

Code: [Select]
C^C^C_-TOOLBAR;MyLayerToolbar;_SHOW;\_-TOOLBAR;MyLayerToolbar;_HIDE;;_LINE

Try this:

Code: [Select]
;;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;;
;; LAYER SET BY ENTITY SELECTION
;;
;;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
(Defun c:LAS (/ olderr ent lyr )

   (Prompt "Set Layer")
   (setq olderr *error* *error* myerr)

   (cond ( (setq ent (entsel "\n. Pick entiti      : "))
           (setq lyr (cdr (assoc 8 (entget (car ent)))))
           (command "layer" "set" lyr "" )
           (princ (strcat "\n. Current layer    : " "\"" lyr "\""))
         )
   )

   (setq *error* olderr olderr nil)
   (princ)
)


(defun myerr (msg) ; Function canceled ?
  (if (and (/= msg "Function cancelled")
   (/= msg "quit / exit abort")
      )
    (princ (strcat "\nError: " msg)) ; print a message
  )
  (setq *error* olderr
olderr nil
  ) ; restore error handler !
  (princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: Macro doesn't work
« Reply #3 on: December 18, 2019, 12:28:52 PM »
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.

AKeng

  • Mosquito
  • Posts: 2
Re: Macro doesn't work
« Reply #4 on: December 19, 2019, 04:47:24 AM »
Hello,
Sorry to respond so late, I didn't get a notification.
Have the idea that my question has not been very clear.
"MyLayerToolbar" is its own toolbar with only the "layer control" command in it.
See image

If I click on the toolbar then I get the entire dropdown list and can choose a layer, if this is done the toolbar should close and execute the _LINE command and that somehow doesn't work.
Hope this is a better explanation.

roy_043

  • Water Moccasin
  • Posts: 1804
  • BricsCAD 18
Re: Macro doesn't work
« Reply #5 on: December 19, 2019, 08:36:15 AM »
For reference previous (Dutch) discussion:
https://www.cadsite.be/smf/index.php?topic=6766.0

tombu

  • Bull Frog
  • Posts: 206
  • ByLayer=>Not0
Re: Macro doesn't work
« Reply #6 on: December 19, 2019, 10:59:35 AM »
As you're now using a more recent version of AutoCAD now you should try adding the "Layer List Combo Box" to your Quick Access Toolbar. It's a lot more powerful than the toolbar control and combined with "Layer Previous" or "Make Objects Layer Current" makes your procedure a couple clicks and works for any command not just LINE.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

jethro_in_petaluma

  • Mosquito
  • Posts: 2
Re: Macro doesn't work
« Reply #7 on: December 19, 2019, 05:51:28 PM »
Hello, I want to present to you, what I believe may be a much simpler solution. Fewer keystrokes is better.
On my computer, I have assigned many hotkeys to single keys on the keyboard, by putting special entries into the startup lisp called acad.lsp.
I will not go into all of them, but I want to mention two, that seem very relevant to the task you are describing.
Here is what I can do:
I hit the "G" key then hit enter.  It prompts, "select object whose layer will become current".
Then I click on a line or a block or other object, and it's layer instantly becomes my current layer.
Why did I choose the G key? "G" = Go to a layer.
******************    *********************
Now for one more: 
I hit the "Y" key and then hit enter.  It prompts, "Select objects to be changed to the current layer".
Then I select one or more objects and then hit enter, then all those objects get moved to the current layer.
<Why did I choose the Y key? "Y" = Yank objects to the current layer.
Maybe you know the modifications to make the .lsp file, so maybe I don't need to explain that right now. 
OK, here's a few more shortcuts that I use:  L= line   K= polyline   J= sketch   A= arc   E= spline.
A MORE POWERFUL SOLUTION: 
Just use the Palette.  You can assign a line, a text and a dimension command to the Palette, and you may specify which layer it will be on.  The layer will revert back to the original layer when you are done with the command.  I think the Palette is a lot more powerful and more adaptable than these other methods.  Cheers!
« Last Edit: December 20, 2019, 11:39:21 AM by jethro_in_petaluma »

Rustabout

  • Newt
  • Posts: 46
Re: Macro doesn't work
« Reply #8 on: December 19, 2019, 09:24:36 PM »
Hi Akeng,

In addition to the suggestions already offered, I should share a problem I recently had: I copied and pasted a macro into the CUI. It was a very simple macro and I almost lost my mind not being able to get it to work. It turns out that whatever format I copied didn't jive with AutoCAD's CUI for some reason, and manually typing it in fixed my problem. Either manually type it in. Or type pasting it into a notepad (.txt) file, then pasting it into the CUI. Maybe copying off the web places text in "rich text format".

This sounds absurd I know, but I cannot figure out what else created my problem (there weren't any typos in the original text).

tombu

  • Bull Frog
  • Posts: 206
  • ByLayer=>Not0
Re: Macro doesn't work
« Reply #9 on: January 02, 2020, 08:35:38 AM »
Hi Akeng,

I copied and pasted a macro into the CUI. It was a very simple macro and I almost lost my mind not being able to get it to work. It turns out that whatever format I copied didn't jive with AutoCAD's CUI for some reason, and manually typing it in fixed my problem. Either manually type it in. Or type pasting it into a notepad (.txt) file, then pasting it into the CUI. Maybe copying off the web places text in "rich text format".
This sounds absurd I know, but I cannot figure out what else created my problem (there weren't any typos in the original text).
Usually it's quotation marks used by Office software for file paths as an example will not work, only "" will.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

stevej

  • Mosquito
  • Posts: 17
Re: Macro doesn't work
« Reply #10 on: January 03, 2020, 06:27:47 PM »
Here is a Layer Director reactor that LeeMac wrote way back in 2008 that I use daily.
I've changed it to suit your particular requirements.
You can add it to your acaddoc.lsp file so it runs automatically, or save it as a .lsp file and drop it onto the active drawing when you need it.
It makes the layer if it does not exist, and issuing the LINE command switches to the layer.
When you exit the LINE command, it returns you to the layer you were previously working on.

This is all LeeMac's code.
Please respect his efforts and retain all the header information that references the author and the original thread.

Code: [Select]
;; Modified from:
;; Layer Director posted by Lee Mac 11 Dec 2008
;; http://www.cadtutor.net/forum/showpost.php?p=194484&postcount=3
;; Post 3
;;
;; Modified to perform a single task for single command, because that's all I really needed.  Steve
;;
;; (Double-semicolon comments because VLIDE tabs single-semicolons
;;   half way across the known universe when formatting the code.)
;;
;; Layer Director
;;
(vl-load-com)
;; ***********************************************************************
;; Makes the layer if it does not exist. This section was not part of the
;;   original Layer Director code as posted at the link above by LeeMac,
;;   but was added later to make sure the layer existed before activating
;;   the reactor. Steve
;;
  (if (not (tblsearch "LAYER" "Alg.-hatch"));; If the layer does not exist,
    (entmake                                ;; then make it
      (list                                 ;; by doing all this stuff
         '(0 . "LAYER")
         '(100 . "AcDbSymbolTableRecord")
         '(100 . "AcDbLayerTableRecord")
         '(70 . 0)
          (cons 2 "Alg.-hatch")  ;; layer name
          (cons 6 "CONTINUOUS")  ;; linetype
          (cons 62 7)            ;; color WHITE
          (cons 370 -3)          ;; default line weight
      );;end list
    );;end entmake
  );;endif
;; ***********************************************************************

(if(not cmdReactor)
  (setq cmdReactor
    (vlr-command-reactor nil
        '((:vlr-commandWillstart . startCommand)
          (:vlr-commandEnded . endcommand)
          (:vlr-commandCancelled . cancelCommand))
    );; end command reactor
  );;end setq
);;end if

(defun startCommand (calling-reactor startcommandInfo / thecommandstart)
    (setq oldlay (getvar "clayer"))  ;;Save Current Layer
    (setq thecommandstart (nth 0 startcommandInfo))
    (cond
        ((= thecommandstart "LINE")  ;;If the command is LINE
         (setvar "clayer" "Alg.-hatch") ;;Set Current Layer to "Alg.-hatch"
        );; end condition 2
    );;end cond
    (princ)
);;end startcommand

(defun endCommand (calling-reactor endcommandInfo / thecommandend)
    (setq thecommandend (nth 0 endcommandInfo))
    (cond
        ((= thecommandend "LINE")    ;;AT END OF THE COMMAND
         (setvar "clayer" oldlay)    ;;RETURN TO ORIGINAL LAYER
        ) ; end condition 2
    );;end cond
    (princ)
);;end endCommand

(defun cancelCommand (calling-reactor cancelcommandInfo / thecommandcancel)
    (setq thecommandcancel (nth 0 cancelcommandInfo))
    (cond
        ((= thecommandcancel "LINE") ;;IF THE COMMAND IS CANCELLED
         (setvar "clayer" oldlay)    ;;RETURN TO ORIGINAL LAYER
        );;end condition 2
    );;end cond
    (princ)
);;end cancelCommand

Steve

BIGAL

  • Bull Frog
  • Posts: 474
  • 30 + years of using Autocad
Re: Macro doesn't work
« Reply #11 on: January 04, 2020, 11:50:14 PM »
The other way to go is have a toolbar with objects, so you will have say dims, base, wall1, wall2, pit etc So you draw on a predefined layer and it starts with the correct command.

It is useful if you don't have to draw on 100's of different layers. I know if a multi site development 300+ re developments, the cad was customised to draw objects not lines, you would have like a canopy menu, car park and so on. No layer errors or the Cad manager would fire you.
A man who never made a mistake never made anything