PDA

View Full Version : How to cause recorded macro code to be visible in the VBA editor.



TheNewGuy
21st May 2009, 01:10 pm
I would like to know if there is a way to make the code from a user recorded macro to be visible when you go to the VBA editor screen.(like in excel) In excel I can use this to help teach myself the coding language, and I would like to try doing the same in autocad so I can start to write my own lisp programs. Thanks for any input and help!

Lee Mac
21st May 2009, 01:36 pm
I would like to know if there is a way to make the code from a user recorded macro to be visible when you go to the VBA editor screen.(like in excel) In excel I can use this to help teach myself the coding language, and I would like to try doing the same in autocad so I can start to write my own lisp programs. Thanks for any input and help!

Bear in mind that VBA and LISP are two very different things. If you want to write LISP, you will need to write it from scratch, and won't be able to "record" anything that you do. I can't speak for VBA, as, honestly, I have never programmed with it - but I am sure others will have something to say :)

As for LISP, I use the Visual LISP Editor in ACAD (type VLIDE at command line, then File, New File).

There are dozens of tutorial sites out there for you to learn from, and, if you're still stuck, just post a thread on here, and we will help you all we can :)

Cheers

Lee

dbroada
21st May 2009, 01:41 pm
VBA - I've not encountered a user recorded macro in older AutoCAD implementations. I cartainly can't see it on my 2008 version.

I am looking at a nice new 2010 box atm so once we get some time I will have a look at URMs but until then I can't help.

Lee Mac
21st May 2009, 01:45 pm
I am looking at a nice new 2010 box atm...

You lucky lad :P

dbroada
21st May 2009, 02:01 pm
You lucky lad :Pbut by the time our parent company do all their "tests" on any piece of software and allow IT to (tell me to) install it, I will be looking at a nice new 2012 box. :x

Lee Mac
21st May 2009, 02:07 pm
but by the time our parent company do all their "tests" on any piece of software and allow IT to (tell me to) install it, I will be looking at a nice new 2012 box. :x

Haha, I know what you mean :)

But I'd be happy with the wait - I'm still stuck with '04... (best release.. ever.)

TheNewGuy
21st May 2009, 02:18 pm
Sorry I needed to update my user CP because now I've got this fancy new 2009!!! I thought that the language used in VBA would be similar to what is used in a LISP. Is that not the case? And So I guess I would like to see if someone (Ideally NOT LEE MAC as he has done enough for me already) would mind writing a short lisp that I can use as a starting point to learn from.

Lee Mac
21st May 2009, 02:23 pm
Haha "NOT LEE MAC" ... you should be so lucky...

The methods used are similar, but the format and language is quite different.

As for a LISP to "learn from", your best bet would be to check out a tutorial site, like Jeffery Sanders, or AfraLISP - they will step you through it carefully, and use appropriate LISPs.

But, as you asked for it, below is one of my very first LISPs :P



(defun c:addone (/ ent count)
(while (setq ent (car (entsel "\nSelect Numerical Text: ")))
(setq ent (entget ent))
(setq count (atoi (cdr (assoc 1 ent))))
(setq count (+ 1 count))
(setq ent (subst (cons 1 (itoa count)) (assoc 1 ent) ent))
(entmod ent)
) ; end while
(princ)
)

TheNewGuy
21st May 2009, 02:43 pm
Your too much Lee Mac I think I'll be indebted to you for a long time at this rate! Thanks for your help. Again.....

dbroada
21st May 2009, 03:16 pm
as I hinted above, I have yet to install our copy of 2009 or 2010 ut from what I saw the macro produced is in the form of a script file with place holders for variables. Script files have been covered extensively here (a lot of them by me) but are one of the best kept secrets in AutoCAD. So powerful but used by only a few. Have a search here then compare with your 2009 macro.

TheNewGuy
21st May 2009, 06:34 pm
Ok. Thank you for your help. So is there a way to make the code that is generated when I record a macro visible for analysis and editing. I have looked and can't find it.(in excel when I record a new macro the code is stored as a new module and is visible in the VBA editor.) I like this because it is helping me to learn how to write these codes for excel. I would like to do the same thing for autocad. thanks for your help.

TheNewGuy
21st May 2009, 07:22 pm
--EDIT--- I think I have answered this on my own. So this topic is closed. Thanks for your help.

Lee Mac
21st May 2009, 07:26 pm
--EDIT--- I think I have answered this on my own. So this topic is closed. Thanks for your help.

What was the answer? Could you please post it so that others may benefit :)

BIGAL
22nd May 2009, 05:03 am
I am sure others have commented here but there is the action recorder available in 2009 + it allows you to record a macro similar to excell etc Not sure how much editing it allows you to do as I have not played with much it may be good for simple stuff offseting and changing layer properties as a macro. It mentions can put lisp & vba code into the macros.

Well just had a play very interesting you can ask for user input and I guess program it.

Can someone maybe put a couple of examples here done in action recorder.