.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Save a password protected drawing without password with VB.NET
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello,
our drawings are protected by a password.
We have a VB.NET programm to export a drawing without password.
...
Dim securityPar As New SecurityParameters(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
doc.Database.SaveAs("C:\Temp\Test.DWG", False, DwgVersion.Current, securityPar)
doc.CloseAndSave("C:\Temp\Test.DWG")
...
In AutoCAD Architecture 2009 (Win XP) it works fine.
In AutoCAD Architecture 2011 (Win 7) the drawing is still password protected.
Thank you for help,
Udo
Solved! Go to Solution.
Re: Save a password protected drawing without password with VB.NET
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
With help of ObjecARX (native) you can clear password protection: http://forums.autodesk.com/t5/Autodesk-ObjectARX/a
I've not found corresponding method AutoCAD .NET API. IMHO you have to P/Invoke setSecurityParams method.
Re: Save a password protected drawing without password with VB.NET
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Try this code (minimum testing with AutoCAD 2012 x86):
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(Rivilis.ClearPassword))]
namespace Rivilis
{
// This class is instantiated by AutoCAD for each document when
// a command is called by the user the first time in the context
// of a given document. In other words, non static data in this class
// is implicitly per-document!
public class ClearPassword
{
[StructLayout(LayoutKind.Sequential)]
// From dbsecurity.h
public struct SecurityParams
{
public uint cbSize;
public uint ulFlags; // see enum above for flag values
// data relevant to password protection
public string wszPassword;
public uint ulProvType;
public string wszProvName;
public uint ulAlgId; // SECURITYPARAMS_ALGID_RC4
public uint ulKeyLength;
// data relevant to digital signatures
public string wszCertSubject;
public string wszCertIssuer;
public string wszCertSerialNum;
public string wszComment;
public string wszTimeServer;
};
[DllImport("acdb18.dll", CallingConvention = CallingConvention.ThisCall,
EntryPoint = "?setSecurityParams@AcDbDatabase@@QAE_NPBUSecurity Params@@_N@Z")]
static extern private bool setSecurityParamsX32(IntPtr db, ref SecurityParams pSecParams, bool bSetDbMod = true);
[DllImport("acdb18.dll", CallingConvention = CallingConvention.ThisCall,
EntryPoint = "?setSecurityParams@AcDbDatabase@@QEAA_NPEBUSecuri tyParams@@_N@Z")]
static extern private bool setSecurityParamsX64(IntPtr db, ref SecurityParams pSecParams, bool bSetDbMod = true);
static public bool setSecurityParams(Database db, ref SecurityParams parms, bool bSetDbMod = true)
{
if (IntPtr.Size == 4) return setSecurityParamsX32(db.UnmanagedObject, ref parms, bSetDbMod);
else return setSecurityParamsX64(db.UnmanagedObject, ref parms, bSetDbMod);
}
[CommandMethod("ClearPWD", CommandFlags.Modal)]
public void ClearPWD()
{
Database db = HostApplicationServices.WorkingDatabase;
SecurityParams parms = new SecurityParams();
parms.cbSize = (uint)Marshal.SizeOf(parms);
parms.ulFlags = 0; // Clear security flag
setSecurityParams(db, ref parms);
}
}
}
For VB.NET you can convert C# code: http://www.developerfusion.com/tools/convert/cshar
Re: Save a password protected drawing without password with VB.NET
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello Alexander,
thank you! It works very fine in AutoCAD Architecture 2011.
Udo




