Parametric AutoCAD drawings

Other Versions
Spanish
Setting up parametric AutoCAD drawings to accompany CNC programs. November 22, 2003

Question
Does anyone know how to set up a parametric drawing in AutoCAD 2000? I would like to set up parametric AutoCAD drawings to go along with parametric CNC programs. We run many similar CNC programs where the only difference is panel size and hole locations, which move proportionally to the panel size. I have set up several parametric CNC programs that use formulas and variables to save programming and set-up time. Now I would like to do the same thing with our parts drawings, which are generated with AutoCAD 2000. I would like to set up parts drawings using a small database and algebraic formulas that can be modified by making changes to the database. Is this possible? I would think that if you can do this with the CNC software and Excel spreadsheets, that there must be a way to do it in AutoCad.

Forum Responses
From contributor A:
I am not an expert, so if my response is off target, I hope some others will chime in.

Here goes: I think AutoCAD is not parametric. You will need to go to Mechanical Desktop or Inventor for that. But I don't know if saving your parts as blocks will do the trick. To get bigger or smaller parts you just need to insert them in ratio bigger/smaller than 1.



From contributor B:
If you were versed in Visual LISP you could do it. Problem is, I haven’t been able to find any “how to” books that address the subject. Recommendations, anyone?


From contributor C:
There are several ways to accomplish this. Keep in mind, my responses are based on how I do things. I don't use paper space; I use Visual Basic, not Lisp; etc.

1. If your drawings don't have to be to scale… You can draw the parts as you would normally. Explode the dimensions. Delete the dimensional information and insert an attribute. Use the command ATTDEF. For example, you can put in Attributes with the tags of WIDTH and DEPTH. These can be controlled by Visual Basic routines in Excel and/or AutoCAD. Think of it as a fancy charted drawing without the chart.

2. You can set up an Excel spreadsheet to control the drawing if you know Visual Basic. I really like Visual Basic compared to Lisp because then you can control various programs with similar code.

You have to know what AutoCAD information needs to create the drawing object. For example, if you want to draw a line, you have to know the start point in X,Y, and Z. You have to also know the end point in X, Y, and Z. For drawings, Z is always 0. Excel is great for keeping track of and manipulating dimensional data, which you already know if you are using it to create programs. There are about a million other things that you can control - layer, linetype, scale, etc, and you can choose to manipulate them or not.

Anyway, in order to do this, you have to be good at these things:
Excel spreadsheet layout and formulas
Excel visual basic
AutoCAD commands
AutoCAD visual basic. I am fairly weak at this, but I stumbled through it by following the poor examples in the help files.

I have found that it very difficult (time consuming) to try creating a professional drawing by method two. It is better for creating a dimensionally accurate drawing. Method 1 will allow for good visual clarity at the sacrifice of perfect scale.

3. Other options are to go with a commercial package that is already written for the job. MicroVellum, Pattern Systems, Striker Systems (for sheet metal), Synthesis (general purpose parametrics) all have programs that can control AutoCAD parametrically. There are others whose names I just can't think of right now.

These commercial programs are very nice, but we chose to create our own because we could integrate with our scheduling, order entry, bill of material programs easier with our own software.



From the original questioner:
Thanks for the help. Contributor C, your advice was extremely helpful. I set up a drawing for a constantly varying part using your first method, and find it will be more than sufficient for this part and similar parts. Now, with the addition of two pieces of information to our Excel cutlists, we are able to create AutoCAD drawings for this part in virtually no time at all.


From contributor D:
I have had quite a bit of experience creating parametric drawings in AutoCAD using both Lisp and VB. It actually is pretty simple to have AutoCAD generate new geometry each time your part changes size. With Lisp you can enter your parametric values on the command line or in dialog boxes. With VBA built into AutoCAD, it is pretty easy to create a form that allows you to enter the values that will drive your parts. The help files have a lot of great examples of things like adding lines, polylines, circles, etc. Both lisp and VB have their strong points. I prefer VB myself, but, both are pretty easy to use. If you are interested in learning VBA for AutoCAD, "AutoCAD 2000 VBA Programmers Reference" by Joe Sutphin is the best reference book that I have found. It doesn't cover things like creating forms, however, it covers everything related to the AutoCAD VBA interface. VBA will also link to Excel and can be set up to automatically read data and automatically create geometry.


From contributor A:
Command: attdef
Attribute modes - Invisible:N Constant:N Verify:N Preset:N
Enter (ICVP) to change, or press ENTER when done: length
Invalid option keyword.

What is ICVP?



From contributor E:
ICVP
I=Invisible
C=Constant
V=Verify
P=.....your turn here ;-)


From contributor A:
P=Preset

Caught that just after I fired off that post, wanted to... but thought that someone may have further clarification to add.

Ahh! Parametric for AutoCAD. That is interesting. Even Omura (of Mastering AutoCAD fame) never gave a squeak about it.

Tried it - exploded dimension, deleted text, inserted attribute, but couldn't proceed further.



From contributor C:
You are correct, at this point in your setup you haven't gained much. Try this:

1. Save the drawing with the two defined attributes - Width, Depth. Call this drawing TEST.DWG
2. Close this drawing.
3. Open a new drawing.
4. Insert the drawing TEST.DWG as a block.
5. Type in the command DDATTE, pick the block.
6. You should see an edit attributes form pop up, with areas that will allow you to type in the Width and Depth dimensions.

This method has some usages. Titleblocks are easy to create and fill out this way, for example. However, for our purpose the only point is to show you that the dimensions now have names (TAGS in ACAD language). These TAGS can be accessed with VB commands to update them automatically as explained above.

This isn't a real parametric drawing, but it has its place.

Here's some VB code that will insert the block C:\TEST.DWG in a new drawing and update the Width and Depth dimensions. The code is very crude. I just wrote it to show that these things can be done.

Sub updatedim()
Dim objEntity As Object
Dim objModelSpace As AcadModelSpace
Dim ac As Object
Dim mydoc As Object
Set ac = GetObject(, "AutoCAD.Application")
Set objModelSpace = ac.ActiveDocument.ModelSpace()
Set objModelSpace = ac.ActiveDocument.ModelSpace()
Dim varAtt As Variant
Dim blockRefObj As AcadBlockReference
Dim centerpart(0 To 2) As Double
centerpart(0) = X: centerpart(1) = Y: centerpart(2) = 0#
Set blockRefObj = objModelSpace.InsertBlock(centerpart, "C:\TEST.DWG", 1#, _
1#, 1#, 0#)

varAtt = blockRefObj.GetAttributes

mywidth = 24.375

MYNAME = "WIDTH"

For t = LBound(varAtt) To UBound(varAtt)

temp = varAtt(t).TagString

If varAtt(t).TagString = MYNAME Then _

varAtt(t).TextString = mywidth

Next t
mydepth = 12.437

MYNAME = "DEPTH"

For t = LBound(varAtt) To UBound(varAtt)

temp = varAtt(t).TagString

If varAtt(t).TagString = MYNAME Then _

varAtt(t).TextString = mydepth

Next t

ZoomExtents
End Sub

We now have two variables, MYWIDTH and MYDEPTH that we can manipulate and have the program update the drawing. Where this gets useful is not in the width and depth, but let's say you have a hole that is always in the center of the part… you can add two TAGS, HOLEX and HOLEY, then add math formulas, HOLEX = WIDTH/2 and HOLEY = DEPTH/2.



From contributor F:
You guys should really try out Mechanical Desktop or Inventor. It is already parametric based. No understanding of Lisp is required. Going from AutoCAD 2000 to Desktop is like night and day.


The comments below were added after this Forum discussion was archived as a Knowledge Base article (add your comment).

Comment from contributor V:
I have been writing parametric PGM' with VB since 2000. With VB.Net it is even cooler and simpler. You make an object for an ACAD command. Parameters in the constructor. Have some methods, draw, set, get. Do the AutoCAD code in the object. You can make a more complex object by composition. Widget object creates line here, arc there, etc. Make a driver that calculates positions or reads from database and watch it go. I have done 3-D automation the same way. Dimensions, layers, whatever. Some objects require a lot of thought. Only bad thing is it's slow (VB overhead) and eats memory.