So as we have seen how to run VBA Macro file in and Create Line DraftSight , now its time to understand VBA macro code.
Know how it works!
First of you should ask question that how Word Macro connect with DraftSight and access DraftSight functions and commands.
Well we have to write this code at start by assuming some preconditions.
1. We have to Declare Variables in VBA. and to make sure all variables are declared at start add this line
2. Now write our Sub Procedure you can change name or keep it as Menu if there is only one macro module.
Sub main() 'Write your VBA code here ( ' is used to comment your code as in DraftSight LISP we use ; or ;| ) End Menu
3. As you have added dsAutomation.dll from Word Menu Tools > References and checked Check box for ‘ DraftSight 1.0 Type Library’ you should see DraftSight Objects in word Macro .
Go to Word Menu View > Object Browser or Press F2 .
In ‘All Libraries’ Drop down list select ‘DraftSight’
Here get information of DraftSight VBA class, Object, Properties and Methods.
4. Moving on now How to Connect to DraftSight.
(If you are viewing Object Browser in above point then double click on Module macro program to view our VBA macro code..)
Declare & set dsApp which connect to DraftSight Application.
Dim dsApp As DraftSight.Application 'Connect to DraftSight Set dsApp = GetObject(, "DraftSight.Application")
5. As soon as we connect to DraftSight abort any running command which will not disturb our program and to avoid nested commands.
'Abort any command currently running in DraftSight dsApp.AbortRunningCommand
6. As you connect to DraftSight Application you need to get Active DraftSight Document with default template.
Dim dsDoc As DraftSight.Document 'Get active document Set dsDoc = dsApp.GetActiveDocument()
7. After Document its time to Get Active Model.
Dim dsModel As DraftSight.Model 'Get model space Set dsModel = dsDoc.GetModel()
8. Once you are in Model Space and to Draw any Entity you need to Get Sketch Manager
Dim dsSketchManager As DraftSight.SketchManager 'Get Sketch Manager Set dsSketchManager = dsModel.GetSketchManager()
9. If you need View Manger in DraftSight to Draw entities in Specific views then Declare and Set View Manager also as :
Dim dsViewManager As DraftSight.ViewManager 'Get View Manager Set dsViewManager = dsDoc.GetViewManager()
10. So far so good , Now we will move ahead.
What if There is no Open Document in DraftSight then ?
Write conditional code after Set dsDoc in Point 6 above to Get Active Document.
If Not dsDoc Is Nothing Then 'Write your program here and declare other parameters after dsDoc. Else MsgBox "There are no open documents in DraftSight" End If
11. Create an Entity: First Declare it .
Dim line1 As DraftSight.Line If 1 Then Set line1 = dsSketchManager.InsertLine(0#, 0#, 0#, 8#, 0#, 0#) End If
Next Modify DraftSight VBA Macro Code >>