Password to protect blocks

Password to protect blocks

Anonymous
Not applicable
405 Views
7 Replies
Message 1 of 8

Password to protect blocks

Anonymous
Not applicable
Hi,

I have sent this question to other discussion also,but can anyone give me a
solution or some codes that can protect Blocks of being edited or copied ?
Thanks,

A.K.
0 Likes
406 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
If it's for use in your own office, and you can be sure that the VBA code
will be loaded and enabled ...

Here's a hack solution that may provide some protection.

Hope it helps.

Gary


Private Sub AcadDocument_EndCommand(ByVal CommandName As String)

Dim oEntity As AcadEntity

For Each oEntity In ThisDrawing.ActiveSelectionSet
If oEntity.ObjectName = "AcDbBlockReference" Then
SendKeys "UNDO" & vbCrLf
End If
Next

End Sub


Private Sub AcadDocument_SelectionChanged()

Dim oEntity As AcadEntity

For Each oEntity In ThisDrawing.PickfirstSelectionSet
If oEntity.ObjectName = "AcDbBlockReference" Then
SendKeys Chr(27) & Chr(27)
End If
Next

End Sub
0 Likes
Message 3 of 8

Anonymous
Not applicable
Gary, Thanks for reply
But could you tell me how it works ? I am not professional with VBA.
Thank you.
A.K.


"Gary McMaster" wrote in message
news:4877367@discussion.autodesk.com...
If it's for use in your own office, and you can be sure that the VBA code
will be loaded and enabled ...

Here's a hack solution that may provide some protection.

Hope it helps.

Gary


Private Sub AcadDocument_EndCommand(ByVal CommandName As String)

Dim oEntity As AcadEntity

For Each oEntity In ThisDrawing.ActiveSelectionSet
If oEntity.ObjectName = "AcDbBlockReference" Then
SendKeys "UNDO" & vbCrLf
End If
Next

End Sub


Private Sub AcadDocument_SelectionChanged()

Dim oEntity As AcadEntity

For Each oEntity In ThisDrawing.PickfirstSelectionSet
If oEntity.ObjectName = "AcDbBlockReference" Then
SendKeys Chr(27) & Chr(27)
End If
Next

End Sub
0 Likes
Message 4 of 8

Anonymous
Not applicable
It uses two of several events built into Acad VBA.

The code in the "EndCommand" event checks each entity in the selection set.
If any of them are blocks it sends an "undo" command.

The code in "SelectionChanged" event checks to see if any blocks are
selected. If so, it sends two escape characters to cancel the command.

Not a great way to do things but ...

To try it:

Type "VBAMAN" at the command line
Select the "Visual Basic Editor" button
Double click on "ThisDrawing" in the Project window
Copy and paste the code in the "Declarations" window

Gary


"A-Design" wrote in message
news:4881381@discussion.autodesk.com...
Gary, Thanks for reply
But could you tell me how it works ? I am not professional with VBA.
Thank you.
A.K.


"Gary McMaster" wrote in message
news:4877367@discussion.autodesk.com...
If it's for use in your own office, and you can be sure that the VBA code
will be loaded and enabled ...

Here's a hack solution that may provide some protection.

Hope it helps.

Gary


Private Sub AcadDocument_EndCommand(ByVal CommandName As String)

Dim oEntity As AcadEntity

For Each oEntity In ThisDrawing.ActiveSelectionSet
If oEntity.ObjectName = "AcDbBlockReference" Then
SendKeys "UNDO" & vbCrLf
End If
Next

End Sub


Private Sub AcadDocument_SelectionChanged()

Dim oEntity As AcadEntity

For Each oEntity In ThisDrawing.PickfirstSelectionSet
If oEntity.ObjectName = "AcDbBlockReference" Then
SendKeys Chr(27) & Chr(27)
End If
Next

End Sub
0 Likes
Message 5 of 8

Anonymous
Not applicable
Thank you so much, it is very good,the bad thing is it can not be used on
other computer.


"Gary McMaster" wrote in message
news:4881579@discussion.autodesk.com...
It uses two of several events built into Acad VBA.

The code in the "EndCommand" event checks each entity in the selection set.
If any of them are blocks it sends an "undo" command.

The code in "SelectionChanged" event checks to see if any blocks are
selected. If so, it sends two escape characters to cancel the command.

Not a great way to do things but ...

To try it:

Type "VBAMAN" at the command line
Select the "Visual Basic Editor" button
Double click on "ThisDrawing" in the Project window
Copy and paste the code in the "Declarations" window

Gary


"A-Design" wrote in message
news:4881381@discussion.autodesk.com...
Gary, Thanks for reply
But could you tell me how it works ? I am not professional with VBA.
Thank you.
A.K.


"Gary McMaster" wrote in message
news:4877367@discussion.autodesk.com...
If it's for use in your own office, and you can be sure that the VBA code
will be loaded and enabled ...

Here's a hack solution that may provide some protection.

Hope it helps.

Gary


Private Sub AcadDocument_EndCommand(ByVal CommandName As String)

Dim oEntity As AcadEntity

For Each oEntity In ThisDrawing.ActiveSelectionSet
If oEntity.ObjectName = "AcDbBlockReference" Then
SendKeys "UNDO" & vbCrLf
End If
Next

End Sub


Private Sub AcadDocument_SelectionChanged()

Dim oEntity As AcadEntity

For Each oEntity In ThisDrawing.PickfirstSelectionSet
If oEntity.ObjectName = "AcDbBlockReference" Then
SendKeys Chr(27) & Chr(27)
End If
Next

End Sub
0 Likes
Message 6 of 8

Anonymous
Not applicable
As I mentioned in my original response:

"If it's for use in your own office ..."

You could "Embed" that code in your start model/template. Assuming everyone
in your office uses the same template the code would always be there. There
are also other methods of automatically loading/executing VBA code.

If you embed it, you will probably have to disable the "Macro Virus" warning
dialog on each computer. That could be dangerous if you accept drawings from
outside sources.

Type "vbaman" at the command line. The "Embed" button is in that first
dialog box. Clicking it will cause that code to be saved with the
drawing/template.

Hope that helps,

Gary
0 Likes
Message 7 of 8

Anonymous
Not applicable
Gary thanks for the answer,
As you know on those files contain the macros, when you try to open them
AutoCAD will ask about a permission to run the marcros, in this time if you
cancel it macros wouldn't be run, is there any way that you write your codes
to prevent user cancel this permission (like closeting the file in case of
cancellation) ?

Thanks again.
A.K.



"Gary McMaster" wrote in message
news:4882215@discussion.autodesk.com...
As I mentioned in my original response:

"If it's for use in your own office ..."

You could "Embed" that code in your start model/template. Assuming everyone
in your office uses the same template the code would always be there. There
are also other methods of automatically loading/executing VBA code.

If you embed it, you will probably have to disable the "Macro Virus" warning
dialog on each computer. That could be dangerous if you accept drawings from
outside sources.

Type "vbaman" at the command line. The "Embed" button is in that first
dialog box. Clicking it will cause that code to be saved with the
drawing/template.

Hope that helps,

Gary
0 Likes
Message 8 of 8

Anonymous
Not applicable
A.K.

Again, this will only work on computers that you have control over.

Use the VBA Manager ("vbaman" at command line) to save the previously posted
VBA code to a path and filename of your choice. It may be a network drive.

I have Acad 2004. The following may differ if you have something else.

Add the following two lines of lisp to your "acaddoc.lsp" file. If that file
does not exist, create it using "Windows Notepad" or equivalent and save it
in the Acad search path(s). You will have to modify or create the
acaddoc.lsp file on every machine. Of course the path and filename shown
below will have to match your choices.

Spaces in the path or filename will likely cause problems and will require
further modification of the lisp. The double backslashes are NOT a mistake.

(vl-vbaload "C:\\Temp\\Block-Protect.dvb")
(princ)

Gary
0 Likes