PDA

View Full Version : Converting a drawing to VBA code?


ptvba
06-11-2004, 03:59 PM
Is it possible to draw something in autocad and then import or convert it to vba source code? It would be much easier than drawing models from vba directly...
Is there any software to do it? An option in autocad? A script?

Thanks

hendie
07-11-2004, 01:35 PM
I don't understand your question.
a drawing is a series of entities described by points and a whole series of other attributes.
VBA is a language ~ a drawing isn't a language

MickD
08-11-2004, 01:53 AM
Hi ptvba,
I know what you are saying and I reckon it could be done by exporting the objects to a text file with a format like -
Line,(5.0,5.0,0.0)
Circle(10.0, 5.0)
etc.
Then when read back in use a 'switch' on the text string and use the arguments in the brackets for the functions arguments. This would be a mamoth task to allow for all the possible types of objects.
I think Acad solved this sort of problem with blocks which do pretty much what I said above but this info is stored in the drg as another drg (a simple description of this anyway ;) )
This is also how a dxf file is created, open one up in notepad and have a look, you'll see a pattern of how it's laid out which is how it was written out to be read back in.

YosSa
08-11-2004, 09:43 AM
Well yes, you probably can store all entities into a VBA DBASE.
But whats the use of it ??

hendie
08-11-2004, 10:13 AM
As MickD has already stated, in effect, all you would be doing is creating a DXF file.
Autocad already has blocks and wblocks which on the face of it would appear to achieve what you are describing, unless you are looking for some form of parametrics or drawing simple "variations on a theme"

perhaps you could clarify a bit more ?

ptvba
08-11-2004, 05:21 PM
When i say convert or import the drawing to vba i mean to generate the code that would draw those objects.
What i'm looking for is some parametric simple variations on an object (like hendie said).
An example: i want to draw a table and then use vba to create a macro that allows me to change the size of the legs or whatever...
It would be much easier to draw one table in autocad, "import" it to vba code, and then turn the values into variables and allow to change them.
Maybe this isn't the better way.
I'm really new in autocad and not very good in vba, so i'm just looking for the easiest way.
I believe another option would be importing objects from a dwg or dwf file and change it's properties in vba, right?

I tried opening a dwf and a dwg in notepad like MikeD said... it only had stange charecters, it's a binary file

Thanks all for your help

hendie
08-11-2004, 07:30 PM
taking your "table" example
the table is made from 2 components ~ table top and leg
you would have a textbox each for tabletop width, tabletop depth, and tabletop length
for the leg: leg height, leg width, leg depth
you would need to define a "reationship" between the tabletop and the leg so you would know how to position the legs, perhaps inset from edge ?
enter the info hit the button and hey presto Acad draws the table for you.
oobviously, it's not "just" as simple as that. what about 3 legs or more than 4 ? mouldings around te edge etc ? ~ you need to take all this into account and create the code to deal with it. But once you have it written, no more drawing boring tables !

MickD
08-11-2004, 09:14 PM
I think what you need ptvba is a 'class' which you could call 'table' for instance. This is the whole concept behind OOP, or Object Orientated Programming, the use of 'objects' which have both data and functionality.
A class is a template if you like, it has member variables (data such as how long the table legs will be, insert point etc.) and member functions such as DrawTableLegs() and DrawTableTop() which could all be called by a function DrawTable(). These member functions look up the member variables to get the information to draw the table. You set these variables via the command line with prompts or a dialog box to enter the parameters into and hit a button to draw your table.
You probably could do this without a class but if you were drawing lot's of different tables, I think this would be the way to go.
Does that make sense?
Cheers,
MickD

Postonz
18-11-2004, 02:50 PM
:D Hi ptvba...
AutoCad has NO Learning MODE...
Can NOT Convert AutoCad object(Triangle) to VBA code.
AutoCad VBA is a simple language for drawing LINES... Objects...
VBA IT is very similar as Microsoft Visual Basic Code...
Ther is not much info on AutoCad VBA... less basic knowledge...
BUT mountains of instructional data on MS Visual Basic Programming...
However.... I have my students order AutoCad VBA by WORX Publishers
ROTS of RUCK...

hendie
18-11-2004, 04:18 PM
Can NOT Convert AutoCad object(Triangle) to VBA code.
AutoCad VBA is a simple language for drawing LINES... Objects...
Ther is not much info on AutoCad VBA... less basic knowledge...

how do you arrive at those conclusions ? care to elaborate ?

YosSa
19-11-2004, 07:29 AM
glad you said it, it just kept quiet.

But if we believe him, AutoCAD VBA is totally powerless, but believe me, AutoCAD VBA is very powerful and i think there is more then enough literature available for it !! :P