Jump to content

Question about Macro and VBA


Faouweb

Recommended Posts

Hi,

When we use Macros in Excel we can see the code, this is an example when i record a macro in Excel:

Sub Macro1()
'
' Macro1 Macro
'

'
   ActiveCell.FormulaR1C1 = "12"
   Range("A2").Select
   ActiveCell.FormulaR1C1 = "30"
   Range("A3").Select
   ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
   Range("A4").Select
End Sub

I have tried in AutoCAD but I can't see anything.

How can I do it?

Thank you :)

Link to comment
Share on other sites

here is an guide about macro making and editing, i hope this is what you need.

 

http://www.ellenfinkelstein.com/acadblog/record-macros-with-the-action-recorder/

Thank you.

It's said in the web site :

Action Recorder macros have some limitations:

 

  • You can’t open files
  • You can’t grip edit or use PRESSPULL
  • You can’t load VBA files
  • Macros also don’t record changes to a dialog box, which means that you may need to use the command line version of a command. If you’ve worked with scripts, you’re familiar with this type of functioning.

You may find other limitations.

 

:(

I want to do an example with VBA in AutoCAD like for example drawing a rectangle or a circle.

There is no enough tutorial on this field :glare:

Link to comment
Share on other sites

VBAMAN opens up the VBA editor

 

There is no VBA macro recorder unlike Word & Excel, you need to write VBA code from scratch copy and paste stuff you can find at places like here

 

Autodesk really dropped the ball with macro record its almost useless compared to Corelcad it writes .NET code as its defualt.

 

Anyway here is some examples

 

Set objTXT = ThisDrawing.ModelSpace.AddText(textVal, varPT2, textSize)
   objTXT.Layer = "TEXT"
   objTXT.Rotation = dtr(90)
   objTXT.color = acYellow

varPT1 = ThisDrawing.Utility.GetPoint(, "Pick Datum Point: ")

   startCH = ThisDrawing.Utility.GetReal("Enter Start CH: ")

acdLINE = ThisDrawing.ModelSpace.AddLine(startPOINT, endPOINT)

Link to comment
Share on other sites

I agree with Al regarding Action Recorder - tested it myself, and never used it again.

 

Separately, I'd suggest that you start learning .NET in lieu of VBA which is no longer supported and is dead or dying. Perhaps VB.NET would be a good place to start given your familiarity with VBA, but you *may* find the need to learn C# at some point also. Coding in .NET will especially come in handy when coding for newer versions, if not verticals.

 

HTH

Link to comment
Share on other sites

Ok I have a googd idea now ;).

What about AutoLISP?

I bought an old book "Inside AutoLISP" i'm in the end of Chapter 2, I hope I'm not wasting time :?

Link to comment
Share on other sites

Learning LISP will serve you well; especially for common, repetitive tasks, etc. and has the ability of performing very complex tasks as well (thanks to ActiveX). Learning .NET can be much more advanced, and is especially applicable when coding for verticals (i.e., Civil 3D, Map 3d, etc.) IMO.

 

** Edit - As for books, I learned a lot about LISP from David Stein's "The Visual LISP Developer's Bible" which is now out in a 2011 edition as well.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...