PDA

View Full Version : Scale Change Procedure



jcronburg
2004-06-16, 04:58 PM
AUGIs:

In ACAD 2002/ADT3.3, I'm trying to create a VBA Project with a procedure (if that's the correct term) written by Bobby C. Jones (that I recevived at least 2 years ago) for automatically changing the ltscale value depending on being in model or paper space. After spending many hours plowing through Richard Binning's VBA Foudnations, I'm still confused about how to enter this procedure (shown below) into a VBA project and get it to work. My problem seems to lie in the naming of the Project or Procedure or Macro (which one I don't understand).

Can someone give me concise directions on how to set this up?

Thanks,

Jim Cronburg
____________________________________________________________________

Private Sub AcadDocument_LayoutSwitched(ByVal LayoutName As String)
Dim oLayout As AcadLayout

Set oLayout = ThisDrawing.Layouts.Item(LayoutName)

If oLayout.ModelType Then
ThisDrawing.SetVariable "LTSCALE", 48#
Else
ThisDrawing.SetVariable "LTSCALE", 1#
ThisDrawing.SetVariable "PSLTSCALE", 1#
End If
End Sub

jwanstaett
2004-06-16, 09:00 PM
The code need to me put ThisDrawing and then it should work

jcronburg
2004-06-17, 01:45 PM
j:

1) Where precisely should "ThisDrawing" go in the code list?

2) Do I set this up as a Procedure in a Module?

3) If so, how do I set up the Name, so that when the Code screen comes up it shows Private Sub [Name].

4) When I've Run the Procedure, if I've made certain changes, it won't give me a error code. Does this mean it has run properly? How can I tell, because it does not seem to have done anything to the drawing. I've read about "compiling" it but can't find a way to do that. I've also heard about embedding it (in my Template) but how do I know if it is embedded?

Thanks very much.

Jim Cronburg

Ed Jobe
2004-06-17, 03:18 PM
Jim, here is a step-by-step.

1. Create a new project (*.dvb).

Open VBA Manager, VBAMAN.
Click on the "New" button.
Click on the project just created and then the "Save As" button.
Click on the "Visual Basic Editor" button to switch to the IDE.

2. Edit the project.

Open Project Explorer, ctrl+R .
Double click on the ThisDrawing object to open its code pane.
Click on the combo box in the upper left where it says "General" and select the AcadDocument object. This creates an event procedure for the objects default procedure, which is BeginSave.
Click on the combo box in the upper right that shows the AcadDocument properties/events and select "LayoutSwitched".
Paste Bobby's code in this procedure.
Save your project. You can change its name in the properties window if you wish.

What did you do? You created an event handler. It doesn't "do" anything...until its event is triggered, switching layouts. One caveat, you won't be able to change ltscale at the command prompt. You'll have to change this code. For your next lesson, figure how to create a configuration utility for this. You want a command that stores a value for the ltscale. Modify Bobby's code to look at this value instead of hard-coding a scale.