VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with Save Triggers

1 REPLY 1
Reply
Message 1 of 2
C-Clements
234 Views, 1 Reply

Need help with Save Triggers

Hello, I need help getting a EndSave event trigger to work for a drawing I'm working on. I have VB experience, but this is my first time with AutoCAD in my life, and I need help even getting the vb code to run to debug it to see if I even get the data I need. I am currently uing AutoCAD 2014 and installed the VBA patch.

 

This is my code so far:

 

Private Sub AcadDocument_EndSave(ByVal FileName As String)
Dim TestValue(20) As String
Dim TestValue2 As String
Dim i
Dim MyEntity As AcadEntity
Dim blkRef As AcadBlockReference
Debug.Print ("Is this working?")
For Each MyEntity In ThisDrawing.ModelSpace
If MyEntity.ObjectName = "AcadBlockReference" Then
If MyEntity.blockName = "TBBC" Then
Set blkRef = MyEnitiy
Dim attArray As Variant
attArray = blkRef.GetAttributes

For i = LBound(attArray) To UBound(attArray)
TestValue(i) = attArray(i)
Debug.Print ("test value is" & TestValue(i))
Next i

End If
End If
Next
End Sub

 

After I entered the code in the Visual Basic Editor, I saved it and tried to save my drawing to see if it would trigger the code for testing purposes, but it didn't do anything. Do I need to do anything else with the code first before the drawing does the trigger? Am I just missing something stupid but simple?

1 REPLY 1
Message 2 of 2
norman.yuan
in reply to: C-Clements

Which module you place your code in VBA Editor?

 

In order for the code to be triggered, it has to be hooked to a AcadDocument.

 

In VBA editor, in the project treeview, you can see a node "ThisDrawing" underneath folder node "AuotCAD Objects".

 

Double-click "ThisDrawing" node and a code module pops up. At the top of the code window, select AcadDocument iin the left dropdown, and then select "EndSave" iin the right dropdown. Then place your code inside

 

Private Sub AcadDocument_EndSave(...)

   ''Your code here

End Sub

 

To be warned, if you use 64b-bit ACad2013 or earlier, the code execution of your code (looping through entire ModelSpace) could be very slow (depending on how big of your drawing is), so that your user may think AutoCAD freezes every time AutoCAD saves.

Norman Yuan

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost