Asterisk doesn't repeat string of commands on macro?

jason.bowman
Advocate

Asterisk doesn't repeat string of commands on macro?

jason.bowman
Advocate
Advocate

We have a command that we've made which allows us to select a polyline and then it inputs a area where we can specify a base point and adds it as a text element. However, this command doesn't repeat itself, it only repeats the last command in the string. I've added a * at the start of the command but it doesn't appear to work.

 

The macro we are using is as below:

^C^C-LAYER T -HK-HEADAREAS M -HK-HEADAREAS C 54 -HK-HEADAREAS LW 0.00 -HK-HEADAREAS PL NOPLOT -HK-HEADAREAS ;^C^CAREA O \ ^C^Cattdia;0;_-insert;AREABLK;\1;1;0;$M=$(rtos,$(*,0.000001,$(getvar,area)),2,3);attdia;1

 

We either want it to continue running the command until it is cancelled by using Esc etc like normal or to run the command once and then run again when the Enter key is pressed?

0 Likes
Reply
Accepted solutions (1)
1,123 Views
11 Replies
Replies (11)

ВeekeeCZ
Consultant
Consultant

Is the LISP option? Are you on LT?

0 Likes

jason.bowman
Advocate
Advocate

No, full version of AutoCAD 2019

0 Likes

ВeekeeCZ
Consultant
Consultant

The thing is that with MARCO are very limited options for repetition. Which in LISP is a natural thing.

So I would rewrite that to LISP.

Would post that block of yours and a sample dwg with desired outcome?

0 Likes

jason.bowman
Advocate
Advocate

Drawing attached as below, basically if you draw any polyline and use the macro on it, you can insert the head area as a piece of text.

0 Likes

ВeekeeCZ
Consultant
Consultant

Sorry, back to the question. How about make it a field?

0 Likes

jason.bowman
Advocate
Advocate

Not sure what benefit that would have to us, we use the areas provided to input into a hydraulic calc program so a label or text, whatever is easiest.

 

But its worth noting we can have 100+ different areas, so if the field is limited then a label or text would be better suited as they all need their individual figures.

0 Likes

ВeekeeCZ
Consultant
Consultant

Ok. Text it is.

One more question. Your code requires a click to place the text. Maybe your shapes (or most of them?) are all rectangles and then the text could be placed automatically to the LL corner?

0 Likes

jason.bowman
Advocate
Advocate

Nope, we'd need a specify point as some of the areas are polygonal rather than a normal rectangle - also gives our designers the option to move them to a more visible spot on the drawing if necessary.

0 Likes

ВeekeeCZ
Consultant
Consultant
Accepted solution

Besides some minor improvements I kept your algorithm to you to see the differences.

 

(defun c:Headareas ( / *error* atr atd lay cmd en)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if atr (setvar 'attreq atr))
    (if atd (setvar 'attdia atd))
    (if lay (setvar 'clayer lay))
    (if cmd (setvar 'cmdecho cmd))
    (princ)
    )
  
  ; -------------------------------------------
  
  (if (or (tblsearch "BLOCK" "AREABLK")
	  (prompt "\nError: No 'areablk' found in the drawing!"))

    (progn  
      (setq atr (getvar 'attreq)
	    atd (getvar 'attdia)
	    lay (getvar 'clayer)
	    cmd (getvar 'cmdecho))
      
      (setvar 'attreq 1)
      (setvar 'attdia 0)
      (setvar 'cmdecho 0)
      (command "LAYER" "T" "-HK-HEADAREAS" "M" "-HK-HEADAREAS" "C" 54 "" "LW" 0.00 "" "PL" "NOPLOT" "" "")
      
      (while (setq en (car (entsel "\rSelect readarea <exit>: ")))
	(princ "\rPlace the label: ")
	(command "AREA" "O" en
		 "INSERT" "AREABLK" "S" 1 "R" 0 PAUSE (rtos (* 0.000001 (getvar 'area)) 2 3)))
      
      (*error* "end")))
  )

Edit: Code updated. The layer command should run before the loop.

0 Likes

jason.bowman
Advocate
Advocate

That's perfect!! Thank you for that, it's much appreciated, feel like you've just improved our workflow by about a billion percent, saves us clicking the button every time

Kent1Cooper
Consultant
Consultant

Just a thought [untested]:  I've done some self-repeating macro commands with the *^C^C at the beginning, but I've never had any additional cancels inside them, the way your code has.  Is there some reason for the ^C^C cancel entries before some of the within-the-macro command names?  They shouldn't be necessary, if the macro is written correctly for inputs to complete all commands involved.  What if you take those out, and use *^C^C at the beginning of the whole thing?  I'm just speculating that maybe the ^C^C's inside could be what makes it not repeat the whole macro.

Kent Cooper, AIA
0 Likes