Open Autocad Drawing and then execute the program

Open Autocad Drawing and then execute the program

Anonymous
Not applicable
1,229 Views
1 Reply
Message 1 of 2

Open Autocad Drawing and then execute the program

Anonymous
Not applicable

Hi I have some coding in VBA but I want that if I click on generate drawing then new Autocad drawing should be open and then my program should run to draw the drawing.Capture1.PNG

0 Likes
Accepted solutions (1)
1,230 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor
Accepted solution

In most cases, the workflow like that would be: 

1. Run a VBA macro (a public method in an VBA module);

2. The macro brings up the UserForm to collect data from user;

3. User clicks either "Generate/OK" or "Cancel" button, which hides the UserForm with someway indicates the UserForm is oked, or cancelled;

4. If the UserForm is oked, gather the user-input data from the UserForm;

5. Create new drawing with the user-input data, or use the data on existing (bland?) drawing.

 

So, for the UserForm, you may have a member field like this

Public oked As Boolean

....

Then for the "Generate" and "Cancel" button, you would have their click event handler like:

 

Private Sub GenerateCommandButton_Click

    If Not ValiddateUserInputs() Then '' you may want to make sure all required data are entered

        MsgBox "Some requried data missing!"

        Exit sub

    End If

    oked=True

    Me.Hide

End Sub

Private Sub CancelCommandButton_Click

    oked=False

    Me.Hide

End Sub

 

Then here is the VBA Macro in module:

 

Public Sub CreateNewDrawing()

 

     ' You'd better define a class to hold the data

     ' inputted by user

     Dim newDwgData As DwgData 

 

    UserForm1.Show

    if UserForm1.oked Then

        Set newDwgData='' get from the UserForm1, it is up to your code

        CreateNewDrawing newDwgData

    End if

 

    Unload UserForm1

 

End Sub

 

Private Sub CreateNewDrawing(data As DwgData)

    Dim dwg As cadDocument

    Set dwg=Application.Documents.Add([template path/name])

    ''Do whatever with the AcadDocument with user-input data stored in data parameter

    ......

    dwg.SaveAs [file name]

End Sub

Norman Yuan

Drive CAD With Code

EESignature

0 Likes