Macro lisp for consecutive commands

Macro lisp for consecutive commands

larsr2866
Enthusiast Enthusiast
4,802 Views
19 Replies
Message 1 of 20

Macro lisp for consecutive commands

larsr2866
Enthusiast
Enthusiast

Good day everyone,

 

For my work i need to use al lot of repeating actions in autocad (cleaning up existing engineering-plans). So with searching and reading over the internet i have tried to write a script with a few consecutive commands. Only one problem: my script doesn't work at all, and i don't know what am i doing wrong? It would be great if sonemone could help me out with this?

 

I shall describe what i'm would wish to become + what code i am using:

 

 Scale my drawing x10 (between these coordinates)
- scale;49130,-49590,0;387222,166237,0;10;
Freeze layers i dont need (with user input):
-layer;freeze;select;\;;
Explode all blocks (between these coordinates):
Burst;49130,-49590,0;387222,166237,0;
Delete all excisting dimensions and wipeouts:
ssx;;entity;;dimension;;erase;p;;
ssx;;entity;;wipeout;;erase;p;;
Set all objects (between these coordinates) color by layer:
-setbylayer;49130,-49590,0;387222,166237,0;settings;color;;
Change all hatches to a specific color:
ssx;;entity;;hatch;;change;p;;properties;color;truecolor;170,170,170;;
Put the objects from layer "0" automaticaly on layer "background"
ssx;;layer;;0;;change;p;;properties;layer;background;;

 

So i wrote this code to one .lsp file and appload this in autocad but it doesn't do anything?

- scale;49130,-49590,0;387222,166237,0;10;

-layer;freeze;select;\;;

Burst;49130,-49590,0;387222,166237,0;

ssx;;entity;;dimension;;erase;p;;
ssx;;entity;;wipeout;;erase;p;;

-setbylayer;49130,-49590,0;387222,166237,0;settings;color;;

ssx;;entity;;hatch;;change;p;;properties;color;truecolor;170,170,170;;

ssx;;layer;;0;;change;p;;properties;layer;background;;

 

Thank you for your reactions!

 

Lars

0 Likes
Accepted solutions (1)
4,803 Views
19 Replies
Replies (19)
Message 2 of 20

devitg
Advisor
Advisor

script or SCR files, DO NOT ACCEPT USER INPUT 

0 Likes
Message 3 of 20

cadffm
Consultant
Consultant

"So i wrote this code to one .lsp file and appload this in autocad but it doesn't do anything?"

This isn't lisp code. This syntax is like your topic said: macro. MenuMacro 

Not lisp, not script, just menumacro.

 

Sebastian

0 Likes
Message 4 of 20

larsr2866
Enthusiast
Enthusiast

Thanks for your reaction. Sorry i am totally new with this, and i found a lot on the internet, but not exactly what i was looking for.  I searched again and tried to use my programming as a menumacro, but it isn't working either (invalid command?). What would be your advice? I've read that there are more possibilities with lisp programming, but is it possible for wich i wish to become? Is there a good info website with examples for these consecutive commands i try to program? Or is it better with my menumacro  and a few modifications? 

 

I did some research on the lisp code. I see that all commands need to be places between " "

Maybe if someone can help to start me up with this?

 

Thanks in advance!

Lars

0 Likes
Message 5 of 20

devitg
Advisor
Advisor

please upload at least 2 dwg sample. 

 

a 3 dwg as the 1st dwg as have to be after.

And if possible the"to erase" layer's  names list, that way will be easy to handle.

 

 

 

 

 

0 Likes
Message 6 of 20

ВeekeeCZ
Consultant
Consultant

Impressive start Lars!!

Macros are useful in some cases (especially if you have autocad LT) but mostly very limited. Don't recommend you to continue learning this way.

 

You may make your macro working for your ideal example drawing. But let say what if you have no DIMENSIONs in the drawing. Are you able to skip that step? No, the marco fails. And its very complicated to fix that.

 

So I would suggest to start learning LISP. It's much more powerful than macros.

See the attachment where I rewrote your macro to LISP. It's very basic (the first part until a line).

Try to fight yourself with that for a while, then ask if you don't understand something.

 

Read HERE how to run lisp. If you don't make my lisp working, post some testing file due I didn't test my code.

 

PS. There are a lot of free LISP libraries on web - one of those is Lee Mac's page HERE. There I used his BUSRT function which isn't just better than Express Tool's version, but also easier to use within LISP. (don't recommend you to try to learn from it, it's very advanced)

 

0 Likes
Message 7 of 20

larsr2866
Enthusiast
Enthusiast

Thank you so much BeekeeCZ! That's great! 

This will give me a good start in understanding the lisp code. I will also check the link with the lisp librarie. Very helpfull! 🙂

 

The lisp is working perfectly, except for the truebook color. It says this in my command line:

New color [Truecolor/COlorbook] <BYLAYER>: _True Red,Green,Blue: 175.0000000000000,154.0000000000000
Invalid color. Type three comma separated values from 0 to 255.

 

However in your lisp code there are three separated values? Do you have an idea what could be the problem here?

 

I also post my 2 dwg's before and after.

 

Thanks!

Lars

0 Likes
Message 8 of 20

ВeekeeCZ
Consultant
Consultant

Sorry, wrong syntax. It should be "170,170,170"

 

However, for you to learn. My confusion is from the syntax of point coordinates. There are possible both ways and the first one is more the LISP like, the second the ACAD's way. See the example:

 

(command "_line" "_non" '(10 10) "_non" "20,20" "")

And then the second very important thing to learn. When setting point coordinates within the command function (no matter if hardcoded of via variable) ALWAYS make sure to TURN OFF OSNAPs someway! Either use "_none" temp OSNAP mode for each point or for more set OSMODE to 0... or OSNAPCOORD to 1... whatever fits you better.

0 Likes
Message 9 of 20

larsr2866
Enthusiast
Enthusiast

Thanks! That works perfect!

 

I have another question. Is it possible to do the same with with the solids? I tried to use the same line as yours for the hatches but that does'nt seem to work.

 

  (if (setq sst (acet-ss-ssget-filter ss '((0 . "HATCH"))))
    (command "_.CHPROP" sst "" "_Color" "_True" '"170,170,170" "")) => this works

  (if (setq sst (acet-ss-ssget-filter ss '((0 . "SOLID"))))
    (command "_.CHPROP" sst "" "_Color" "_True" '"170,170,170" "")) => this does not?

 

Is it also possible to change also the type of these hatches to Ansi31 with a scale of 16? I have been searching in the library link, but can't find something similar to that.

 

Lars

0 Likes
Message 10 of 20

ВeekeeCZ
Consultant
Consultant

@larsr2866 wrote:

  (if (setq sst (acet-ss-ssget-filter ss '((0 . "SOLID"))))
    (command "_.CHPROP" sst "" "_Color" "_True" '"170,170,170" "")) => this does not?

 


 

If you really mean the SOLID entity, and these entities were selected before to the ss selection set, then it works. 

 

 


@larsr2866 wrote:

Is it also possible to change also the type of these hatches to Ansi31 with a scale of 16?


 

See the HELP, search for "hatch dxf", then check the "Developer" filter. You'll get THIS list of codes.

There you can find that a hatch pattern is associated with code 2 and a scale with code 41. Then your filter would look like this: 

'((0 . "HATCH") (2 . "ANSI31") (41 . 16)).

It's case-sensitive.

 

BTW Lee has nice page about filters HERE. Usage within the ssget function is more common that my usage within acet function, which is not even a core AutoLISP function but function of ExpressTools.

0 Likes
Message 11 of 20

larsr2866
Enthusiast
Enthusiast

Thanks, the solid does also work now (think i made a mistake with my "")

 

I just don't seem to get the hatchedit good working.

So i'm selecting all my hathes with "sst", and then put the command "hatchedit" for my selecion like this:

 

 (if (setq sst (acet-ss-ssget-filter ss '((0 . "HATCH"))))
(command "_.HATCHEDIT" sst "" (2 . "ANSI31") (41 . 16)) 

 

Is there still something wrong with my "" or () maybe?

Thanks!!

Lars

0 Likes
Message 12 of 20

ВeekeeCZ
Consultant
Consultant
Accepted solution

It's not that simple. This list syntax '(() ()) as a filter you can apply just for (ssget) and that function.

For properties specs of HATCHEDIT you need to follow the prompts:

 

(command "_.HATCHEDIT" sst "" "_Properties" "ANSI31" 16 0)

0 Likes
Message 13 of 20

larsr2866
Enthusiast
Enthusiast
Okay, thanks! With this info, i will try to figure out some other things
for understanding all these codes and make myself a complete ‘drawing
cleanup’ macro. You’ve been a great help into getting started with this!
0 Likes
Message 14 of 20

larsr2866
Enthusiast
Enthusiast

I'm sorry to bother you again but i answered too soon (before trying it)

When i put this in my lsp file :


(if (setq sst (acet-ss-ssget-filter ss '((0 . "HATCH"))))
(command "_.HATCHEDIT" sst "" "_.Properties" "ANSI31" 16 0)

 

it says this:

Unknown command "ANSI31". Press F1 for help.
16

0

 

Could you help with this last thing? 🙂

Lars

0 Likes
Message 15 of 20

ВeekeeCZ
Consultant
Consultant

Ok, I see the issue. 

By calling (command "HATCHEDIT") we actually don't call the AutoCAD's command directly but it's LISP equivalent. And sometimes these two are little different. And HATCHEDIT is the case. The difference is that while AutoCAD's version accepts multiple selection, the LISP's version does not (the same issue is with the EXPLODE command).

Fortunately, nowadays we have a command - (initcommandversion) - which can specify the version of command we would like to use. 

BTW the behavior of LISP version you can easily test inside the AutoCAD by typing (command-s "_hatchedit")

 

(if (setq sst (acet-ss-ssget-filter ss '((0 . "HATCH"))))
  (progn
    (initcommandversion)
    (command "_.-HATCHEDIT" sst "" "_Properties" "ANSI31" 16 0)))

Also note, that a dot prefix has only command name, not it's option "_Properties". It's because a command name CAN be redefined so we want to make sure that we call its original version by adding .prefix, whilst inner options cannot. 

0 Likes
Message 16 of 20

larsr2866
Enthusiast
Enthusiast

Thanks, that works like a charm.

I have been trying this weekend to form a complete personal drawing cleenup lisp with your tips, wich is going very well now. But i have one other issue changing my text between coordinates. I think it may be beyond my ability to understand. I would like to change all text scale to 70pt. between certain coordinates + put all annotative scale off. I first have been trying to see the different steps in autocad by typing the following commands line in autocad but when i type 'textedit', its says 'select an annotative object'. Isn't there a way to change all existing text in autocad by the command line? Because this would help me to create my lisp.

 

This is what i would think if textedit would work in my command line?

 

(if (setq sst (ssget "_W" '(49130 -49590) '(387222 166237)))
(if (setq sst (acet-ss-ssget-filter ss '((0 . "TEXT"))))
(progn
(initcommandversion)
(command "_.-TEXTEDIT" sst "" "_Properties" "80")))

 

Lars

 

 

0 Likes
Message 17 of 20

ВeekeeCZ
Consultant
Consultant

For scaling use the _SCALETEXT command.

For turning off the annotativity, use the CHANGE command.

Good luck.

0 Likes
Message 18 of 20

larsr2866
Enthusiast
Enthusiast

Thanks, i will try to fix this!

May i ask one more question to figure this out?

 

When i add my settings off the coordinates to my burst command, autocad won't upload my lisp anymore. ("malformed list on input"). However i don't see the problem with this?

 

(if (setq ss (ssget "_W" '(49130 -49590) '(387222 166237)))    <= i added this

(if (setq sst (acet-ss-ssget-filter ss '((0 . "INSERT"))))
(LM:burstsel sst t))

 

 

0 Likes
Message 19 of 20

ВeekeeCZ
Consultant
Consultant

Well, I would recommend you to type VLIDE into command line and figure out yourself.

 

But here is the spoiler with two other ways to achieve the same: 

(if (setq ss (ssget "_W" '(49130 -49590) '(387222 166237)))
  (if (setq sst (acet-ss-ssget-filter ss '((0 . "INSERT"))))
    (LM:burstsel sst t)))


(if (and (setq ss (ssget "_W" '(49130 -49590) '(387222 166237)))
	 (setq sst (acet-ss-ssget-filter ss '((0 . "INSERT"))))
	 )
  (LM:burstsel sst t))


(and (setq ss (ssget "_W" '(49130 -49590) '(387222 166237)))
     (setq sst (acet-ss-ssget-filter ss '((0 . "INSERT"))))
     (LM:burstsel sst t)
     )
0 Likes
Message 20 of 20

larsr2866
Enthusiast
Enthusiast
Thanks for your help. I fixed it all! 🙂 ##- Please type your reply above
this line -##
0 Likes